[U-Boot] [PATCH 09/12] board/BuR/brppt1: implement more flexible boot process

Hannes Schmelzer oe5hpm at oevsv.at
Fri Jul 6 13:41:26 UTC 2018


With this commit we do:

- set the bootdelay in all brppt1 defconfigs to 0, this makes
development easier, since we can break into serial console.

- move CONFIG_BOOTCOMMAND from header file to defconfig

- introduce b_mode variable for selecting the final boot-target.
This b_mode represents the boot-switch, which can found on most b&r
targets. On the brppt1 this boot-switch is derived from some gpio and
the bootcounter within the RTC block, making it so possible to force
a boot-target (as example for repair-case).

- refactor the environment for booting new flexible way
primary we want to get some bootscr.img within the mass-storage,
this script then loads everything needed for the boot.
For legacy reason we implement the t30lgcy#x boot targets, booting the
already delivered linux-images.

- make space for the cfgscr within mtdparts on brppt1_nand

Signed-off-by: Hannes Schmelzer <oe5hpm at oevsv.at>
---

 board/BuR/brppt1/board.c      |  28 +++++++-
 configs/brppt1_mmc_defconfig  |   4 +-
 configs/brppt1_nand_defconfig |   6 +-
 configs/brppt1_spi_defconfig  |   4 +-
 include/configs/brppt1.h      | 145 +++++++++++++++++++-----------------------
 5 files changed, 102 insertions(+), 85 deletions(-)

diff --git a/board/BuR/brppt1/board.c b/board/BuR/brppt1/board.c
index f970f98..87b76a6 100644
--- a/board/BuR/brppt1/board.c
+++ b/board/BuR/brppt1/board.c
@@ -140,11 +140,33 @@ int board_init(void)
 }
 
 #ifdef CONFIG_BOARD_LATE_INIT
+static char *bootmodeascii[16] = {
+	"BOOT",		"reserved",	"reserved",	"reserved",
+	"RUN",		"reserved",	"reserved",	"reserved",
+	"reserved",	"reserved",	"reserved",	"reserved",
+	"PME",		"reserved",	"reserved",	"DIAG",
+};
+
 int board_late_init(void)
 {
-	if (0 == gpio_get_value(REPSWITCH)) {
-		env_set("bootcmd", "run netconsole");
-	}
+	unsigned char bmode = 0;
+	ulong bootcount = 0;
+
+	bootcount = bootcount_load() & 0xF;
+
+	if (gpio_get_value(REPSWITCH) == 0 || bootcount == 12)
+		bmode = 12;
+	else if (bootcount > 0)
+		bmode = 0;
+	else
+		bmode = 4;
+
+	printf("Mode:  %s\n", bootmodeascii[bmode & 0x0F]);
+	env_set_ulong("b_mode", bmode);
+
+	/* get sure that bootcmd isn't affected by any bootcount value */
+	env_set_ulong("bootlimit", 0);
+
 	return 0;
 }
 #endif /* CONFIG_BOARD_LATE_INIT */
diff --git a/configs/brppt1_mmc_defconfig b/configs/brppt1_mmc_defconfig
index b8db509..6bb4657 100644
--- a/configs/brppt1_mmc_defconfig
+++ b/configs/brppt1_mmc_defconfig
@@ -10,7 +10,9 @@ CONFIG_SPL_SERIAL_SUPPORT=y
 CONFIG_SPL=y
 CONFIG_OF_BOARD_SETUP=y
 CONFIG_SYS_EXTRA_OPTIONS="SERIAL1,CONS_INDEX=1,EMMC_BOOT"
-CONFIG_BOOTDELAY=-2
+CONFIG_BOOTDELAY=0
+CONFIG_USE_BOOTCOMMAND=y
+CONFIG_BOOTCOMMAND="run b_default"
 CONFIG_SYS_CONSOLE_IS_IN_ENV=y
 CONFIG_SYS_CONSOLE_OVERWRITE_ROUTINE=y
 CONFIG_SYS_CONSOLE_INFO_QUIET=y
diff --git a/configs/brppt1_nand_defconfig b/configs/brppt1_nand_defconfig
index 907ce71..7846e55 100644
--- a/configs/brppt1_nand_defconfig
+++ b/configs/brppt1_nand_defconfig
@@ -9,7 +9,9 @@ CONFIG_SPL_SERIAL_SUPPORT=y
 CONFIG_SPL=y
 CONFIG_OF_BOARD_SETUP=y
 CONFIG_SYS_EXTRA_OPTIONS="SERIAL1,CONS_INDEX=1"
-CONFIG_BOOTDELAY=-2
+CONFIG_BOOTDELAY=0
+CONFIG_USE_BOOTCOMMAND=y
+CONFIG_BOOTCOMMAND="run b_default"
 CONFIG_SYS_CONSOLE_IS_IN_ENV=y
 CONFIG_SYS_CONSOLE_OVERWRITE_ROUTINE=y
 CONFIG_SYS_CONSOLE_INFO_QUIET=y
@@ -46,7 +48,7 @@ CONFIG_CMD_FAT=y
 CONFIG_CMD_FS_GENERIC=y
 CONFIG_CMD_MTDPARTS=y
 CONFIG_MTDIDS_DEFAULT="nand0=omap2-nand.0"
-CONFIG_MTDPARTS_DEFAULT="mtdparts=omap2-nand.0:128k(MLO),128k(MLO.backup),128k(dtb),128k(u-boot-env),512k(u-boot),4m(kernel),128m(rootfs),-(user)"
+CONFIG_MTDPARTS_DEFAULT="mtdparts=omap2-nand.0:128k(MLO),128k(cfgscr),128k(dtb),128k(u-boot-env),512k(u-boot),4m(kernel),128m(rootfs),-(user)"
 CONFIG_ENV_IS_IN_NAND=y
 CONFIG_NETCONSOLE=y
 CONFIG_BOOTCOUNT_LIMIT=y
diff --git a/configs/brppt1_spi_defconfig b/configs/brppt1_spi_defconfig
index 90054aa..f4197c4 100644
--- a/configs/brppt1_spi_defconfig
+++ b/configs/brppt1_spi_defconfig
@@ -13,7 +13,9 @@ CONFIG_SPL_SPI_SUPPORT=y
 CONFIG_OF_BOARD_SETUP=y
 CONFIG_SYS_EXTRA_OPTIONS="SERIAL1,CONS_INDEX=1,SPI_BOOT,EMMC_BOOT"
 CONFIG_SPI_BOOT=y
-CONFIG_BOOTDELAY=-2
+CONFIG_BOOTDELAY=0
+CONFIG_USE_BOOTCOMMAND=y
+CONFIG_BOOTCOMMAND="run b_default"
 CONFIG_SYS_CONSOLE_IS_IN_ENV=y
 CONFIG_SYS_CONSOLE_OVERWRITE_ROUTINE=y
 CONFIG_SYS_CONSOLE_INFO_QUIET=y
diff --git a/include/configs/brppt1.h b/include/configs/brppt1.h
index 32bb83c..d5b2573 100644
--- a/include/configs/brppt1.h
+++ b/include/configs/brppt1.h
@@ -16,6 +16,7 @@
 /* ------------------------------------------------------------------------- */
 /* memory */
 #define CONFIG_SYS_MALLOC_LEN		(5 * 1024 * 1024)
+#define CONFIG_SYS_BOOTM_LEN		SZ_32M
 
 /* Clock Defines */
 #define V_OSCK				26000000  /* Clock output from T2 */
@@ -56,100 +57,88 @@
 #define CONFIG_ENV_SIZE			(64 << 10)
 
 #ifdef CONFIG_NAND
-#define NANDARGS \
-	"mtdids=" CONFIG_MTDIDS_DEFAULT "\0" \
-	"mtdparts=" CONFIG_MTDPARTS_DEFAULT "\0" \
-	"nandargs=setenv bootargs console=${console} " \
-		"${optargs} " \
-		"${optargs_rot} " \
-		"root=mtd6 " \
-		"rootfstype=jffs2\0" \
-	"kernelsize=0x400000\0" \
-	"nandboot=echo booting from nand ...; " \
-		"run nandargs; " \
-		"nand read ${loadaddr} kernel ${kernelsize}; " \
-		"bootz ${loadaddr} - ${dtbaddr}\0" \
-	"defboot=run nandboot\0" \
-	"bootlimit=1\0" \
-	"simplefb=1\0 " \
-	"altbootcmd=run usbscript\0"
+#define NANDTGTS \
+"mtdids=" CONFIG_MTDIDS_DEFAULT "\0" \
+"mtdparts=" CONFIG_MTDPARTS_DEFAULT "\0" \
+"cfgscr=nand read ${cfgaddr} cfgscr && source ${cfgaddr}\0" \
+"nandargs=setenv bootargs console=${console} ${optargs} ${optargs_rot} " \
+	"root=mtd6 rootfstype=jffs2 b_mode=${b_mode}\0" \
+"b_nand=nand read ${loadaddr} kernel; nand read ${dtbaddr} dtb; " \
+	"run nandargs; run cfgscr; bootz ${loadaddr} - ${dtbaddr}\0" \
+"b_tgts_std=usb0 nand net\0" \
+"b_tgts_rcy=net usb0 nand\0" \
+"b_tgts_pme=usb0 nand net\0"
 #else
-#define NANDARGS ""
+#define NANDTGTS ""
 #endif /* CONFIG_NAND */
 
+#define MMCSPI_TGTS \
+"t30args#0=setenv bootargs ${optargs_rot} ${optargs} console=${console} " \
+	"b_mode=${b_mode} root=/dev/mmcblk0p2 rootfstype=ext4\0" \
+"b_t30lgcy#0=" \
+	"load ${loaddev}:2 ${loadaddr} /boot/PPTImage.md5 && " \
+	"load ${loaddev}:2 ${loadaddr} /boot/zImage && " \
+	"load ${loaddev}:2 ${dtbaddr} /boot/am335x-ppt30.dtb || " \
+	"load ${loaddev}:1 ${dtbaddr} am335x-ppt30-legacy.dtb; "\
+	"run t30args#0; run cfgscr; bootz ${loadaddr} - ${dtbaddr}\0" \
+"t30args#1=setenv bootargs ${optargs_rot} ${optargs} console=${console} " \
+	"b_mode=${b_mode}\0" \
+"b_t30lgcy#1=" \
+	"load ${loaddev}:1 ${loadaddr} zImage && " \
+	"load ${loaddev}:1 ${dtbaddr} am335x-ppt30.dtb && " \
+	"load ${loaddev}:1 ${ramaddr} rootfsPPT30.uboot && " \
+	"run t30args#1; run cfgscr; bootz ${loadaddr} ${ramaddr} ${dtbaddr}\0" \
+"b_mmc0=load ${loaddev}:1 ${scraddr} bootscr.img && source ${scraddr}\0" \
+"b_mmc1=load ${loaddev}:1 ${scraddr} /boot/bootscr.img && source ${scraddr}\0" \
+"b_tgts_std=mmc0 mmc1 t30lgcy#0 t30lgcy#1 usb0 net\0" \
+"b_tgts_rcy=t30lgcy#1 usb0 net\0" \
+"b_tgts_pme=net usb0 mmc0 mmc1\0" \
+"loaddev=mmc 1\0"
+
 #ifdef CONFIG_MMC
-#define MMCARGS \
-"dtbdev=mmc\0" \
-"dtbpart=1:1\0" \
-"mmcroot0=setenv bootargs ${optargs_rot} ${optargs} console=${console}\0" \
-"mmcroot1=setenv bootargs ${optargs_rot} ${optargs} console=${console} " \
-	"root=/dev/mmcblk0p2 rootfstype=ext4\0" \
-"mmcboot0=echo booting Updatesystem from mmc (ext4-fs) ...; " \
-	"setenv simplefb 1; " \
-	"ext4load mmc 1:1 ${loadaddr} /${kernel}; " \
-	"ext4load mmc 1:1 ${ramaddr} /${ramdisk}; " \
-	"run mmcroot0; bootz ${loadaddr} ${ramaddr} ${dtbaddr};\0" \
-"mmcboot1=echo booting PPT-OS from mmc (ext4-fs) ...; " \
-	"setenv simplefb 0; " \
-	"ext4load mmc 1:2 ${loadaddr} /boot/${kernel}; " \
-	"run mmcroot1; bootz ${loadaddr} - ${dtbaddr};\0" \
-"defboot=ext4load mmc 1:2 ${loadaddr} /boot/PPTImage.md5 && run mmcboot1; " \
-	"ext4load mmc 1:1 ${dtbaddr} /$dtb && run mmcboot0; " \
-	"run ramboot; run usbscript;\0" \
-"bootlimit=1\0" \
-"altbootcmd=mmc dev 1; run mmcboot0;\0" \
-"upduboot=dhcp; " \
-	"tftp ${loadaddr} MLO && mmc write ${loadaddr} 100 100; " \
-	"tftp ${loadaddr} u-boot.img && mmc write ${loadaddr} 300 400;\0"
+#define MMCTGTS \
+MMCSPI_TGTS \
+"cfgscr=mmc dev 1; mmc read ${cfgaddr} 200 80; source ${cfgaddr}\0"
 #else
-#define MMCARGS ""
+#define MMCTGTS ""
 #endif /* CONFIG_MMC */
 
+#ifdef CONFIG_SPI
+#define SPITGTS \
+MMCSPI_TGTS \
+"cfgscr=sf probe; sf read ${cfgaddr} 0xC0000 10000; source ${cfgaddr}\0"
+#else
+#define SPITGTS ""
+#endif /* CONFIG_SPI */
+
+#define LOAD_OFFSET(x)			0x8##x
+
 #ifndef CONFIG_SPL_BUILD
 #define CONFIG_EXTRA_ENV_SETTINGS \
 BUR_COMMON_ENV \
 "verify=no\0" \
 "autoload=0\0" \
-"dtb=bur-ppt-ts30.dtb\0" \
-"dtbaddr=0x80100000\0" \
-"loadaddr=0x80200000\0" \
-"ramaddr=0x80A00000\0" \
-"kernel=zImage\0" \
-"ramdisk=rootfs.cpio.uboot\0" \
+"scraddr=" __stringify(LOAD_OFFSET(0000000)) "\0" \
+"cfgaddr=" __stringify(LOAD_OFFSET(0020000)) "\0" \
+"dtbaddr=" __stringify(LOAD_OFFSET(0040000)) "\0" \
+"loadaddr=" __stringify(LOAD_OFFSET(0100000)) "\0" \
+"ramaddr=" __stringify(LOAD_OFFSET(2000000)) "\0" \
 "console=ttyO0,115200n8\0" \
 "optargs=consoleblank=0 quiet panic=2\0" \
-"nfsroot=/tftpboot/tseries/rootfs-small\0" \
-"nfsopts=nolock\0" \
-"ramargs=setenv bootargs ${optargs} console=${console} root=/dev/ram0\0" \
-"netargs=setenv bootargs console=${console} " \
-	"${optargs} " \
-	"root=/dev/nfs " \
-	"nfsroot=${serverip}:${nfsroot},${nfsopts} rw " \
-	"ip=dhcp\0" \
-"netboot=echo Booting from network ...; " \
-	"dhcp; " \
-	"tftp ${loadaddr} ${kernel}; " \
-	"tftp ${dtbaddr} ${dtb}; " \
-	"run netargs; " \
-	"bootz ${loadaddr} - ${dtbaddr}\0" \
-"ramboot=echo Booting from network into RAM ...; "\
-	"if dhcp; then; " \
-	"tftp ${loadaddr} ${kernel}; " \
-	"tftp ${ramaddr} ${ramdisk}; " \
-	"if ext4load ${dtbdev} ${dtbpart} ${dtbaddr} /${dtb}; " \
-	"then; else tftp ${dtbaddr} ${dtb}; fi;" \
-	"run mmcroot0; " \
-	"bootz ${loadaddr} ${ramaddr} ${dtbaddr}; fi;\0" \
-"netupdate=echo Updating UBOOT from Network (TFTP) ...; " \
-	"setenv autoload 0; " \
-	"dhcp && tftp 0x80000000 updateUBOOT.img && source;\0" \
-NANDARGS \
-MMCARGS
+"b_break=0\0" \
+"b_usb0=usb start && load usb 0 ${scraddr} bootscr.img && source ${scraddr}\0" \
+"b_net=tftp ${scraddr} netscript.img && source ${scraddr}\0" \
+MMCTGTS \
+SPITGTS \
+NANDTGTS \
+"b_deftgts=if test ${b_mode} = 12; then setenv b_tgts ${b_tgts_pme};" \
+" elif test ${b_mode} = 0; then setenv b_tgts ${b_tgts_rcy};" \
+" else setenv b_tgts ${b_tgts_std}; fi\0" \
+"b_default=run b_deftgts; for target in ${b_tgts};"\
+" do echo \"### booting ${target} ###\"; run b_${target};" \
+" if test ${b_break} = 1; then; exit; fi; done\0"
 #endif /* !CONFIG_SPL_BUILD*/
 
-#define CONFIG_BOOTCOMMAND \
-	"mmc dev 1; run defboot;"
-
 #ifdef CONFIG_NAND
 /*
  * GPMC  block.  We support 1 device and the physical address to
-- 
2.7.4



More information about the U-Boot mailing list