diff mbox

[U-Boot,v1] arm: socfpga: Enable load zImage and Linux DTB from QSPI

Message ID 201511271326.18246.marex@denx.de
State Deferred
Delegated to: Marek Vasut
Headers show

Commit Message

Marek Vasut Nov. 27, 2015, 12:26 p.m. UTC
On Friday, November 27, 2015 at 01:16:19 PM, Chin Liang See wrote:
> On Fri, 2015-11-27 at 13:11 +0100, Marek Vasut wrote:
> > On Friday, November 27, 2015 at 01:07:23 PM, Chin Liang See wrote:
> > > On Fri, 2015-11-27 at 11:20 +0100, Marek Vasut wrote:
> > > > On Friday, November 27, 2015 at 02:34:27 AM, Chin Liang See
> > > > 
> > > > wrote:
> > > > > Hi Marek,
> > > > > 
> > > > > On Fri, 2015-11-27 at 02:27 +0100, Marek Vasut wrote:
> > > > > > On Friday, November 27, 2015 at 02:24:49 AM, Chin Liang See
> > > > > > 
> > > > > > wrote:
> > > > > > > Hi Pavel,
> > > > > > > 
> > > > > > > On Thu, 2015-11-26 at 15:43 +0100, Pavel Machek wrote:
> > > > > > > > Hi!
> > > > > > > > 
> > > > > > > > > Adding new environment qspiload which will load zImage
> > > > > > > > > and
> > > > > > > > > Linux DTB from serial NOR flash. The default flash
> > > > > > > > > offset
> > > > > > > > > for
> > > > > > > > > the images as below and they are configurable during
> > > > > > > > > run
> > > > > > > > > time.
> > > > > > > > > 
> > > > > > > > > - zImage located at    0xa0000 with assuming file size
> > > > > > > > > 6MB
> > > > > > > > > - Linux DTB located at 0x50000 with assuming file size
> > > > > > > > > 28kB
> > > > > > > > 
> > > > > > > > Hmm. Ok, zImage second, so that it can grow. Makes sense.
> > > > > > > > Not
> > > > > > > > sure if
> > > > > > > > 28kB is not a bit small for DTB. I'd reserve at least
> > > > > > > > 64kB.
> > > > > > > 
> > > > > > > Yup, it can grow up to 64kB as the size for a sector. We
> > > > > > > used
> > > > > > > 28KB
> > > > > > > mainly for boot time performance.
> > > > > > 
> > > > > > So why don't you use UBI on the QSPI NOR ? That way, you'd
> > > > > > secure
> > > > > > the
> > > > > > binaries against bitrot as well.
> > > > > 
> > > > > Good point. Its a nice enhancement as we were using raw access
> > > > > for
> > > > > the
> > > > > images in NAND and QSPI. Will add a new command for fs support
> > > > > once
> > > > > we
> > > > > enable the ubifs support in socfpga
> > > > 
> > > > Why can't this be enabled now then ?
> > > 
> > > Mainly for backward compatibility as customer might have their own
> > > script on programming a blank flash in production. This is the same
> > > where we can do mmc load or a load (with file system).
> > 
> > Does that imply that we will have to get stuck in the past because
> > some
> > random customer of some random company might have a random script
> > somewhere? :)
> 
> Haha nope, we still need to advance. Just that we are giving choice for
> classic and new :)

Can you check if we can do both then? With the option to prefer the new one?

Check the attached patch, it should give you an idea how to load files from
UBI/UBIFS on QSPI. It even enables mtdparts for the QSPI, which is cool too.

Comments

Chin Liang See Nov. 27, 2015, 1:08 p.m. UTC | #1
On Fri, 2015-11-27 at 13:26 +0100, Marek Vasut wrote:
> On Friday, November 27, 2015 at 01:16:19 PM, Chin Liang See wrote:
> > On Fri, 2015-11-27 at 13:11 +0100, Marek Vasut wrote:
> > > On Friday, November 27, 2015 at 01:07:23 PM, Chin Liang See
> > > wrote:
> > > > On Fri, 2015-11-27 at 11:20 +0100, Marek Vasut wrote:
> > > > > On Friday, November 27, 2015 at 02:34:27 AM, Chin Liang See
> > > > > 
> > > > > wrote:
> > > > > > Hi Marek,
> > > > > > 
> > > > > > On Fri, 2015-11-27 at 02:27 +0100, Marek Vasut wrote:
> > > > > > > On Friday, November 27, 2015 at 02:24:49 AM, Chin Liang
> > > > > > > See
> > > > > > > 
> > > > > > > wrote:
> > > > > > > > Hi Pavel,
> > > > > > > > 
> > > > > > > > On Thu, 2015-11-26 at 15:43 +0100, Pavel Machek wrote:
> > > > > > > > > Hi!
> > > > > > > > > 
> > > > > > > > > > Adding new environment qspiload which will load
> > > > > > > > > > zImage
> > > > > > > > > > and
> > > > > > > > > > Linux DTB from serial NOR flash. The default flash
> > > > > > > > > > offset
> > > > > > > > > > for
> > > > > > > > > > the images as below and they are configurable
> > > > > > > > > > during
> > > > > > > > > > run
> > > > > > > > > > time.
> > > > > > > > > > 
> > > > > > > > > > - zImage located at    0xa0000 with assuming file
> > > > > > > > > > size
> > > > > > > > > > 6MB
> > > > > > > > > > - Linux DTB located at 0x50000 with assuming file
> > > > > > > > > > size
> > > > > > > > > > 28kB
> > > > > > > > > 
> > > > > > > > > Hmm. Ok, zImage second, so that it can grow. Makes
> > > > > > > > > sense.
> > > > > > > > > Not
> > > > > > > > > sure if
> > > > > > > > > 28kB is not a bit small for DTB. I'd reserve at least
> > > > > > > > > 64kB.
> > > > > > > > 
> > > > > > > > Yup, it can grow up to 64kB as the size for a sector.
> > > > > > > > We
> > > > > > > > used
> > > > > > > > 28KB
> > > > > > > > mainly for boot time performance.
> > > > > > > 
> > > > > > > So why don't you use UBI on the QSPI NOR ? That way,
> > > > > > > you'd
> > > > > > > secure
> > > > > > > the
> > > > > > > binaries against bitrot as well.
> > > > > > 
> > > > > > Good point. Its a nice enhancement as we were using raw
> > > > > > access
> > > > > > for
> > > > > > the
> > > > > > images in NAND and QSPI. Will add a new command for fs
> > > > > > support
> > > > > > once
> > > > > > we
> > > > > > enable the ubifs support in socfpga
> > > > > 
> > > > > Why can't this be enabled now then ?
> > > > 
> > > > Mainly for backward compatibility as customer might have their
> > > > own
> > > > script on programming a blank flash in production. This is the
> > > > same
> > > > where we can do mmc load or a load (with file system).
> > > 
> > > Does that imply that we will have to get stuck in the past
> > > because
> > > some
> > > random customer of some random company might have a random script
> > > somewhere? :)
> > 
> > Haha nope, we still need to advance. Just that we are giving choice
> > for
> > classic and new :)
> 
> Can you check if we can do both then? With the option to prefer the
> new one?
> 

Sure as you already give me a jump start :)


> Check the attached patch, it should give you an idea how to load
> files from
> UBI/UBIFS on QSPI. It even enables mtdparts for the QSPI, which is
> cool too.

Cool, thanks for the pointer.

Thanks
Chin Liang
Marek Vasut Nov. 27, 2015, 2:24 p.m. UTC | #2
On Friday, November 27, 2015 at 02:08:30 PM, Chin Liang See wrote:
> On Fri, 2015-11-27 at 13:26 +0100, Marek Vasut wrote:
> > On Friday, November 27, 2015 at 01:16:19 PM, Chin Liang See wrote:
> > > On Fri, 2015-11-27 at 13:11 +0100, Marek Vasut wrote:
> > > > On Friday, November 27, 2015 at 01:07:23 PM, Chin Liang See
> > > > 
> > > > wrote:
> > > > > On Fri, 2015-11-27 at 11:20 +0100, Marek Vasut wrote:
> > > > > > On Friday, November 27, 2015 at 02:34:27 AM, Chin Liang See
> > > > > > 
> > > > > > wrote:
> > > > > > > Hi Marek,
> > > > > > > 
> > > > > > > On Fri, 2015-11-27 at 02:27 +0100, Marek Vasut wrote:
> > > > > > > > On Friday, November 27, 2015 at 02:24:49 AM, Chin Liang
> > > > > > > > See
> > > > > > > > 
> > > > > > > > wrote:
> > > > > > > > > Hi Pavel,
> > > > > > > > > 
> > > > > > > > > On Thu, 2015-11-26 at 15:43 +0100, Pavel Machek wrote:
> > > > > > > > > > Hi!
> > > > > > > > > > 
> > > > > > > > > > > Adding new environment qspiload which will load
> > > > > > > > > > > zImage
> > > > > > > > > > > and
> > > > > > > > > > > Linux DTB from serial NOR flash. The default flash
> > > > > > > > > > > offset
> > > > > > > > > > > for
> > > > > > > > > > > the images as below and they are configurable
> > > > > > > > > > > during
> > > > > > > > > > > run
> > > > > > > > > > > time.
> > > > > > > > > > > 
> > > > > > > > > > > - zImage located at    0xa0000 with assuming file
> > > > > > > > > > > size
> > > > > > > > > > > 6MB
> > > > > > > > > > > - Linux DTB located at 0x50000 with assuming file
> > > > > > > > > > > size
> > > > > > > > > > > 28kB
> > > > > > > > > > 
> > > > > > > > > > Hmm. Ok, zImage second, so that it can grow. Makes
> > > > > > > > > > sense.
> > > > > > > > > > Not
> > > > > > > > > > sure if
> > > > > > > > > > 28kB is not a bit small for DTB. I'd reserve at least
> > > > > > > > > > 64kB.
> > > > > > > > > 
> > > > > > > > > Yup, it can grow up to 64kB as the size for a sector.
> > > > > > > > > We
> > > > > > > > > used
> > > > > > > > > 28KB
> > > > > > > > > mainly for boot time performance.
> > > > > > > > 
> > > > > > > > So why don't you use UBI on the QSPI NOR ? That way,
> > > > > > > > you'd
> > > > > > > > secure
> > > > > > > > the
> > > > > > > > binaries against bitrot as well.
> > > > > > > 
> > > > > > > Good point. Its a nice enhancement as we were using raw
> > > > > > > access
> > > > > > > for
> > > > > > > the
> > > > > > > images in NAND and QSPI. Will add a new command for fs
> > > > > > > support
> > > > > > > once
> > > > > > > we
> > > > > > > enable the ubifs support in socfpga
> > > > > > 
> > > > > > Why can't this be enabled now then ?
> > > > > 
> > > > > Mainly for backward compatibility as customer might have their
> > > > > own
> > > > > script on programming a blank flash in production. This is the
> > > > > same
> > > > > where we can do mmc load or a load (with file system).
> > > > 
> > > > Does that imply that we will have to get stuck in the past
> > > > because
> > > > some
> > > > random customer of some random company might have a random script
> > > > somewhere? :)
> > > 
> > > Haha nope, we still need to advance. Just that we are giving choice
> > > for
> > > classic and new :)
> > 
> > Can you check if we can do both then? With the option to prefer the
> > new one?
> 
> Sure as you already give me a jump start :)
> 
> > Check the attached patch, it should give you an idea how to load
> > files from
> > UBI/UBIFS on QSPI. It even enables mtdparts for the QSPI, which is
> > cool too.
> 
> Cool, thanks for the pointer.

Thanks! This really helps.
diff mbox

Patch

From 031c5c705c2726040d81cd7cbc9cd2361f35913b Mon Sep 17 00:00:00 2001
From: Marek Vasut <marex@denx.de>
Date: Sun, 2 Aug 2015 22:18:19 +0200
Subject: [PATCH] FIXME: SoCkit OpenWRT tuning

Signed-off-by: Marek Vasut <marex@denx.de>
---
 include/configs/socfpga_sockit.h | 158 +++++++++++++++++++++++++++++++++------
 1 file changed, 137 insertions(+), 21 deletions(-)

diff --git a/include/configs/socfpga_sockit.h b/include/configs/socfpga_sockit.h
index 6c71ef4..3496ca5 100644
--- a/include/configs/socfpga_sockit.h
+++ b/include/configs/socfpga_sockit.h
@@ -36,13 +36,9 @@ 
 
 /* Booting Linux */
 #define CONFIG_BOOTDELAY	3
-#define CONFIG_BOOTFILE		"fitImage"
+#define CONFIG_BOOTFILE		"openwrt-socfpga-socfpga_cyclone5_sockit-fit-uImage.itb"
 #define CONFIG_BOOTARGS		"console=ttyS0," __stringify(CONFIG_BAUDRATE)
-#ifdef CONFIG_SOCFPGA_VIRTUAL_TARGET
-#define CONFIG_BOOTCOMMAND	"run ramboot"
-#else
-#define CONFIG_BOOTCOMMAND	"run mmcload; run mmcboot"
-#endif
+#define CONFIG_BOOTCOMMAND	"run selboot"
 #define CONFIG_LOADADDR		0x01000000
 #define CONFIG_SYS_LOAD_ADDR	CONFIG_LOADADDR
 
@@ -72,25 +68,145 @@ 
 /* Extra Environment */
 #define CONFIG_HOSTNAME		socfpga_sockit
 
+#define CONFIG_PREBOOT					\
+	"run adddfltmtd ; "				\
+	"if gpio input 79 ; then "			\
+		"setenv bootdelay -1 ; "		\
+	"else "						\
+		"setenv bootdelay $dfltbootdelay ; "	\
+	"fi"
+
 #define CONFIG_EXTRA_ENV_SETTINGS \
+	"dfltbootdelay=" __stringify(CONFIG_BOOTDELAY) "\0" \
 	"verify=n\0" \
-	"loadaddr= " __stringify(CONFIG_SYS_LOAD_ADDR) "\0" \
-	"ramboot=setenv bootargs " CONFIG_BOOTARGS ";" \
-		"bootm ${loadaddr} - ${fdt_addr}\0" \
-	"bootimage=zImage\0" \
-	"fdt_addr=100\0" \
-	"fdtimage=socfpga.dtb\0" \
-		"fsloadcmd=ext2load\0" \
-	"bootm ${loadaddr} - ${fdt_addr}\0" \
-	"mmcroot=/dev/mmcblk0p2\0" \
-	"mmcboot=setenv bootargs " CONFIG_BOOTARGS \
-		" root=${mmcroot} rw rootwait;" \
-		"bootz ${loadaddr} - ${fdt_addr}\0" \
-	"mmcload=mmc rescan;" \
-		"load mmc 0:1 ${loadaddr} ${bootimage};" \
-		"load mmc 0:1 ${fdt_addr} ${fdtimage}\0" \
+	"consdev=ttyS0\0"						\
+	"baudrate=115200\0"						\
+	"bootscript=boot.scr\0"						\
+	"bootdev=/dev/mmcblk0p2\0"					\
+	"rootdev=/dev/mmcblk0p3\0"					\
+	"ubimtdnr=3\0"							\
+	"ubimtd=rootfs\0"						\
+	"ubipart=ubi0:rootfs\0"						\
+	"netdev=eth0\0"							\
+	"hostname=sockit\0"						\
+	"kernel_addr_r=0x10000000\0"					\
+	"update_filename=u-boot-with-spl-dtb.sfp\0"			\
+	"update_sd_offset=0x800\0"					\
+	"update_sd="		/* Update the SD firmware partition */	\
+		"if mmc rescan ; then "					\
+		"if tftp ${update_filename} ; then "			\
+		"setexpr fw_sz ${filesize} / 0x200 ; "	/* SD block size */ \
+		"setexpr fw_sz ${fw_sz} + 1 ; "				\
+		"mmc write ${loadaddr} ${update_sd_offset} ${fw_sz} ; "	\
+		"fi ; "							\
+		"fi\0"							\
+	"update_qspi_offset=0x0\0"					\
+	"update_qspi="		/* Update the QSPI firmware */		\
+		"if sf probe ; then "					\
+		"if tftp ${update_filename} ; then "			\
+		"sf update ${loadaddr} ${update_qspi_offset} ${filesize} ; " \
+		"fi ; "							\
+		"fi\0"							\
+	"fpga_filename=output_file.rbf\0"				\
+	"load_fpga="		/* Load FPGA bitstream */		\
+		"if tftp ${fpga_filename} ; then "			\
+		"fpga load 0 $loadaddr $filesize ; "			\
+		"bridge enable ; "					\
+		"fi\0"							\
+	"addcons="							\
+		"setenv bootargs ${bootargs} "				\
+		"console=${consdev},${baudrate}\0"			\
+	"addip="							\
+		"setenv bootargs ${bootargs} "				\
+		"ip=${ipaddr}:${serverip}:${gatewayip}:"		\
+			"${netmask}:${hostname}:${netdev}:off\0"	\
+	"addmisc="							\
+		"setenv bootargs ${bootargs} ${miscargs}\0"		\
+	"adddfltmtd="							\
+		"if test \"x${mtdparts}\" == \"x\" ; then "		\
+			"mtdparts default ; "				\
+		"fi\0"							\
+	"addmtd="							\
+		"run adddfltmtd ; "					\
+		"setenv bootargs ${bootargs} ${mtdparts}\0"		\
+	"addargs=run addcons addmtd addmisc\0"				\
+	"mmcload="							\
+		"mmc rescan ; "						\
+		"load mmc 0:2 ${kernel_addr_r} ${bootfile}\0"		\
+	"ubiload="							\
+		"ubi part ${ubimtd} ; ubifsmount ${ubipart} ; "		\
+		"ubifsload ${kernel_addr_r} /boot/${bootfile}\0"	\
+	"netload="							\
+		"tftp ${kernel_addr_r} ${hostname}/${bootfile}\0"	\
+	"miscargs=nohlt panic=1\0"					\
+	"mmcargs=setenv bootargs root=${rootdev} rw rootwait\0"		\
+	"ubiargs="							\
+		"setenv bootargs ubi.mtd=${ubimtdnr} "			\
+		"root=${ubipart} rootfstype=ubifs\0"			\
+	"nfsargs="							\
+		"setenv bootargs root=/dev/nfs rw "			\
+			"nfsroot=${serverip}:${rootpath},v3,tcp\0"	\
+	"mmc_mmc="							\
+		"run mmcload mmcargs addargs ; "			\
+		"bootm ${kernel_addr_r}\0"				\
+	"mmc_ubi="							\
+		"run mmcload ubiargs addargs ; "			\
+		"bootm ${kernel_addr_r}\0"				\
+	"mmc_nfs="							\
+		"run mmcload nfsargs addip addargs ; "			\
+		"bootm ${kernel_addr_r}\0"				\
+	"ubi_mmc="							\
+		"run ubiload mmcargs addargs ; "			\
+		"bootm ${kernel_addr_r}\0"				\
+	"ubi_ubi="							\
+		"sf probe ; "						\
+		"run ubiload ubiargs addargs ; "			\
+		"bootm ${kernel_addr_r}\0"				\
+	"ubi_nfs="							\
+		"run ubiload nfsargs addip addargs ; "			\
+		"bootm ${kernel_addr_r}\0"				\
+	"net_mmc="							\
+		"run netload mmcargs addargs ; "			\
+		"bootm ${kernel_addr_r}\0"				\
+	"net_ubi="							\
+		"run netload ubiargs addargs ; "			\
+		"bootm ${kernel_addr_r}\0"				\
+	"net_nfs="							\
+		"run netload nfsargs addip addargs ; "			\
+		"bootm ${kernel_addr_r}\0"				\
+	"selboot="	/* Select from where to boot. */		\
+		"if test \"${bootmode}\" = \"sd\" ; then "		\
+		"run mmc_mmc ; "					\
+		"elif test \"${bootmode}\" = \"qspi\" ; then "		\
+		"run ubi_ubi ; "					\
+		"else echo \"Unsupported boot mode: \"${bootmode} ; "	\
+		"fi\0"
 
 /* The rest of the configuration is shared */
 #include <configs/socfpga_common.h>
 
+#ifdef CONFIG_CMD_SF
+#define CONFIG_CMD_UBI
+#define CONFIG_CMD_UBIFS
+#define CONFIG_CMD_MTDPARTS
+#define CONFIG_RBTREE
+#define CONFIG_LZO
+#define MTDPARTS_DEFAULT			\
+	"mtdparts=ff705000.spi:"		\
+		"1m(u-boot),"			\
+		"64k(env1),"			\
+		"64k(env2),"			\
+		"16m(rootfs),"			\
+		"-(UBI)\0"
+
+#undef CONFIG_ENV_IS_NOWHERE
+#define CONFIG_ENV_IS_IN_SPI_FLASH
+#define CONFIG_SYS_REDUNDAND_ENVIRONMENT
+#define CONFIG_ENV_SIZE_REDUND		CONFIG_ENV_SIZE
+#define CONFIG_ENV_SECT_SIZE		(64 * 1024)
+#define CONFIG_ENV_OFFSET		0x100000
+#define CONFIG_ENV_OFFSET_REDUND	\
+	(CONFIG_ENV_OFFSET + CONFIG_ENV_SECT_SIZE)
+#endif
+
 #endif	/* __CONFIG_TERASIC_SOCKIT_H__ */
-- 
2.1.4