From: Andre Renaud <andre@bluewatersys.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [Patch 1/1] Spi Flash: Allow auto-booting of images from spi flash load
Date: Thu, 07 Jul 2011 09:51:58 +1200 [thread overview]
Message-ID: <4E14D8FE.9@bluewatersys.com> (raw)
This allows intelligent booting of FIT (& the legacy style) images from
SPI flash. Basically it means that you don't have to guess at the image
length, so data reads are more optimal (& hopefully faster).
Signed-off-by: Andre Renaud <andre@bluewatersys.com>
---
Index: common/cmd_sf.c
===================================================================
--- common/cmd_sf.c (revision 31)
+++ common/cmd_sf.c (working copy)
@@ -109,6 +109,96 @@
return 0;
}
+static int do_spi_flash_boot(cmd_tbl_t *cmdtp, int argc, char * const argv[])
+{
+ char *ep;
+ size_t cnt;
+ image_header_t *hdr;
+#if defined(CONFIG_FIT)
+ const void *fit_hdr = NULL;
+#endif
+ unsigned long addr;
+ unsigned long offset;
+ char *endp;
+ int ret;
+
+ if (argc < 3)
+ return -1;
+
+ addr = simple_strtoul(argv[1], &endp, 16);
+ if (*argv[1] == 0 || *endp != 0)
+ return -1;
+ offset = simple_strtoul(argv[2], &endp, 16);
+ if (*argv[2] == 0 || *endp != 0)
+ return -1;
+
+ printf("\nLoading from offset 0x%lx\n", offset);
+
+ ret = spi_flash_read(flash, offset, 1024, (u_char *)addr);
+ if (ret) {
+ printf("SPI flash boot failed\n");
+ return 1;
+ }
+
+ switch (genimg_get_format((void *)addr)) {
+ case IMAGE_FORMAT_LEGACY:
+ hdr = (image_header_t *)addr;
+
+ image_print_contents(hdr);
+
+ cnt = image_get_image_size(hdr);
+ break;
+#if defined(CONFIG_FIT)
+ case IMAGE_FORMAT_FIT:
+ fit_hdr = (const void *)addr;
+ puts("Fit image detected...\n");
+
+ cnt = fit_get_size(fit_hdr);
+ break;
+#endif
+ default:
+ puts("** Unknown image type\n");
+ return 1;
+ }
+
+ ret = spi_flash_read(flash, offset, cnt, (u_char *)addr);
+ if (ret) {
+ printf("SPI flash boot failed\n");
+ return 1;
+ }
+
+#if defined(CONFIG_FIT)
+ /* This cannot be done earlier,
+ * we need complete FIT image in RAM first */
+ if (genimg_get_format((void *)addr) == IMAGE_FORMAT_FIT) {
+ if (!fit_check_format(fit_hdr)) {
+ puts("** Bad FIT image format\n");
+ return 1;
+ }
+ fit_print_contents(fit_hdr);
+ }
+#endif
+
+ /* Loading ok, update default load address */
+
+ load_addr = addr;
+
+ /* Check if we should attempt an auto-start */
+ if (((ep = getenv("autostart")) != NULL) && (strcmp(ep, "yes") == 0)) {
+ char *local_args[2];
+
+ local_args[0] = "bootm";
+ local_args[1] = NULL;
+
+ printf("Automatic boot of image at addr 0x%08lx ...\n", addr);
+
+ do_bootm(cmdtp, 0, 1, local_args);
+ return 1;
+ }
+ return 0;
+}
+
+
static int do_spi_flash_read_write(int argc, char * const argv[])
{
unsigned long addr;
@@ -207,6 +297,8 @@
ret = do_spi_flash_read_write(argc, argv);
else if (strcmp(cmd, "erase") == 0)
ret = do_spi_flash_erase(argc, argv);
+ else if (strcmp(cmd, "boot") == 0)
+ ret = do_spi_flash_boot(cmdtp, argc, argv);
else
ret = -1;
@@ -229,4 +321,7 @@
" at `addr' to flash at `offset'\n"
"sf erase offset [+]len - erase `len' bytes from `offset'\n"
" `+len' round up `len' to block size"
+ "sf boot addr offset - read a boot image starting at\n"
+ " `offset' to memory@`addr' and\n"
+ " execute it\n"
);
next reply other threads:[~2011-07-06 21:51 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-07-06 21:51 Andre Renaud [this message]
2011-07-06 22:14 ` [U-Boot] [Patch 1/1] Spi Flash: Allow auto-booting of images from spi flash load Mike Frysinger
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4E14D8FE.9@bluewatersys.com \
--to=andre@bluewatersys.com \
--cc=u-boot@lists.denx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.