[U-Boot] [PATCH V2 3/8] arm: Add savebp implementation for arm

Simon Schwarz simonschwarzcor at googlemail.com
Wed Aug 24 12:39:18 CEST 2011


This adds the savebp implementation to the arm platform.

Related CONFIGs:
CONFIG_CMD_SAVEBP_WRITE_SIZE defines the size of the image to write

Signed-off-by: Simon Schwarz <simonschwarzcor at gmail.com>
---

V2 changes:
DEL _cosmetic_ old comment
---
 arch/arm/include/asm/savebp.h |   27 ++++++++++++
 arch/arm/lib/Makefile         |    1 +
 arch/arm/lib/savebp.c         |   91 +++++++++++++++++++++++++++++++++++++++++
 include/command.h             |    5 ++
 include/configs/devkit8000.h  |    1 +
 5 files changed, 125 insertions(+), 0 deletions(-)
 create mode 100644 arch/arm/include/asm/savebp.h
 create mode 100644 arch/arm/lib/savebp.c

diff --git a/arch/arm/include/asm/savebp.h b/arch/arm/include/asm/savebp.h
new file mode 100644
index 0000000..3774e45
--- /dev/null
+++ b/arch/arm/include/asm/savebp.h
@@ -0,0 +1,27 @@
+/* Copyright (C) 2011
+ * Corscience GmbH & Co. KG - Simon Schwarz <schwarz at corscience.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
+ */
+#ifndef _SAVEBP_H_
+#define _SAVEBP_H_
+
+extern bootm_headers_t images;
+
+#endif /* _SAVEBP_H_ */
diff --git a/arch/arm/lib/Makefile b/arch/arm/lib/Makefile
index 300c8fa..abf7a6a 100644
--- a/arch/arm/lib/Makefile
+++ b/arch/arm/lib/Makefile
@@ -44,6 +44,7 @@ COBJS-y	+= cache-cp15.o
 COBJS-$(CONFIG_SYS_L2_PL310) += cache-pl310.o
 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
 endif
diff --git a/arch/arm/lib/savebp.c b/arch/arm/lib/savebp.c
new file mode 100644
index 0000000..e0cfd83
--- /dev/null
+++ b/arch/arm/lib/savebp.c
@@ -0,0 +1,91 @@
+/* Copyright (C) 2011
+ * Corscience GmbH & Co. KG - Simon Schwarz <schwarz at corscience.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 <command.h>
+#include <image.h>
+
+#include <nand.h>
+#include <asm/savebp.h>
+
+#ifdef CONFIG_OMAP34XX
+#include <asm/arch/sys_proto.h>
+#endif
+
+DECLARE_GLOBAL_DATA_PTR;
+
+/* 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
+ */
+static void boot_params_to_nand(u_char *adr, size_t length, loff_t off)
+{
+	nand_info_t *nand = &nand_info[0]; /* use 0 as in SPL */
+	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");
+		return;
+	}
+
+	printf("Written to offset 0x%llX, size: %d bytes\n",
+		off, length);
+}
+
+/* Saves FDT to NAND */
+int do_savebp_fdt(loff_t offset)
+{
+	boot_params_to_nand((u_char *)images.ft_addr,
+		CONFIG_CMD_SAVEBP_WRITE_SIZE, offset);
+	return 0;
+}
+
+
+/* Saves ATAGS to NAND */
+int do_savebp_atags(loff_t offset)
+{
+	/* Vars */
+	bd_t *bd = gd->bd;
+
+	printf("write ATAGS to NAND...\n");
+
+	/* save em */
+	/* used fixed size - easier to read later just ignore garbage */
+	boot_params_to_nand((u_char *)bd->bi_boot_params,
+		CONFIG_CMD_SAVEBP_WRITE_SIZE, offset);
+
+	return 0;
+}
diff --git a/include/command.h b/include/command.h
index 8310fe5..3ae68a8 100644
--- a/include/command.h
+++ b/include/command.h
@@ -101,6 +101,11 @@ extern int do_bootd(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
 extern int do_bootm(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
 extern int do_reset(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
 
+#ifdef CONFIG_CMD_SAVEBP
+int do_savebp_atags(loff_t offset);
+int do_savebp_fdt(loff_t offset);
+#endif
+
 #endif	/* __ASSEMBLY__ */
 
 /*
diff --git a/include/configs/devkit8000.h b/include/configs/devkit8000.h
index 80b441a..4d0573c 100644
--- a/include/configs/devkit8000.h
+++ b/include/configs/devkit8000.h
@@ -355,6 +355,7 @@
 
 /* SPL OS boot options */
 #define CONFIG_CMD_SAVEBP
+#define CONFIG_CMD_SAVEBP_WRITE_SIZE	0x400 /* 1024 byte */
 #define CONFIG_CMD_SAVEBP_NAND_OFS	(CONFIG_SYS_NAND_SPL_KERNEL_OFFS+\
 						0x400000)
 #define CONFIG_SYS_NAND_SPL_KERNEL_OFFS	0x280000
-- 
1.7.4.1



More information about the U-Boot mailing list