]> git.kernelconcepts.de Git - karo-tx-uboot.git/blobdiff - common/cmd_bootce.c
karo: bootce: suppress mtdparts related error message when CMD_MTDPARTS is not set
[karo-tx-uboot.git] / common / cmd_bootce.c
index eca5df88488bd936ce91189271cf920fc7c89c58..7103b7f898a238888810eb160991859db770a36b 100644 (file)
@@ -52,7 +52,7 @@ DECLARE_GLOBAL_DATA_PTR;
 
 static ce_bin __attribute__ ((aligned (32))) g_bin;
 static ce_net __attribute__ ((aligned (32))) g_net;
-static IPaddr_t server_ip;
+static struct in_addr server_ip;
 
 static void ce_init_bin(ce_bin *bin, unsigned char *dataBuffer)
 {
@@ -133,24 +133,38 @@ static void ce_setup_std_drv_globals(ce_std_driver_globals *std_drv_glb)
        snprintf(std_drv_glb->deviceId, sizeof(std_drv_glb->deviceId),
                "Triton%02X", eth_get_dev()->enetaddr[5]);
 
-       NetCopyIP(&std_drv_glb->kitl.ipAddress, &NetOurIP);
-       std_drv_glb->kitl.ipMask = getenv_IPaddr("netmask");
-       std_drv_glb->kitl.ipRoute = getenv_IPaddr("gatewayip");
+       net_copy_ip(&std_drv_glb->kitl.ipAddress, &net_ip);
+       std_drv_glb->kitl.ipMask = getenv_ip("netmask").s_addr;
+       std_drv_glb->kitl.ipRoute = getenv_ip("gatewayip").s_addr;
 
        if (mtdparts) {
                strncpy(std_drv_glb->mtdparts, mtdparts, max_len);
                std_drv_glb->mtdparts[max_len - 1] = '\0';
        } else {
-               printf("Failed to get mtdparts environment variable\n");
+               if (CONFIG_IS_ENABLED(CMD_MTDPARTS))
+                       printf("Failed to get mtdparts environment variable\n");
        }
 }
 
-static void ce_prepare_run_bin(ce_bin *bin)
+static void ce_init_drv_globals(void)
 {
-       ce_driver_globals *drv_glb;
        struct ce_magic *ce_magic = (void *)CONFIG_SYS_SDRAM_BASE + 0x160;
        ce_std_driver_globals *std_drv_glb = &ce_magic->drv_glb;
 
+       debug("Copying CE MAGIC from %p to %p..%p\n",
+               &ce_magic_template, ce_magic,
+               (void *)ce_magic + sizeof(*ce_magic) - 1);
+       memcpy(ce_magic, &ce_magic_template, sizeof(*ce_magic));
+
+       ce_setup_std_drv_globals(std_drv_glb);
+       ce_magic->size = sizeof(*std_drv_glb) +
+               strlen(std_drv_glb->mtdparts) + 1;
+       ce_dump_block(ce_magic, offsetof(struct ce_magic, drv_glb) +
+               ce_magic->size);
+}
+
+static void ce_prepare_run_bin(ce_bin *bin)
+{
        /* Clear os RAM area (if needed) */
        if (bin->edbgConfig.flags & EDBG_FL_CLEANBOOT) {
                debug("cleaning memory from %p to %p\n",
@@ -161,50 +175,7 @@ static void ce_prepare_run_bin(ce_bin *bin)
                printf("ok\n");
        }
 
-       /* Prepare driver globals (if needed) */
-       if (bin->eDrvGlb) {
-               debug("Copying CE MAGIC from %p to %p..%p\n",
-                       &ce_magic_template, ce_magic,
-                       (void *)ce_magic + sizeof(*ce_magic) - 1);
-               memcpy(ce_magic, &ce_magic_template, sizeof(*ce_magic));
-
-               ce_setup_std_drv_globals(std_drv_glb);
-               ce_magic->size = sizeof(*std_drv_glb) +
-                       strlen(std_drv_glb->mtdparts) + 1;
-               ce_dump_block(ce_magic, offsetof(struct ce_magic, drv_glb) +
-                       ce_magic->size);
-
-               drv_glb = bin->eDrvGlb;
-               memset(drv_glb, 0, sizeof(*drv_glb));
-
-               drv_glb->signature = DRV_GLB_SIGNATURE;
-
-               /* Local ethernet MAC address */
-               memcpy(drv_glb->macAddr, std_drv_glb->kitl.mac,
-                       sizeof(drv_glb->macAddr));
-               debug("got MAC address %pM from environment\n",
-                       drv_glb->macAddr);
-
-               /* Local IP address */
-               drv_glb->ipAddr = getenv_IPaddr("ipaddr");
-
-               /* Subnet mask */
-               drv_glb->ipMask = getenv_IPaddr("netmask");
-
-               /* Gateway config */
-               drv_glb->ipGate = getenv_IPaddr("gatewayip");
-#ifdef DEBUG
-               debug("got IP address %pI4 from environment\n",
-                       &drv_glb->ipAddr);
-               debug("got IP mask %pI4 from environment\n",
-                       &drv_glb->ipMask);
-               debug("got gateway address %pI4 from environment\n",
-                       &drv_glb->ipGate);
-#endif
-               /* EDBG services config */
-               memcpy(&drv_glb->edbgConfig, &bin->edbgConfig,
-                       sizeof(bin->edbgConfig));
-       }
+       ce_init_drv_globals();
 
        /*
         * Make sure, all the above makes it into SDRAM because
@@ -249,15 +220,6 @@ static int ce_lookup_ep_bin(ce_bin *bin)
                                e32->e32_entryrva;
                        bin->eRamStart = CE_FIX_ADDRESS(header->ramStart);
                        bin->eRamLen = header->ramEnd - header->ramStart;
-                       // Save driver_globals address
-                       // Must follow RAM section in CE config.bib file
-                       //
-                       // eg.
-                       //
-                       // RAM          80900000        03200000        RAM
-                       // DRV_GLB      83B00000        00001000        RESERVED
-                       //
-                       bin->eDrvGlb = CE_FIX_ADDRESS(header->ramEnd);
                        return 1;
                }
        }
@@ -416,6 +378,10 @@ static int do_bootce(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
        size_t image_size;
 
        if (argc > 1) {
+               if (strcmp(argv[1], "-i") == 0) {
+                       ce_init_drv_globals();
+                       return CMD_RET_SUCCESS;
+               }
                addr = (void *)simple_strtoul(argv[1], NULL, 16);
                image_size = INT_MAX;           /* actually we do not know the image size */
        } else if (getenv("fileaddr") != NULL) {
@@ -454,9 +420,12 @@ U_BOOT_CMD(
        bootce, 2, 0, do_bootce,
        "Boot a Windows CE image from RAM",
        "[addr]\n"
-       "\taddr\t\tboot image from address addr (default ${fileaddr})"
+       "\taddr\t\tboot image from address addr (default ${fileaddr})\n"
+       "or\n"
+       "\t-i\t\tinitialize the WinCE globals data structure (before loading a .nb0 image)"
 );
 
+#ifdef CONFIG_CMD_NAND
 static int ce_nand_load(ce_bin *bin, loff_t *offset, void *buf, size_t max_len)
 {
        int ret;
@@ -550,6 +519,9 @@ static int do_nbootce(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
                        break;
 
                        case CE_PR_EOF:
+                               ce_prepare_run_bin(&g_bin);
+                               break;
+
                        case CE_PR_ERROR:
                                break;
                        }
@@ -581,6 +553,7 @@ U_BOOT_CMD(
        "\toff\t\t- flash offset (hex)\n"
        "\tpartition\t- partition name"
 );
+#endif
 
 static int ce_send_write_ack(ce_net *net)
 {
@@ -645,9 +618,9 @@ static enum bootme_state ce_process_download(ce_net *net, ce_bin *bin)
                                        // Some diag output
                                        if (net->verbose) {
                                                printf("Locked Down download link, IP: %pI4\n",
-                                                       &NetServerIP);
+                                                       &net_server_ip);
                                                printf("Sending BOOTME request [%d] to %pI4\n",
-                                                       net->seqNum, &NetServerIP);
+                                                       net->seqNum, &net_server_ip);
                                        }
 
                                        // Lock down EShell download link
@@ -733,7 +706,7 @@ static enum bootme_state ce_process_edbg(ce_net *net, ce_bin *bin)
                /* Some diag output */
                if (net->verbose) {
                        printf("Locked Down EDBG service link, IP: %pI4\n",
-                               &NetServerIP);
+                               &net_server_ip);
                }
 
                /* Lock down EDBG link */
@@ -865,7 +838,7 @@ static int ce_send_bootme(ce_net *net)
        }
 
        /* IP address from active config */
-       NetCopyIP(&data->ipAddr, &NetOurIP);
+       net_copy_ip(&data->ipAddr, &net_ip);
 
        // Device name string (NULL terminated). Should include
        // platform and number based on Ether address (e.g. Odo42, CEPCLS2346, etc)
@@ -941,8 +914,6 @@ static inline int ce_init_download_link(ce_net *net, ce_bin *bin, int verbose)
        return 0;
 }
 
-#define UINT_MAX ~0UL
-
 static inline int ce_download_file(ce_net *net, ulong timeout)
 {
        ulong start = get_timer_masked();
@@ -996,7 +967,7 @@ static int do_ceconnect(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[]
        int ret = 1;
        int i;
 
-       server_ip = 0;
+       server_ip.s_addr = 0;
 
        for (i = 1; i < argc; i++){
                if (*argv[i] != '-')
@@ -1009,7 +980,7 @@ static int do_ceconnect(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[]
                                timeout = simple_strtoul(argv[i],
                                                        NULL, 0);
                                if (timeout >= UINT_MAX / CONFIG_SYS_HZ) {
-                                       printf("Timeout value %lu out of range (max.: %lu)\n",
+                                       printf("Timeout value %lu out of range (max.: %u)\n",
                                                timeout, UINT_MAX / CONFIG_SYS_HZ - 1);
                                        return CMD_RET_USAGE;
                                }