From: Johannes Thoma Date: Thu, 28 Apr 2011 14:25:39 +0200 Subject: [PATCH] Smart autoboot Message-ID: List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de We check if the image is a kernel image and use bootm command to boot the OS, else we do a go. To use this feature, #define CONFIG_SMART_AUTOBOOT in your config and set the environment variable autostart to "yes". Then your DHCP driver can be used to either boot a kernel image or a u-boot application without changing anything on the target. --- README | 5 +++++ common/cmd_net.c | 25 +++++++++++++++++++++++-- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/README b/README index 4917e26..e33caf2 100644 --- a/README +++ b/README @@ -576,6 +576,11 @@ The following options need to be configured: as a convenience, when switching between booting from RAM and NFS. + CONFIG_SMART_AUTOBOOT + Check if the image is a kernel image. Then a bootm + command is executed, else the go command (for standalone + applications) is executed. + - Pre-Boot Commands: CONFIG_PREBOOT diff --git a/common/cmd_net.c b/common/cmd_net.c index 8c6f5c8..6fa32e3 100644 --- a/common/cmd_net.c +++ b/common/cmd_net.c @@ -28,6 +28,12 @@ #include #include +extern int do_bootm (cmd_tbl_t *, int, int, char * const []); +#ifdef CONFIG_SMART_AUTOBOOT +extern int do_go (cmd_tbl_t *, int, int, char * const []); +#endif + + static int netboot_common (proto_t, cmd_tbl_t *, int , char * const []); int do_bootp (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) @@ -212,14 +218,29 @@ netboot_common (proto_t proto, cmd_tbl_t *cmdtp, int argc, char * const argv[]) /* Loading ok, check if we should attempt an auto-start */ if (((s = getenv("autostart")) != NULL) && (strcmp(s,"yes") == 0)) { - char *local_args[2]; + char *local_args[3]; local_args[0] = argv[0]; local_args[1] = NULL; printf ("Automatic boot of image at addr 0x%08lX ...\n", load_addr); show_boot_progress (82); - rcode = do_bootm (cmdtp, 0, 1, local_args); +#ifdef CONFIG_SMART_AUTOBOOT + if (image_get_type((void*) load_addr) == IH_TYPE_KERNEL) +#endif + rcode = do_bootm (cmdtp, 0, 1, local_args); +#ifdef CONFIG_SMART_AUTOBOOT + else { /* its probably a binary image, use go to start it */ + char load_addr_as_string[17]; /* be 64-bit ready */ + + printf("Not a kernel image, trying standalone binary ...\n"); + sprintf(load_addr_as_string, "%lx", load_addr); + local_args[0] = "go"; + local_args[1] = load_addr_as_string; + local_args[2] = NULL; + rcode = do_go (cmdtp, 0, 2, local_args); + } +#endif } if (rcode < 0) -- 1.6.0.4 -- NEU: FreePhone - kostenlos mobil telefonieren und surfen! Jetzt informieren: http://www.gmx.net/de/go/freephone