From patchwork Fri Jul 8 11:31:27 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Schwarz X-Patchwork-Id: 103826 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 3DC2CB6F74 for ; Fri, 8 Jul 2011 21:31:57 +1000 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id E87B9280A6; Fri, 8 Jul 2011 13:31:55 +0200 (CEST) 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 NSD-ZwCI6Qnf; Fri, 8 Jul 2011 13:31:55 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 3554B280B4; Fri, 8 Jul 2011 13:31:54 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 8236C280B4 for ; Fri, 8 Jul 2011 13:31:52 +0200 (CEST) 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 CIqieGlIfAZT for ; Fri, 8 Jul 2011 13:31:51 +0200 (CEST) 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 mail-fx0-f50.google.com (mail-fx0-f50.google.com [209.85.161.50]) by theia.denx.de (Postfix) with ESMTPS id 3449B280BF for ; Fri, 8 Jul 2011 13:31:48 +0200 (CEST) Received: by mail-fx0-f50.google.com with SMTP id 2so1541735fxh.23 for ; Fri, 08 Jul 2011 04:31:48 -0700 (PDT) Received: by 10.223.13.211 with SMTP id d19mr2945914faa.67.1310124708900; Fri, 08 Jul 2011 04:31:48 -0700 (PDT) Received: from localhost.localdomain (DSL01.212.114.252.242.ip-pool.NEFkom.net [212.114.252.242]) by mx.google.com with ESMTPS id w15sm7325613faj.23.2011.07.08.04.31.47 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 08 Jul 2011 04:31:48 -0700 (PDT) From: Simon Schwarz To: u-boot@lists.denx.de, simonschwarzcor@gmail.com Date: Fri, 8 Jul 2011 13:31:27 +0200 Message-Id: <1310124687-11494-2-git-send-email-simonschwarzcor@gmail.com> X-Mailer: git-send-email 1.7.4.1 In-Reply-To: <1310124687-11494-1-git-send-email-simonschwarzcor@gmail.com> References: <1309872039-15316-1-git-send-email-simonschwarzcor@gmail.com> <1310124687-11494-1-git-send-email-simonschwarzcor@gmail.com> Organization: Corscience GmbH & Co. KG Subject: [U-Boot] [RFC 2/2] arm: Adds saving of Kernel boot args to NAND flash X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.9 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 Adds the saving of either ATAGS or FDT kernel argument image to NAND flash This image then can be used in SPL boot. Command savebp is added to achieve this. This inits a partial run of bootm utilizing subcommands. The result then is saved to NAND flash. This adds the following defines to board configuration: CONFIG_CMD_SAVEBP activates the command CONFIG_CMD_SAVEBP_ARGS_NAND_OFS defines the offset in NAND flash where the image is saved For OMAP34XX the image is saved with hw-ecc. --- For RFC: the FDT implementation is todo Signed-off-by: Simon Schwarz --- arch/arm/lib/Makefile | 1 + arch/arm/lib/savebp.c | 100 ++++++++++++++++++++++++++++++++++++++++++ common/Makefile | 2 +- common/cmd_savebp.c | 97 ++++++++++++++++++++++++++++++++++++++++ include/configs/devkit8000.h | 4 ++ 5 files changed, 203 insertions(+), 1 deletions(-) create mode 100644 arch/arm/lib/savebp.c create mode 100644 common/cmd_savebp.c diff --git a/arch/arm/lib/Makefile b/arch/arm/lib/Makefile index 03b1b5e..ccaae4f 100644 --- a/arch/arm/lib/Makefile +++ b/arch/arm/lib/Makefile @@ -44,6 +44,7 @@ COBJS-y += cache-cp15.o endif COBJS-y += interrupts.o COBJS-y += reset.o +COBJS-$(CONFIG_CMD_SAVEBP) += savebp.o SOBJS-$(CONFIG_USE_ARCH_MEMSET) += memset.o SOBJS-$(CONFIG_USE_ARCH_MEMCPY) += memcpy.o diff --git a/arch/arm/lib/savebp.c b/arch/arm/lib/savebp.c new file mode 100644 index 0000000..8394994 --- /dev/null +++ b/arch/arm/lib/savebp.c @@ -0,0 +1,100 @@ +/* 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 */ +/*#include */ +/*#include */ + +#ifdef CONFIG_CMD_SAVEBP +#include +#ifdef CONFIG_OMAP34XX +#include +#endif +#endif + +DECLARE_GLOBAL_DATA_PTR; +extern bootm_headers_t images; /* Struct of the Image header */ + +/* This function writes given bootparams to NAND flash + * adr: Start adress of Kernel parameter image (ATAGS, FDT) + * length: length of the image in byte + * off: offset in NAND flash + * + * borrowd heavily from common/cmd_nand.c + */ +void boot_params_to_nand(u_char *adr, size_t length, loff_t off) +{ + nand_info_t *nand = &nand_info[nand_curr_device]; /* use current dev */ + nand_erase_options_t opts; + +#ifdef CONFIG_OMAP34XX + omap_nand_switch_ecc(1); /* use hw ecc on omap for SPL compat */ +#endif + /* erase */ + memset(&opts, 0, sizeof(opts)); + opts.offset = off; + opts.length = length; + opts.quiet = 1; + opts.spread = 1; + nand_erase_opts(nand, &opts); + + /* write */ + if (nand_write_skip_bad(nand, off, &length, adr, 0)) + printf("FAILED!\n"); + + printf("Written to offset 0x%llX, size: %d bytes\n", + off, length); +} + +/* Saves FDT to NAND */ +int do_savebp_fdt(loff_t offset) +{ + printf(">>>do_save_params_fdt()"); + printf("NOT IMPLEMENTED YET!"); + printf("<<bd; + + printf("write ATAGS to NAND...\n"); + + /* get size of atags */ + for_each_tag(t, (struct tag *)(bd->bi_boot_params)) + size += t->hdr.size; + size += 2; /* ATAG_NONE has size 0 */ + size *= 4; /* words -> byte! */ + + /* save em */ + boot_params_to_nand((u_char *)bd->bi_boot_params, size, offset); + + return 0; +} diff --git a/common/Makefile b/common/Makefile index 224b7cc..d7719bc 100644 --- a/common/Makefile +++ b/common/Makefile @@ -160,6 +160,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_SAVEBP) += cmd_savebp.o # others COBJS-$(CONFIG_DDR_SPD) += ddr_spd.o @@ -174,7 +175,6 @@ COBJS-$(CONFIG_MODEM_SUPPORT) += modem.o COBJS-$(CONFIG_UPDATE_TFTP) += update.o COBJS-$(CONFIG_USB_KEYBOARD) += usb_kbd.o - COBJS := $(sort $(COBJS-y)) XCOBJS := $(sort $(XCOBJS-y)) SRCS := $(COBJS:.o=.c) $(XCOBJS:.o=.c) diff --git a/common/cmd_savebp.c b/common/cmd_savebp.c new file mode 100644 index 0000000..b8233f8 --- /dev/null +++ b/common/cmd_savebp.c @@ -0,0 +1,97 @@ +/* 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 + +#define TYPE_FDT 0 +#define TYPE_ATAGS 1 + +extern bootm_headers_t images; + +static inline int str2off(const char *p, loff_t *num) +{ + char *endptr; + + *num = simple_strtoull(p, &endptr, 16); + return *p != '\0' && *endptr == '\0'; +} + +int do_savebp(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) +{ + loff_t offset; + char * bootm_argsv[] = {"do_bootm","xxxxxxx"}; + + /* - Validate args - */ + if (argc == 2) { + if (!str2off(argv[2], &offset)) { + printf("'%s' is not a number\n",argv[2]); + return cmd_usage(cmdtp); + } + } else if (argc == 1) { + offset = (loff_t)CONFIG_CMD_SAVEBP_NAND_OFS; + printf("using standard destination at: 0x%x\n", (uint32_t)offset); + } else + return cmd_usage(cmdtp); + + /* - do the work - */ + /* exec bootm_start as subcommand of do_bootm to init the images + * data structure */ + bootm_argsv[1] = "start"; + if(do_bootm(find_cmd("do_bootm"),0,2,bootm_argsv)) + printf("ERROR: subcommand start of bootm failed\n"); + + bootm_argsv[1] = "loados"; + if(do_bootm(find_cmd("do_bootm"),0,2,bootm_argsv)) + printf("ERROR: subcommand loados of bootm failed\n"); + +#ifdef CONFIG_SYS_BOOT_RAMDISK_HIGH + bootm_argsv[1] = "ramdisk"; + if(do_bootm(find_cmd("do_bootm"),0,2,bootm_argsv)) + printf("ERROR: subcommand ramdisk of bootm failed\n"); +#endif + +#ifdef CONFIG_OF_LIBFDT + bootm_argsv[1] = "fdt"; + if(do_bootm(find_cmd("do_bootm"),0,2,bootm_argsv)) + printf("ERROR: subcommand fdt of bootm failed\n"); +#endif + + /*subcommand cmdline and bdt are not implemented*/ + + bootm_argsv[1] = "prep"; + if(do_bootm(find_cmd("do_bootm"),0,2,bootm_argsv)) + printf("ERROR: subcommand prep of bootm failed\n"); + + /* call arch specific handlers */ +#ifdef CONFIG_OF_LIBFDT + /*do_savebp_fdt(offset);*/ +#else + do_savebp_atags(offset, &images); +#endif + return 0; +} + +U_BOOT_CMD( + savebp,3,1,do_savebp,"save boot params to NAND flash", + "[nand_offset] saves the parameter image to NAND. \ + Kernel image has to be in RAM!"); diff --git a/include/configs/devkit8000.h b/include/configs/devkit8000.h index 1bf6bea..ff6d750 100644 --- a/include/configs/devkit8000.h +++ b/include/configs/devkit8000.h @@ -194,6 +194,7 @@ #define CONFIG_CMD_MTDPARTS /* Enable MTD parts commands */ #define CONFIG_CMD_NAND /* NAND support */ #define CONFIG_CMD_NAND_LOCK_UNLOCK /* nand (un)lock commands */ +#define CONFIG_CMD_SAVEBP /* Save kernel params command */ #undef CONFIG_CMD_FPGA /* FPGA configuration Support */ #undef CONFIG_CMD_IMI /* iminfo */ @@ -345,4 +346,7 @@ CONFIG_SYS_INIT_RAM_SIZE - \ GENERATED_GBL_DATA_SIZE) +/* Direct OS boot options */ +#define CONFIG_CMD_SAVEBP_NAND_OFS 0x700000 + #endif /* __CONFIG_H */