ARM64: zynqmp: Add support for standard distro boot commands
PATCH v2 1/1 ARM64: zynqmp: Add support for standard distro boot commands
Nand and QSPI are not defined now but this will be extended. Based on selected bootmode boot_targets are rewritten. Patch also contains detection if variables are saved. If yes don't rewrite boot_targets variable.
Also move variable setup to the end of file because SCSI needs to be defined before others macros are using it.
---
Changes in v2:
- Append default boot_targets to the list
Patch depends on
"env: Setup GD_FLG_ENV_DEFAULT flag when default environment are used"
--- board/xilinx/zynqmp/zynqmp.c | 27 ++++++++++++++----- include/configs/xilinx_zynqmp.h | 59 ++++++++++++++++++++++++++++++----------- 2 files changed, 64 insertions(+), 22 deletions(-)
board/xilinx/zynqmp/zynqmp.c +20 -7
@@ -215,6 +215,11 @@ int board_late_init(void)u32 reg =0 ;u8 bootmode; +if (!(gd->flags &GD_FLG_ENV_DEFAULT )) { +debug ("Saved variables - Skipping\n" ); +return 0 ; + } + reg =readl (&crlapb_base->boot_mode); bootmode = reg &BOOT_MODES_MASK ;
@@ -222,31 +227,39 @@ int board_late_init(void)switch (bootmode) {case JTAG_MODE :puts ("JTAG_MODE\n" ); -setenv ("modeboot" ,"jtagboot" ); +setenv ("boot_targets" ,strcat ("pxe dhcp " , +getenv ("boot_targets" )));break ;case QSPI_MODE_24BIT :case QSPI_MODE_32BIT : -setenv ("modeboot" ,"qspiboot" ); +setenv ("boot_targets" ,strcat ("qspi0 " , +getenv ("boot_targets" )));puts ("QSPI_MODE\n" );break ;case EMMC_MODE :puts ("EMMC_MODE\n" ); -setenv ("modeboot" ,"sdboot" ); +setenv ("boot_targets" ,strcat ("mmc0 " , +getenv ("boot_targets" )));break ;case SD_MODE :puts ("SD_MODE\n" ); -setenv ("modeboot" ,"sdboot" ); +setenv ("boot_targets" ,strcat ("mmc0 " , +getenv ("boot_targets" )));break ;case SD_MODE1 :puts ("SD_MODE1\n" );#if defined(CONFIG_ZYNQ_SDHCI0 ) && defined(CONFIG_ZYNQ_SDHCI1 ) -setenv ("sdbootdev" ,"1" ); +setenv ("boot_targets" ,strcat ("mmc1 " , +getenv ("boot_targets" ))); +#else +setenv ("boot_targets" ,strcat ("mmc0 " , +getenv ("boot_targets" )));#endif -setenv ("modeboot" ,"sdboot" );break ;case NAND_MODE :puts ("NAND_MODE\n" ); -setenv ("modeboot" ,"nandboot" ); +setenv ("boot_targets" ,strcat ("nand0 " , +getenv ("boot_targets" )));break ;default :printf ("Invalid Boot Mode:0x%x\n" , bootmode);
include/configs/xilinx_zynqmp.h +44 -15
71 lines not on this page · raw message
Signature · 1 line
1.9.1
PATCH v2 1/1 ARM64: zynqmp: Add support for standard distro boot commands
Quoted 39 lines · Michal Simek
Nand and QSPI are not defined now but this will be extended. Based on selected bootmode
boot_targetsare rewritten. Patch also contains detection if variables are saved. If yes don't rewriteboot_targetsvariable.Also move variable setup to the end of file because SCSI needs to be defined before others macros are using it.
Signed-off-by Michal Simek <[email protected]>---
Changes in v2:
- Append defaultboot_targetsto the listPatch depends on
"env: SetupGD_FLG_ENV_DEFAULTflag when default environment are used"--- board/xilinx/zynqmp/zynqmp.c | 27 ++++++++++++++----- include/configs/xilinx_zynqmp.h | 59 ++++++++++++++++++++++++++++++----------- 2 files changed, 64 insertions(+), 22 deletions(-)board/xilinx/zynqmp/zynqmp.c +5
-0@@ -215,6 +215,11 @@ int board_late_init(void)u32 reg =0 ;u8 bootmode; +if (!(gd->flags &GD_FLG_ENV_DEFAULT )) { +debug ("Saved variables - Skipping\n" ); +return 0 ; + } + reg =readl (&crlapb_base->boot_mode); bootmode = reg &BOOT_MODES_MASK ;
board/xilinx/zynqmp/zynqmp.c int board_late_init(void) · line 231
Quoted 6 lines
board/xilinx/zynqmp/zynqmp.c +2
-1@@ -222,31 +227,39 @@ int board_late_init(void)switch (bootmode) {case JTAG_MODE :puts ("JTAG_MODE\n" ); -setenv ("modeboot" ,"jtagboot" ); +setenv ("boot_targets" ,strcat ("pxe dhcp " , +getenv ("boot_targets" )));
The strcat() function appends the src string to the dest
string, overwriting the terminating null byte ('\0') at the end of dest, and then adds a terminating null byte. The strings may
not overlap, and the dest string must have enough space for the
result. If dest is not large enough, program behavior is unpredictable; buffer overruns are a favorite avenue for attacking
secure programs.
---
In other words, the code above creates a buffer overflow :). You need something like
const char *new_targets = "pxe dhcp"; // <- make this a parameter to a
function
new_targets = malloc(strlen(new_targets) +strlen(getenv("boot_targets") + 2); // one byte for the space, one for the null-terminator
sprintf(new_targets, "%s %s", new_targets, boot_targets); setenv("boot_targets", new_targets);
Isn't string handling in C awesome? It's almost as readable and easy as doing it in assembly.
Alex
PATCH v2 1/1 ARM64: zynqmp: Add support for standard distro boot commands
Quoted 65 lines · Alexander Graf
Quoted 39 lines · Michal Simek
Nand and QSPI are not defined now but this will be extended. Based on selected bootmode
boot_targetsare rewritten. Patch also contains detection if variables are saved. If yes don't rewriteboot_targetsvariable.Also move variable setup to the end of file because SCSI needs to be defined before others macros are using it.
Signed-off-by Michal Simek <[email protected]>---
Changes in v2:
- Append defaultboot_targetsto the listPatch depends on
"env: SetupGD_FLG_ENV_DEFAULTflag when default environment are used"--- board/xilinx/zynqmp/zynqmp.c | 27 ++++++++++++++----- include/configs/xilinx_zynqmp.h | 59 ++++++++++++++++++++++++++++++----------- 2 files changed, 64 insertions(+), 22 deletions(-)board/xilinx/zynqmp/zynqmp.c +5
-0@@ -215,6 +215,11 @@ int board_late_init(void)u32 reg =0 ;u8 bootmode; +if (!(gd->flags &GD_FLG_ENV_DEFAULT )) { +debug ("Saved variables - Skipping\n" ); +return 0 ; + } + reg =readl (&crlapb_base->boot_mode); bootmode = reg &BOOT_MODES_MASK ;board/xilinx/zynqmp/zynqmp.c int board_late_init(void) · line 231
Quoted 6 lines
board/xilinx/zynqmp/zynqmp.c +2
-1@@ -222,31 +227,39 @@ int board_late_init(void)switch (bootmode) {case JTAG_MODE :puts ("JTAG_MODE\n" ); -setenv ("modeboot" ,"jtagboot" ); +setenv ("boot_targets" ,strcat ("pxe dhcp " , +getenv ("boot_targets" )));The
strcat()function appends the src string to the dest
string, overwriting the terminating null byte ('\0') at the end of dest, and then adds a terminating null byte. The strings may
not overlap, and the dest string must have enough space for the
result. If dest is not large enough, program behavior is unpredictable; buffer overruns are a favorite avenue for attacking
secure programs.---
In other words, the code above creates a buffer overflow :). You need something like
const char
*new_targets= "pxe dhcp"; // <- make this a parameter to a
function
Quoted 8 lines
new_targets= malloc(strlen(new_targets) +strlen(getenv("boot_targets") + 2); // one byte for the space, one for the null-terminator
sprintf(new_targets, "%s %s", new_targets, boot_targets);setenv("boot_targets", new_targets);Isn't string handling in C awesome? It's almost as readable and easy as doing it in assembly.
Time for holiday.
Thanks,
Michal