extern volatile struct ehci_hcor *hcor;
 #endif
 #include "beagle.h"
+#include <command.h>
 
 #define pr_debug(fmt, args...) debug(fmt, ##args)
 
 }
 
 #endif /* CONFIG_USB_EHCI */
+
+/*
+ * This command returns the status of the user button on beagle xM
+ * Input - none
+ * Returns -   1 if button is held down
+ *             0 if button is not held down
+ */
+int do_userbutton (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
+{
+       int     button = 0;
+       int     gpio;
+
+       /*
+        * pass address parameter as argv[0] (aka command name),
+        * and all remaining args
+        */
+       switch (get_board_revision()) {
+       case REVISION_AXBX:
+       case REVISION_CX:
+       case REVISION_C4:
+               gpio = 7;
+               break;
+       case REVISION_XM_A:
+       case REVISION_XM_B:
+       case REVISION_XM_C:
+       default:
+               gpio = 4;
+               break;
+       }
+       omap_request_gpio(gpio);
+       omap_set_gpio_direction(gpio, 1);
+       printf("The user button is currently ");
+       if(omap_get_gpio_datain(gpio))
+       {
+               button = 1;
+               printf("PRESSED.\n");
+       }
+       else
+       {
+               button = 0;
+               printf("NOT pressed.\n");
+       }
+
+       omap_free_gpio(gpio);
+
+       return !button;
+}
+
+/* -------------------------------------------------------------------- */
+
+U_BOOT_CMD(
+       userbutton, CONFIG_SYS_MAXARGS, 1,      do_userbutton,
+       "Return the status of the BeagleBoard USER button",
+       ""
+);
 
                "omapdss.def_disp=${defaultdisplay} " \
                "root=${nandroot} " \
                "rootfstype=${nandrootfstype}\0" \
-       "loadbootenv=fatload mmc ${mmcdev} ${loadaddr} uEnv.txt\0" \
+       "bootenv=uEnv.txt\0" \
+       "loadbootenv=fatload mmc ${mmcdev} ${loadaddr} ${bootenv}\0" \
        "importbootenv=echo Importing environment from mmc ...; " \
                "env import -t $loadaddr $filesize\0" \
        "loaduimage=fatload mmc ${mmcdev} ${loadaddr} uImage\0" \
 
 #define CONFIG_BOOTCOMMAND \
        "if mmc rescan ${mmcdev}; then " \
+               "if userbutton; then " \
+                       "setenv bootenv user.txt;" \
+               "fi;" \
                "echo SD/MMC found on device ${mmcdev};" \
                "if run loadbootenv; then " \
+                       "echo Loaded environment from ${bootenv};" \
                        "run importbootenv;" \
                "fi;" \
                "if test -n $uenvcmd; then " \