[U-Boot] [PATCH v4 3/9] sandbox: Add support for bootz

Sjoerd Simons sjoerd.simons at collabora.co.uk
Mon Apr 13 22:54:21 CEST 2015


Add dummy bootz_setup implementation allowing the u-boot sandbox to
run bootz. This recognizes both ARM and x86 zImages to validate a
valid zImage was loaded.

Signed-off-by: Sjoerd Simons <sjoerd.simons at collabora.co.uk>
Acked-by: Simon Glass <sjg at chromium.org>

---

Changes in v4: None
Changes in v3:
- Fill in *start and *end with proper values

Changes in v2:
- Move into sandbox/lib/bootm.c
- convert to u-boot coding style
- Remove unneeded cast

 arch/sandbox/lib/bootm.c | 42 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 42 insertions(+)

diff --git a/arch/sandbox/lib/bootm.c b/arch/sandbox/lib/bootm.c
index 8ddf4ef..d49c927 100644
--- a/arch/sandbox/lib/bootm.c
+++ b/arch/sandbox/lib/bootm.c
@@ -1,5 +1,6 @@
 /*
  * Copyright (c) 2011 The Chromium OS Authors.
+ * Copyright (c) 2015 Sjoerd Simons <sjoerd.simons at collabora.co.uk>
  * SPDX-License-Identifier:	GPL-2.0+
  */
 
@@ -8,6 +9,47 @@
 
 DECLARE_GLOBAL_DATA_PTR;
 
+#define	LINUX_ARM_ZIMAGE_MAGIC	0x016f2818
+
+struct arm_z_header {
+	uint32_t	code[9];
+	uint32_t	zi_magic;
+	uint32_t	zi_start;
+	uint32_t	zi_end;
+} __attribute__ ((__packed__));
+
+int bootz_setup(ulong image, ulong *start, ulong *end)
+{
+	uint8_t *zimage = map_sysmem(image, 0);
+	struct arm_z_header *arm_hdr = (struct arm_z_header *)zimage;
+	int ret = 0;
+
+	if (memcmp(zimage + 0x202, "HdrS", 4) == 0) {
+		uint8_t setup_sects = *(zimage + 0x1f1);
+		uint32_t syssize =
+			le32_to_cpu(*(uint32_t *)(zimage + 0x1f4));
+
+		*start = 0;
+		*end = (setup_sects + 1) * 512 + syssize * 16;
+
+		printf("setting up X86 zImage [ %ld - %ld ]\n",
+		       *start, *end);
+	} else if (le32_to_cpu(arm_hdr->zi_magic) == LINUX_ARM_ZIMAGE_MAGIC) {
+		*start = le32_to_cpu(arm_hdr->zi_start);
+		*end = le32_to_cpu(arm_hdr->zi_end);
+
+		printf("setting up ARM zImage [ %ld - %ld ]\n",
+		       *start, *end);
+	} else {
+		printf("Unrecognized zImage\n");
+		ret = 1;
+	}
+
+	unmap_sysmem((void *)image);
+
+	return ret;
+}
+
 int do_bootm_linux(int flag, int argc, char *argv[], bootm_headers_t *images)
 {
 	if (flag & (BOOTM_STATE_OS_GO | BOOTM_STATE_OS_FAKE_GO)) {
-- 
2.1.4



More information about the U-Boot mailing list