From patchwork Fri Dec 16 15:37:01 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Babic X-Patchwork-Id: 131848 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id 2F15E1007D7 for ; Sat, 17 Dec 2011 02:38:35 +1100 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 2AEA128423; Fri, 16 Dec 2011 16:38:31 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id RIrsiwhzkujk; Fri, 16 Dec 2011 16:38:30 +0100 (CET) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 8CC02284BF; Fri, 16 Dec 2011 16:38:07 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 1CF4328452 for ; Fri, 16 Dec 2011 16:37:59 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id ZInsY5rARm6C for ; Fri, 16 Dec 2011 16:37:58 +0100 (CET) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from smtpi3.ngi.it (smtpi3.ngi.it [88.149.128.33]) by theia.denx.de (Postfix) with ESMTP id 49928283ED for ; Fri, 16 Dec 2011 16:37:49 +0100 (CET) Received: from paperina.lan (unknown [88.149.182.160]) by smtpi3.ngi.it (Postfix) with ESMTP id 3BF70318DC7; Fri, 16 Dec 2011 16:37:48 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by paperina.lan (Postfix) with ESMTP id 78999140A104; Fri, 16 Dec 2011 16:37:41 +0100 (CET) Received: from paperina.lan ([127.0.0.1]) by localhost (paperina.lan [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id UbNtDGDK0moq; Fri, 16 Dec 2011 16:37:16 +0100 (CET) Received: from papero.lan (papero.lan [192.168.2.247]) by paperina.lan (Postfix) with ESMTP id D7AAA140A0BF; Fri, 16 Dec 2011 16:37:16 +0100 (CET) From: Stefano Babic To: u-boot@lists.denx.de Date: Fri, 16 Dec 2011 16:37:01 +0100 Message-Id: <1324049833-18143-2-git-send-email-sbabic@denx.de> X-Mailer: git-send-email 1.7.5.4 In-Reply-To: <1324049833-18143-1-git-send-email-sbabic@denx.de> References: <1313073896-12952-1-git-send-email-simonschwarzcor@gmail.com> <1324049833-18143-1-git-send-email-sbabic@denx.de> Cc: Simon Schwarz Subject: [U-Boot] [PATCH V11 01/13] Add cmd_spl command X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.11 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: u-boot-bounces@lists.denx.de Errors-To: u-boot-bounces@lists.denx.de From: Simon Schwarz This adds a spl command to the u-boot. Related config: CONFIG_CMD_CPL activate/deactivate the command CONFIG_CMD_SPL_NAND_OFS Offset in NAND to use Signed-off-by: Simon Schwarz CC: Tom Rini CC: Stefano Babic CC: Wolfgang Denk --- V2 changes: CHG corrected bootm call. Now bootm is called with five parameters including Address of FDT in RAM. This fixes the hang on savebp fdt call. ADD debug output of the actual bootm parameter call CHG help message V3 changes: FIX added missing brackets V4 changes: CHG Corrected argument number in comments CHG added check for CONFIG_OF_LIBFDT CHG squashed the README to this commit DEL define description from commit message - unused in this patch CHG renamed to spl now with subcommand export, very different now ADD New call style with subcommands. CHG added printf where the image is located CHG Patched README to reflect changes CHG parameter count CHG usage message V5 changes: nothing V6 changes: nothing V7 changes: FIX multiline comment style, cosmetic changes (http://article.gmane.org/gmane.comp.boot-loaders.u-boot/113499) REBASE on u-boot V8 changes: nothing V9 changes: nothing V10 changes: CHG list is now terminated by NULL not \0 ADD static modifiers to most of cmd_spl.c functions DEL board changes ADD include protection to cmd_spl.h DEL not used enum image_tyep CHG some cosmetic CHG images extern moved from cmd_spl.h to image.h V11 changes: nothing common/Makefile | 1 + common/cmd_spl.c | 229 +++++++++++++++++++++++++++++++++++++++++++++++ doc/README.commands.spl | 31 +++++++ include/cmd_spl.h | 30 ++++++ include/image.h | 2 + 5 files changed, 293 insertions(+), 0 deletions(-) create mode 100644 common/cmd_spl.c create mode 100644 doc/README.commands.spl create mode 100644 include/cmd_spl.h diff --git a/common/Makefile b/common/Makefile index 1be7236..91f3f2e 100644 --- a/common/Makefile +++ b/common/Makefile @@ -165,6 +165,7 @@ COBJS-$(CONFIG_USB_STORAGE) += usb_storage.o endif COBJS-$(CONFIG_CMD_XIMG) += cmd_ximg.o COBJS-$(CONFIG_YAFFS2) += cmd_yaffs2.o +COBJS-$(CONFIG_CMD_SPL) += cmd_spl.o # others ifdef CONFIG_DDR_SPD diff --git a/common/cmd_spl.c b/common/cmd_spl.c new file mode 100644 index 0000000..deab8e9 --- /dev/null +++ b/common/cmd_spl.c @@ -0,0 +1,229 @@ +/* + * Copyright (C) 2011 + * Corscience GmbH & Co. KG - Simon Schwarz + * + * 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 +#include +#include + +DECLARE_GLOBAL_DATA_PTR; + +/* Calls bootm with the parameters given */ +static int call_bootm(int argc, char * const argv[], char *subcommand[]) +{ + char *bootm_argv[5]; + char command[] = "do_bootm"; + + int i = 0; + int ret = 0; + + /* create paramter array */ + bootm_argv[0] = command; + switch (argc) { + case 3: + bootm_argv[4] = argv[2]; /* fdt addr */ + case 2: + bootm_argv[3] = argv[1]; /* initrd addr */ + case 1: + bootm_argv[2] = argv[0]; /* kernel addr */ + } + + + /* + * - do the work - + * exec subcommands of do_bootm to init the images + * data structure + */ + while (subcommand[i] != NULL) { + bootm_argv[1] = subcommand[i]; + debug("args: %s, %s, %s, %s, %s, %d\n", bootm_argv[0], + bootm_argv[1], bootm_argv[2], bootm_argv[3], + bootm_argv[4], argc); + ret = do_bootm(find_cmd("do_bootm"), 0, argc+2, + bootm_argv); + debug("Subcommand retcode: %d\n", ret); + i++; + } + + if (ret) { + printf("ERROR prep subcommand failed!\n"); + return -1; + } + + return 0; +} + +/* assemble the bootm paramteres for fdt creation */ +static int spl_export_fdt(int argc, char * const argv[]) +{ +#ifdef CONFIG_OF_LIBFDT + /* Create subcommand string */ + char *subcommand[] = { + "start", + "loados", +#ifdef CONFIG_SYS_BOOT_RAMDISK_HIGH + "ramdisk", +#endif + "fdt", + "cmdline", + "bdt", + "prep", + NULL}; + + /* inspect paramters and execute bootm */ + argc--; + argv++; + if (call_bootm(argc, argv, subcommand)) + return -1; + + printf("Argument image is now in RAM: 0x%p\n", + (void *)images.ft_addr); + return 0; +#else + printf("Das U-Boot was build without fdt support - aborting\n"); + return -1; +#endif +} + +/* assemble the bootm patameters for atags creation */ +static int spl_export_atags(int argc, char * const argv[]) +{ +#if defined(CONFIG_SETUP_MEMORY_TAGS) || \ + defined(CONFIG_CMDLINE_TAG) || \ + defined(CONFIG_INITRD_TAG) || \ + defined(CONFIG_SERIAL_TAG) || \ + defined(CONFIG_REVISION_TAG) + /* Create subcommand string */ + char *subcommand[] = { + "start", + "loados", +#ifdef CONFIG_SYS_BOOT_RAMDISK_HIGH + "ramdisk", +#endif + "cmdline", + "bdt", + "prep", + NULL}; + + /* inspect parameters and execute bootm */ + argc--; + argv++; + if (call_bootm(argc, argv, subcommand)) + return -1; + + printf("Argument image is now in RAM at: 0x%p\n", + (void *)gd->bd->bi_boot_params); + return 0; +#endif + printf("Das U-Boot was build without ATAGS support - aborting\n"); + return -1; +} + +static cmd_tbl_t cmd_spl_export_sub[] = { + U_BOOT_CMD_MKENT(fdt, 0, 1, (void *)SPL_EXPORT_FDT, "", ""), + U_BOOT_CMD_MKENT(atags, 0, 1, (void *)SPL_EXPORT_ATAGS, "", ""), +}; + +static int spl_export(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) +{ + const cmd_tbl_t *c; + int cmd; + + if (argc < 2) /* no subcommand */ + return cmd_usage(cmdtp); + + c = find_cmd_tbl(argv[1], &cmd_spl_export_sub[0], + ARRAY_SIZE(cmd_spl_export_sub)); + if (c) { + cmd = (int)c->cmd; + switch (cmd) { + case SPL_EXPORT_FDT: + argc--; + argv++; + return spl_export_fdt(argc, argv); + break; + case SPL_EXPORT_ATAGS: + argc--; + argv++; + return spl_export_atags(argc, argv); + break; + default: + /* unrecognized command */ + return cmd_usage(cmdtp); + } + } else { + /* Unrecognized command */ + return cmd_usage(cmdtp); + } + + return 0; +} + +static cmd_tbl_t cmd_spl_sub[] = { + U_BOOT_CMD_MKENT(export, 0, 1, (void *)SPL_EXPORT, "", ""), +}; + +static int do_spl(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) +{ + const cmd_tbl_t *c; + int cmd; + + if (argc < 2) /* no subcommand */ + return cmd_usage(cmdtp); + + c = find_cmd_tbl(argv[1], &cmd_spl_sub[0], ARRAY_SIZE(cmd_spl_sub)); + if (c) { + cmd = (int)c->cmd; + switch (cmd) { + case SPL_EXPORT: + argc--; + argv++; + if (spl_export(cmdtp, flag, argc, argv)) + printf("Subcommand failed\n"); + break; + default: + /* unrecognized command */ + return cmd_usage(cmdtp); + } + } else { + /* Unrecognized command */ + return cmd_usage(cmdtp); + } + return 0; +} + +/* + * Arguments: + * 1: subcommand + * 2: image_type + * 3: nand_offset + * 4: kernel_addr + * 5: initrd_addr + * 6: fdt_adr + */ + +U_BOOT_CMD( + spl, 6 , 1, do_spl, "SPL configuration", + "export [kernel_addr] [initrd_addr] " + "[fdt_addr if = fdt] - export a kernel parameter image\n" + "\t initrd_img can be set to \"-\" if fdt_addr without initrd img is" + "used"); diff --git a/doc/README.commands.spl b/doc/README.commands.spl new file mode 100644 index 0000000..818dd53 --- /dev/null +++ b/doc/README.commands.spl @@ -0,0 +1,31 @@ +The spl command is used to export a boot parameter image to RAM. Later +it may implement more functions connected to the SPL. + +SUBCOMMAND EXPORT +To execute the command everything has to be in place as if bootm should be +used. (kernel image, initrd-image, fdt-image etc.) + +export has to subcommands: + atags: exports the ATAGS + fdt: exports the FDT + +Call is: +spl export [kernel_addr] [initrd_addr] [fdt_addr if fdt] + + +TYPICAL CALL + +on OMAP3: +nandecc hw +nand read 0x82000000 0x280000 0x400000 /* Read kernel image from NAND*/ +spl export atags /* export ATAGS */ +nand erase 0x680000 0x20000 /* erase - one page */ +nand write 0x80000100 0x680000 0x20000 /* write the image - one page */ + +call with FDT: +nandecc hw +nand read 0x82000000 0x280000 0x400000 /* Read kernel image from NAND*/ +tftpboot 0x80000100 devkit8000.dtb /* Read fdt */ +spl export fdt 0x82000000 - 0x80000100 /* export FDT */ +nand erase 0x680000 0x20000 /* erase - one page */ +nand write 0x680000 0x20000 diff --git a/include/cmd_spl.h b/include/cmd_spl.h new file mode 100644 index 0000000..2845367 --- /dev/null +++ b/include/cmd_spl.h @@ -0,0 +1,30 @@ +/* Copyright (C) 2011 + * Corscience GmbH & Co. KG - Simon Schwarz + * + * 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 + */ +#ifndef _NAND_SPL_H_ +#define _NAND_SPL_H_ + +#define SPL_EXPORT (0x00000001) + +#define SPL_EXPORT_FDT (0x00000001) +#define SPL_EXPORT_ATAGS (0x00000002) + +#endif /* _NAND_SPL_H_ */ diff --git a/include/image.h b/include/image.h index 466c980..2cc0575 100644 --- a/include/image.h +++ b/include/image.h @@ -267,6 +267,8 @@ typedef struct bootm_headers { #endif } bootm_headers_t; +extern bootm_headers_t images; + /* * Some systems (for example LWMON) have very short watchdog periods; * we must make sure to split long operations like memmove() or