[U-Boot] [PATCH V3] BOOT: Add "bootz" command to boot Linux zImage

Marek Vasut marex at denx.de
Mon Mar 12 22:34:21 CET 2012


From: Marek Vasut <marek.vasut at gmail.com>

This command boots Linux zImage from where the zImage is loaded to. Passing
initrd and fdt is supported.

Tested on i.MX28 based DENX M28EVK
Tested on PXA270 based Voipac PXA270.

Signed-off-by: Marek Vasut <marek.vasut at gmail.com>
Cc: Tom Warren <TWarren at nvidia.com>
Cc: albert.u.boot at aribaud.net
Cc: afleming at gmail.com,
Cc: Simon Glass <sjg at chromium.org>,
Cc: Stephen Warren <swarren at nvidia.com>
Cc: Nicolas Pitre <nico at fluxnic.net>
Cc: Wolfgang Denk <wd at denx.de>
Cc: Detlev Zundel <dzu at denx.de>
---
 common/Makefile    |    1 +
 common/cmd_bootm.c |   29 +--------
 common/cmd_bootz.c |  175 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 common/image.c     |   25 ++++++++
 include/image.h    |    8 +++
 5 files changed, 210 insertions(+), 28 deletions(-)
 create mode 100644 common/cmd_bootz.c

V2: Use CONFIG_BOOTZ_MAX_KERNEL_LMB_SIZE to reserve kernel LMB
V3: Compute the LMB size at runtime (obsoletes V2)
    Move shared code to image.c/image.h
    Sync with latest U-Boot

Note: The FDT works ok, but I don't know about ramdisk, this might be a subject
of subsequent patch (to support raw ramdisk image).

diff --git a/common/Makefile b/common/Makefile
index 0189aac..3e20889 100644
--- a/common/Makefile
+++ b/common/Makefile
@@ -39,6 +39,7 @@ COBJS-y += xyzModem.o
 # core command
 COBJS-y += cmd_boot.o
 COBJS-$(CONFIG_CMD_BOOTM) += cmd_bootm.o
+COBJS-$(CONFIG_CMD_BOOTZ) += cmd_bootz.o
 COBJS-y += cmd_help.o
 COBJS-y += cmd_nvedit.o
 COBJS-y += cmd_version.o
diff --git a/common/cmd_bootm.c b/common/cmd_bootm.c
index d5745b1..eeb57df 100644
--- a/common/cmd_bootm.c
+++ b/common/cmd_bootm.c
@@ -160,35 +160,8 @@ static boot_os_fn *boot_os[] = {
 
 bootm_headers_t images;		/* pointers to os/initrd/fdt images */
 
-/* Allow for arch specific config before we boot */
-void __arch_preboot_os(void)
-{
-	/* please define platform specific arch_preboot_os() */
-}
-void arch_preboot_os(void) __attribute__((weak, alias("__arch_preboot_os")));
-
 #define IH_INITRD_ARCH IH_ARCH_DEFAULT
 
-static void bootm_start_lmb(void)
-{
-#ifdef CONFIG_LMB
-	ulong		mem_start;
-	phys_size_t	mem_size;
-
-	lmb_init(&images.lmb);
-
-	mem_start = getenv_bootm_low();
-	mem_size = getenv_bootm_size();
-
-	lmb_add(&images.lmb, (phys_addr_t)mem_start, mem_size);
-
-	arch_lmb_reserve(&images.lmb);
-	board_lmb_reserve(&images.lmb);
-#else
-# define lmb_reserve(lmb, base, size)
-#endif
-}
-
 static int bootm_start(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 {
 	void		*os_hdr;
@@ -197,7 +170,7 @@ static int bootm_start(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]
 	memset((void *)&images, 0, sizeof(images));
 	images.verify = getenv_yesno("verify");
 
-	bootm_start_lmb();
+	boot_start_lmb(&images);
 
 	/* get kernel image header, start address and length */
 	os_hdr = boot_get_kernel(cmdtp, flag, argc, argv,
diff --git a/common/cmd_bootz.c b/common/cmd_bootz.c
new file mode 100644
index 0000000..0ccd4c7
--- /dev/null
+++ b/common/cmd_bootz.c
@@ -0,0 +1,175 @@
+/*
+ * Copyright (C) 2011 Marek Vasut <marek.vasut at gmail.com>
+ *
+ * Based on code:
+ * (C) Copyright 2000-2009
+ * Wolfgang Denk, DENX Software Engineering, wd at denx.de.
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ */
+
+#include <common.h>
+#include <watchdog.h>
+#include <command.h>
+#include <image.h>
+#include <malloc.h>
+#include <u-boot/zlib.h>
+#include <bzlib.h>
+#include <environment.h>
+#include <lmb.h>
+#include <linux/ctype.h>
+#include <asm/byteorder.h>
+
+#if defined(CONFIG_CMD_USB)
+#include <usb.h>
+#endif
+
+#if defined(CONFIG_SYS_HUSH_PARSER)
+#include <hush.h>
+#endif
+
+#if defined(CONFIG_OF_LIBFDT)
+#include <fdt.h>
+#include <libfdt.h>
+#include <fdt_support.h>
+#endif
+
+#define IH_INITRD_ARCH IH_ARCH_DEFAULT
+
+extern int do_bootm_linux(int flag, int argc, char * const argv[],
+			bootm_headers_t *images);
+
+struct zimage_header {
+	uint32_t	code[9];
+	uint32_t	zi_magic;
+	uint32_t	zi_start;
+	uint32_t	zi_end;
+};
+
+#define	LINUX_ARM_ZIMAGE_MAGIC	0x016f2818
+
+static int bootz_start(cmd_tbl_t *cmdtp, int flag, int argc,
+			char * const argv[], bootm_headers_t *images)
+{
+	int ret;
+	struct zimage_header *zi;
+
+	memset(images, 0, sizeof(bootm_headers_t));
+
+	boot_start_lmb(images);
+
+	/* Setup Linux kernel zImage entry point */
+	if (argc < 2) {
+		images->ep = load_addr;
+		debug("*  kernel: default image load address = 0x%08lx\n",
+				load_addr);
+	} else {
+		images->ep = simple_strtoul(argv[1], NULL, 16);
+		debug("*  kernel: cmdline image address = 0x%08lx\n",
+			images->ep);
+	}
+
+	zi = (struct zimage_header *)images->ep;
+
+	if (zi->zi_magic != LINUX_ARM_ZIMAGE_MAGIC) {
+		puts("Bad Linux ARM zImage magic!\n");
+		return 1;
+	}
+
+	lmb_reserve(&images->lmb, images->ep, zi->zi_end - zi->zi_start);
+
+	/* Find ramdisk */
+	ret = boot_get_ramdisk(argc, argv, images, IH_INITRD_ARCH,
+			&images->rd_start, &images->rd_end);
+	if (ret) {
+		puts("Ramdisk image is corrupt or invalid\n");
+		return 1;
+	}
+
+#if defined(CONFIG_OF_LIBFDT)
+	/* find flattened device tree */
+	ret = boot_get_fdt(flag, argc, argv, images,
+			   &images->ft_addr, &images->ft_len);
+	if (ret) {
+		puts("Could not find a valid device tree\n");
+		return 1;
+	}
+
+	set_working_fdt_addr(images->ft_addr);
+#endif
+
+	return 0;
+}
+
+int do_bootz(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+	ulong		iflag;
+	bootm_headers_t	images;
+
+	if (bootz_start(cmdtp, flag, argc, argv, &images))
+		return 1;
+
+	/*
+	 * We have reached the point of no return: we are going to
+	 * overwrite all exception vector code, so we cannot easily
+	 * recover from any failures any more...
+	 */
+	iflag = disable_interrupts();
+
+#if defined(CONFIG_CMD_USB)
+	/*
+	 * turn off USB to prevent the host controller from writing to the
+	 * SDRAM while Linux is booting. This could happen (at least for OHCI
+	 * controller), because the HCCA (Host Controller Communication Area)
+	 * lies within the SDRAM and the host controller writes continously to
+	 * this area (as busmaster!). The HccaFrameNumber is for example
+	 * updated every 1 ms within the HCCA structure in SDRAM! For more
+	 * details see the OpenHCI specification.
+	 */
+	usb_stop();
+#endif
+
+#ifdef CONFIG_SILENT_CONSOLE
+	fixup_silent_linux();
+#endif
+	arch_preboot_os();
+
+	do_bootm_linux(0, argc, argv, &images);
+#ifdef DEBUG
+	puts("\n## Control returned to monitor - resetting...\n");
+#endif
+	do_reset(cmdtp, flag, argc, argv);
+
+	return 1;
+}
+
+U_BOOT_CMD(
+	bootz,	CONFIG_SYS_MAXARGS,	1,	do_bootz,
+	"boot Linux zImage image from memory",
+	"[addr [initrd] [fdt]]\n    - boot Linux zImage stored in memory\n"
+	"\tThe argument 'initrd' is optional and specifies the address\n"
+	"\tof the initrd in memory.\n"
+#if defined(CONFIG_OF_LIBFDT)
+	"\tWhen booting a Linux kernel which requires a flat device-tree\n"
+	"\ta third argument is required which is the address of the\n"
+	"\tdevice-tree blob. To boot that kernel without an initrd image,\n"
+	"\tuse a '-' for the second argument. If you do not pass a third\n"
+	"\ta bd_info struct will be passed instead\n"
+#endif
+);
diff --git a/common/image.c b/common/image.c
index fbdc40a..5752bf5 100644
--- a/common/image.c
+++ b/common/image.c
@@ -3190,3 +3190,28 @@ static int fit_check_ramdisk(const void *fit, int rd_noffset, uint8_t arch,
 }
 #endif /* USE_HOSTCC */
 #endif /* CONFIG_FIT */
+
+#ifdef	CONFIG_LMB
+void boot_start_lmb(bootm_headers_t *images)
+{
+	ulong		mem_start;
+	phys_size_t	mem_size;
+
+	lmb_init(&images->lmb);
+
+	mem_start = getenv_bootm_low();
+	mem_size = getenv_bootm_size();
+
+	lmb_add(&images->lmb, (phys_addr_t)mem_start, mem_size);
+
+	arch_lmb_reserve(&images->lmb);
+	board_lmb_reserve(&images->lmb);
+}
+#endif
+
+/* Allow for arch specific config before we boot */
+void __arch_preboot_os(void)
+{
+	/* please define platform specific arch_preboot_os() */
+}
+void arch_preboot_os(void) __attribute__((weak, alias("__arch_preboot_os")));
diff --git a/include/image.h b/include/image.h
index bbf80f0..26b8a20 100644
--- a/include/image.h
+++ b/include/image.h
@@ -486,6 +486,14 @@ void image_multi_getimg(const image_header_t *hdr, ulong idx,
 
 void image_print_contents(const void *hdr);
 
+#ifdef CONFIG_LMB
+void boot_start_lmb(bootm_headers_t *images);
+#else
+static inline void boot_start_lmb(bootm_headers_t *image) { }
+#endif
+
+extern void arch_preboot_os(void);
+
 #ifndef USE_HOSTCC
 static inline int image_check_target_arch(const image_header_t *hdr)
 {
-- 
1.7.9



More information about the U-Boot mailing list