[U-Boot] [PATCH] BOOT: Add "bootz" command to boot Linux zImage
Marek Vasut
marek.vasut at gmail.com
Sat Nov 12 03:35:27 CET 2011
This command boots Linux zImage from where the zImage is loaded to. Passing
initrd and fdt is supported.
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>
---
common/Makefile | 1 +
common/cmd_bootz.c | 178 ++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 179 insertions(+), 0 deletions(-)
create mode 100644 common/cmd_bootz.c
diff --git a/common/Makefile b/common/Makefile
index 1b672ad..1ddf77a 100644
--- a/common/Makefile
+++ b/common/Makefile
@@ -42,6 +42,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_bootz.c b/common/cmd_bootz.c
new file mode 100644
index 0000000..bb35209
--- /dev/null
+++ b/common/cmd_bootz.c
@@ -0,0 +1,178 @@
+/*
+ * 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 *argv[],
+ bootm_headers_t *images);
+
+static void bootm_start_lmb(bootm_headers_t *images)
+{
+#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 bootz_start(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
+ bootm_headers_t *images)
+{
+ int ret;
+
+ memset(images, 0, sizeof(bootm_headers_t));
+
+ bootm_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);
+ }
+
+ lmb_reserve(&images->lmb, images->ep, 16 * 1024*1024);
+
+ /* 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 *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
+);
--
1.7.7.1
More information about the U-Boot
mailing list