Merge git://git.denx.de/u-boot-fsl-qoriq
[oweals/u-boot.git] / board / sunxi / board.c
index c2755b2c6dfd4429b65d93ea5aacffd7f9ed029a..6e13ee32c14d7715739f2dcbdbbff4c54b839862 100644 (file)
@@ -32,7 +32,9 @@
 #include <libfdt.h>
 #include <nand.h>
 #include <net.h>
+#include <spl.h>
 #include <sy8106a.h>
+#include <asm/setup.h>
 
 #if defined CONFIG_VIDEO_LCD_PANEL_I2C && !(defined CONFIG_SPL_BUILD)
 /* So that we can use pin names in Kconfig and sunxi_name_to_gpio() */
@@ -490,20 +492,6 @@ int board_mmc_init(bd_t *bis)
                return -1;
 #endif
 
-#if !defined(CONFIG_SPL_BUILD) && CONFIG_MMC_SUNXI_SLOT_EXTRA == 2
-       /*
-        * On systems with an emmc (mmc2), figure out if we are booting from
-        * the emmc and if we are make it "mmc dev 0" so that boot.scr, etc.
-        * are searched there first. Note we only do this for u-boot proper,
-        * not for the SPL, see spl_boot_device().
-        */
-       if (readb(SPL_ADDR + 0x28) == SUNXI_BOOTED_FROM_MMC2) {
-               /* Booting from emmc / mmc2, swap */
-               mmc0->block_dev.devnum = 1;
-               mmc1->block_dev.devnum = 0;
-       }
-#endif
-
        return 0;
 }
 #endif
@@ -601,7 +589,7 @@ void get_board_serial(struct tag_serialnr *serialnr)
        char *serial_string;
        unsigned long long serial;
 
-       serial_string = getenv("serial#");
+       serial_string = env_get("serial#");
 
        if (serial_string) {
                serial = simple_strtoull(serial_string, NULL, 16);
@@ -645,7 +633,7 @@ static void parse_spl_header(const uint32_t spl_addr)
                return;
        }
        /* otherwise assume .scr format (mkimage-type script) */
-       setenv_hex("fel_scriptaddr", spl->fel_script_address);
+       env_set_hex("fel_scriptaddr", spl->fel_script_address);
 }
 
 /*
@@ -693,7 +681,7 @@ static void setup_environment(const void *fdt)
                        else
                                sprintf(ethaddr, "eth%daddr", i);
 
-                       if (getenv(ethaddr))
+                       if (env_get(ethaddr))
                                continue;
 
                        /* Non OUI / registered MAC address */
@@ -704,14 +692,14 @@ static void setup_environment(const void *fdt)
                        mac_addr[4] = (sid[3] >>  8) & 0xff;
                        mac_addr[5] = (sid[3] >>  0) & 0xff;
 
-                       eth_setenv_enetaddr(ethaddr, mac_addr);
+                       eth_env_set_enetaddr(ethaddr, mac_addr);
                }
 
-               if (!getenv("serial#")) {
+               if (!env_get("serial#")) {
                        snprintf(serial_string, sizeof(serial_string),
                                "%08x%08x", sid[0], sid[3]);
 
-                       setenv("serial#", serial_string);
+                       env_set("serial#", serial_string);
                }
        }
 }
@@ -719,13 +707,22 @@ static void setup_environment(const void *fdt)
 int misc_init_r(void)
 {
        __maybe_unused int ret;
+       uint boot;
 
-       setenv("fel_booted", NULL);
-       setenv("fel_scriptaddr", NULL);
+       env_set("fel_booted", NULL);
+       env_set("fel_scriptaddr", NULL);
+       env_set("mmc_bootdev", NULL);
+
+       boot = sunxi_get_boot_device();
        /* determine if we are running in FEL mode */
-       if (!is_boot0_magic(SPL_ADDR + 4)) { /* eGON.BT0 */
-               setenv("fel_booted", "1");
+       if (boot == BOOT_DEVICE_BOARD) {
+               env_set("fel_booted", "1");
                parse_spl_header(SPL_ADDR);
+       /* or if we booted from MMC, and which one */
+       } else if (boot == BOOT_DEVICE_MMC1) {
+               env_set("mmc_bootdev", "0");
+       } else if (boot == BOOT_DEVICE_MMC2) {
+               env_set("mmc_bootdev", "1");
        }
 
        setup_environment(gd->fdt_blob);
@@ -735,7 +732,10 @@ int misc_init_r(void)
        if (ret)
                return ret;
 #endif
-       sunxi_musb_board_init();
+
+#ifdef CONFIG_USB_ETHER
+       usb_ether_init();
+#endif
 
        return 0;
 }
@@ -761,13 +761,19 @@ int ft_board_setup(void *blob, bd_t *bd)
 #ifdef CONFIG_SPL_LOAD_FIT
 int board_fit_config_name_match(const char *name)
 {
-       const char *cmp_str;
+       struct boot_file_head *spl = (void *)(ulong)SPL_ADDR;
+       const char *cmp_str = (void *)(ulong)SPL_ADDR;
 
+       /* Check if there is a DT name stored in the SPL header and use that. */
+       if (spl->dt_name_offset) {
+               cmp_str += spl->dt_name_offset;
+       } else {
 #ifdef CONFIG_DEFAULT_DEVICE_TREE
-       cmp_str = CONFIG_DEFAULT_DEVICE_TREE;
+               cmp_str = CONFIG_DEFAULT_DEVICE_TREE;
 #else
-       return 0;
+               return 0;
 #endif
+       };
 
 /* Differentiate the two Pine64 board DTs by their DRAM size. */
        if (strstr(name, "-pine64") && strstr(cmp_str, "-pine64")) {