[PATCH u-boot-mvebu 00/31] kwboot / kwbimage improvements

Hi Stefan and others,
this is a series of improvements to kwboot, kwbimage and mvebu.
The main goal of this series is to correctly use BootROM's code for loading U-Boot from NOR / NAND: currently only SPL is read by BootROM and the main U-Boot is read by SPL. By using BootROM to also load main U-Boot we can reduce the size of SPL image, since it does not need to contain code for reading NOR / NAND.
Before merging, this series should be tested on as many relevant boards as possible.
Marek & Pali
Marek Behún (2): tools: kwbimage: Add constant for SDIO bootfrom tools: kwbimage: Cosmetic fix - remove redundant space character
Pali Rohár (29): tools: kwbimage: Fix compilation without CONFIG_SYS_U_BOOT_OFFS tools: kwbimage: Simplify aligning and calculating checksum tools: kwbimage: Align SPI and NAND images to 256 bytes tools: kwbimage: Fix generation of SATA, SDIO and PCIe images tools: kwbimage: Don't crash when binary file name does not contain '/' tools: kwbimage: Fix check for v0 extended header checksum tools: kwbimage: Validate extended headers of v1 images tools: kwbimage: Validate data checksum of v1 images tools: kwbimage: Print size of binary header in kwbimage_print_header() tools: kwboot: Fix wrong parameter passed to read() tools: kwboot: Fix restoring terminal tools: kwboot: Print trailing newline after terminal is terminated tools: kwboot: Cosmetic fix - add missing curly brackets tools: kwboot: Check for v1 header size tools: kwbimage: Use -a parameter (load address) for v1 images arm: mvebu: Fix return_to_bootrom() arm: mvebu: Mark return_to_bootrom() as a noreturn function arm: mvebu: Implement return_to_bootrom() via U-Boot's SPL framework arm: mvebu: Use U-Boot's SPL BootROM framework for booting from NAND/UART arm: mvebu: Always use BootROM for loading the rest of U-Boot's binary arm: mvebu: gdsys: Remove custom spl_board_init() arm: mvebu: Remove legacy U-Boot header from kwbimage v1 files tools: kwbimage: Remove v1 kwbimage SPL padding to CONFIG_SYS_U_BOOT_OFFS bytes arm: mvebu: Remove unused macro CONFIG_SYS_U_BOOT_OFFS tools: kwbimage: Add support for more BINARY headers tools: kwbimage: Don't parse PAYLOAD keyword tools: kwbimage: Add support for DATA command also for v1 images tools: kwbimage: Add support for a new DATA_DELAY command tools: kwbimage: Do not hide usage of secure header under CONFIG_ARMADA_38X
Makefile | 2 +- arch/arm/mach-mvebu/Kconfig | 16 +- arch/arm/mach-mvebu/include/mach/cpu.h | 2 +- arch/arm/mach-mvebu/lowlevel_spl.S | 3 +- arch/arm/mach-mvebu/spl.c | 90 +------ board/gdsys/a38x/Makefile | 2 +- board/gdsys/a38x/spl.c | 20 -- include/configs/clearfog.h | 6 +- include/configs/controlcenterdc.h | 8 +- include/configs/db-88f6720.h | 3 - include/configs/db-88f6820-amc.h | 5 - include/configs/db-88f6820-gp.h | 6 - include/configs/db-mv784mp-gp.h | 3 - include/configs/ds414.h | 5 - include/configs/helios4.h | 6 +- include/configs/theadorable.h | 3 - include/configs/turris_omnia.h | 6 - include/configs/x530.h | 3 - scripts/config_whitelist.txt | 1 - tools/Makefile | 8 - tools/kwbimage.c | 339 +++++++++++++++++-------- tools/kwbimage.h | 30 ++- tools/kwboot.c | 14 +- 23 files changed, 296 insertions(+), 285 deletions(-) delete mode 100644 board/gdsys/a38x/spl.c

From: Pali Rohár pali@kernel.org
The CONFIG_SYS_U_BOOT_OFFS option may be defined as empty string. In this case it causes compilation error:
tools/kwbimage.c: In function ‘image_headersz_v1’: tools/kwbimage.c:1002:39: error: expected expression before ‘)’ token if (headersz > CONFIG_SYS_U_BOOT_OFFS) { ^ tools/kwbimage.c:1006:41: error: expected expression before ‘)’ token (int)headersz, CONFIG_SYS_U_BOOT_OFFS); ^ tools/kwbimage.c:1011:35: error: expected expression before ‘;’ token headersz = CONFIG_SYS_U_BOOT_OFFS; ^ make[1]: *** [scripts/Makefile.host:112: tools/kwbimage.o] Error 1 make: *** [Makefile:1822: tools] Error 2
Check whether the value of CONFIG_SYS_U_BOOT_OFFS is really set.
Signed-off-by: Pali Rohár pali@kernel.org Reviewed-by: Marek Behún marek.behun@nic.cz --- tools/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tools/Makefile b/tools/Makefile index d020c55d66..fadf3135d6 100644 --- a/tools/Makefile +++ b/tools/Makefile @@ -155,7 +155,7 @@ ifdef CONFIG_FIT_CIPHER HOST_EXTRACFLAGS += -DCONFIG_FIT_CIPHER endif
-ifdef CONFIG_SYS_U_BOOT_OFFS +ifneq ($(CONFIG_SYS_U_BOOT_OFFS),) HOSTCFLAGS_kwbimage.o += -DCONFIG_SYS_U_BOOT_OFFS=$(CONFIG_SYS_U_BOOT_OFFS) endif

On 08.07.21 19:30, Marek Behún wrote:
From: Pali Rohár pali@kernel.org
The CONFIG_SYS_U_BOOT_OFFS option may be defined as empty string. In this case it causes compilation error:
tools/kwbimage.c: In function ‘image_headersz_v1’: tools/kwbimage.c:1002:39: error: expected expression before ‘)’ token if (headersz > CONFIG_SYS_U_BOOT_OFFS) { ^ tools/kwbimage.c:1006:41: error: expected expression before ‘)’ token (int)headersz, CONFIG_SYS_U_BOOT_OFFS); ^ tools/kwbimage.c:1011:35: error: expected expression before ‘;’ token headersz = CONFIG_SYS_U_BOOT_OFFS; ^ make[1]: *** [scripts/Makefile.host:112: tools/kwbimage.o] Error 1 make: *** [Makefile:1822: tools] Error 2
Check whether the value of CONFIG_SYS_U_BOOT_OFFS is really set.
Signed-off-by: Pali Rohár pali@kernel.org Reviewed-by: Marek Behún marek.behun@nic.cz
Reviewed-by: Stefan Roese sr@denx.de
Thanks, Stefan
tools/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tools/Makefile b/tools/Makefile index d020c55d66..fadf3135d6 100644 --- a/tools/Makefile +++ b/tools/Makefile @@ -155,7 +155,7 @@ ifdef CONFIG_FIT_CIPHER HOST_EXTRACFLAGS += -DCONFIG_FIT_CIPHER endif
-ifdef CONFIG_SYS_U_BOOT_OFFS +ifneq ($(CONFIG_SYS_U_BOOT_OFFS),) HOSTCFLAGS_kwbimage.o += -DCONFIG_SYS_U_BOOT_OFFS=$(CONFIG_SYS_U_BOOT_OFFS) endif
Viele Grüße, Stefan

From: Pali Rohár pali@kernel.org
The return value of kwbimage_generate() is used for aligning the data part of kwbimage. Use it for calculating proper 4 byte alignment as is required by BootROM and also use it for allocating additional 4 bytes for the 32-bit data checksum.
This simplifies the alignment code to be only at one place (in function kwbimage_generate) and also simplifies setting checksum as it can be directly updated in memory.
Signed-off-by: Pali Rohár pali@kernel.org Reviewed-by: Marek Behún marek.behun@nic.cz --- tools/kwbimage.c | 36 +++++++++++++++--------------------- 1 file changed, 15 insertions(+), 21 deletions(-)
diff --git a/tools/kwbimage.c b/tools/kwbimage.c index 02fd0c949f..c775abf0e3 100644 --- a/tools/kwbimage.c +++ b/tools/kwbimage.c @@ -891,7 +891,7 @@ static void *image_create_v0(size_t *imagesz, struct image_tool_params *params,
/* Fill in the main header */ main_hdr->blocksize = - cpu_to_le32(payloadsz + sizeof(uint32_t) - headersz); + cpu_to_le32(payloadsz - headersz); main_hdr->srcaddr = cpu_to_le32(headersz); main_hdr->ext = has_ext; main_hdr->destaddr = cpu_to_le32(params->addr); @@ -1249,7 +1249,7 @@ static void *image_create_v1(size_t *imagesz, struct image_tool_params *params,
/* Fill the main header */ main_hdr->blocksize = - cpu_to_le32(payloadsz - headersz + sizeof(uint32_t)); + cpu_to_le32(payloadsz - headersz); main_hdr->headersz_lsb = cpu_to_le16(headersz & 0xFFFF); main_hdr->headersz_msb = (headersz & 0xFFFF0000) >> 16; main_hdr->destaddr = cpu_to_le32(params->addr) @@ -1519,7 +1519,6 @@ static void kwbimage_set_header(void *ptr, struct stat *sbuf, int ifd, size_t headersz = 0; uint32_t checksum; int ret; - int size;
fcfg = fopen(params->imagename, "r"); if (!fcfg) { @@ -1547,9 +1546,6 @@ static void kwbimage_set_header(void *ptr, struct stat *sbuf, int ifd, exit(EXIT_FAILURE); }
- /* The MVEBU BootROM does not allow non word aligned payloads */ - sbuf->st_size = ALIGN(sbuf->st_size, 4); - version = image_get_version(); switch (version) { /* @@ -1580,16 +1576,10 @@ static void kwbimage_set_header(void *ptr, struct stat *sbuf, int ifd, free(image_cfg);
/* Build and add image checksum header */ - checksum = - cpu_to_le32(image_checksum32((uint32_t *)ptr, sbuf->st_size)); - size = write(ifd, &checksum, sizeof(uint32_t)); - if (size != sizeof(uint32_t)) { - fprintf(stderr, "Error:%s - Checksum write %d bytes %s\n", - params->cmdname, size, params->imagefile); - exit(EXIT_FAILURE); - } - - sbuf->st_size += sizeof(uint32_t); + checksum = cpu_to_le32(image_checksum32((uint8_t *)ptr + headersz, + sbuf->st_size - headersz - sizeof(uint32_t))); + memcpy((uint8_t *)ptr + sbuf->st_size - sizeof(uint32_t), &checksum, + sizeof(uint32_t));
/* Finally copy the header into the image area */ memcpy(ptr, image, headersz); @@ -1650,6 +1640,7 @@ static int kwbimage_generate(struct image_tool_params *params, struct image_type_params *tparams) { FILE *fcfg; + struct stat s; int alloc_len; int version; void *hdr; @@ -1662,6 +1653,12 @@ static int kwbimage_generate(struct image_tool_params *params, exit(EXIT_FAILURE); }
+ if (stat(params->datafile, &s)) { + fprintf(stderr, "Could not stat data file %s: %s\n", + params->datafile, strerror(errno)); + exit(EXIT_FAILURE); + } + image_cfg = malloc(IMAGE_CFG_ELEMENT_MAX * sizeof(struct image_cfg_element)); if (!image_cfg) { @@ -1719,12 +1716,9 @@ static int kwbimage_generate(struct image_tool_params *params, /* * The resulting image needs to be 4-byte aligned. At least * the Marvell hdrparser tool complains if its unaligned. - * By returning 1 here in this function, called via - * tparams->vrec_header() in mkimage.c, mkimage will - * automatically pad the the resulting image to a 4-byte - * size if necessary. + * After the image data is stored 4-byte checksum. */ - return 1; + return 4 + (4 - s.st_size % 4) % 4; }
/*

On 08.07.21 19:30, Marek Behún wrote:
From: Pali Rohár pali@kernel.org
The return value of kwbimage_generate() is used for aligning the data part of kwbimage. Use it for calculating proper 4 byte alignment as is required by BootROM and also use it for allocating additional 4 bytes for the 32-bit data checksum.
This simplifies the alignment code to be only at one place (in function kwbimage_generate) and also simplifies setting checksum as it can be directly updated in memory.
Signed-off-by: Pali Rohár pali@kernel.org Reviewed-by: Marek Behún marek.behun@nic.cz
Reviewed-by: Stefan Roese sr@denx.de
Thanks, Stefan
tools/kwbimage.c | 36 +++++++++++++++--------------------- 1 file changed, 15 insertions(+), 21 deletions(-)
diff --git a/tools/kwbimage.c b/tools/kwbimage.c index 02fd0c949f..c775abf0e3 100644 --- a/tools/kwbimage.c +++ b/tools/kwbimage.c @@ -891,7 +891,7 @@ static void *image_create_v0(size_t *imagesz, struct image_tool_params *params,
/* Fill in the main header */ main_hdr->blocksize =
cpu_to_le32(payloadsz + sizeof(uint32_t) - headersz);
main_hdr->srcaddr = cpu_to_le32(headersz); main_hdr->ext = has_ext; main_hdr->destaddr = cpu_to_le32(params->addr);cpu_to_le32(payloadsz - headersz);
@@ -1249,7 +1249,7 @@ static void *image_create_v1(size_t *imagesz, struct image_tool_params *params,
/* Fill the main header */ main_hdr->blocksize =
cpu_to_le32(payloadsz - headersz + sizeof(uint32_t));
main_hdr->headersz_lsb = cpu_to_le16(headersz & 0xFFFF); main_hdr->headersz_msb = (headersz & 0xFFFF0000) >> 16; main_hdr->destaddr = cpu_to_le32(params->addr)cpu_to_le32(payloadsz - headersz);
@@ -1519,7 +1519,6 @@ static void kwbimage_set_header(void *ptr, struct stat *sbuf, int ifd, size_t headersz = 0; uint32_t checksum; int ret;
int size;
fcfg = fopen(params->imagename, "r"); if (!fcfg) {
@@ -1547,9 +1546,6 @@ static void kwbimage_set_header(void *ptr, struct stat *sbuf, int ifd, exit(EXIT_FAILURE); }
- /* The MVEBU BootROM does not allow non word aligned payloads */
- sbuf->st_size = ALIGN(sbuf->st_size, 4);
- version = image_get_version(); switch (version) { /*
@@ -1580,16 +1576,10 @@ static void kwbimage_set_header(void *ptr, struct stat *sbuf, int ifd, free(image_cfg);
/* Build and add image checksum header */
- checksum =
cpu_to_le32(image_checksum32((uint32_t *)ptr, sbuf->st_size));
- size = write(ifd, &checksum, sizeof(uint32_t));
- if (size != sizeof(uint32_t)) {
fprintf(stderr, "Error:%s - Checksum write %d bytes %s\n",
params->cmdname, size, params->imagefile);
exit(EXIT_FAILURE);
- }
- sbuf->st_size += sizeof(uint32_t);
checksum = cpu_to_le32(image_checksum32((uint8_t *)ptr + headersz,
sbuf->st_size - headersz - sizeof(uint32_t)));
memcpy((uint8_t *)ptr + sbuf->st_size - sizeof(uint32_t), &checksum,
sizeof(uint32_t));
/* Finally copy the header into the image area */ memcpy(ptr, image, headersz);
@@ -1650,6 +1640,7 @@ static int kwbimage_generate(struct image_tool_params *params, struct image_type_params *tparams) { FILE *fcfg;
- struct stat s; int alloc_len; int version; void *hdr;
@@ -1662,6 +1653,12 @@ static int kwbimage_generate(struct image_tool_params *params, exit(EXIT_FAILURE); }
- if (stat(params->datafile, &s)) {
fprintf(stderr, "Could not stat data file %s: %s\n",
params->datafile, strerror(errno));
exit(EXIT_FAILURE);
- }
- image_cfg = malloc(IMAGE_CFG_ELEMENT_MAX * sizeof(struct image_cfg_element)); if (!image_cfg) {
@@ -1719,12 +1716,9 @@ static int kwbimage_generate(struct image_tool_params *params, /* * The resulting image needs to be 4-byte aligned. At least * the Marvell hdrparser tool complains if its unaligned.
* By returning 1 here in this function, called via
* tparams->vrec_header() in mkimage.c, mkimage will
* automatically pad the the resulting image to a 4-byte
* size if necessary.
*/* After the image data is stored 4-byte checksum.
- return 1;
return 4 + (4 - s.st_size % 4) % 4; }
/*
Viele Grüße, Stefan

From: Pali Rohár pali@kernel.org
Writing into SPI NOR and NAND memory can be done only in 256 bytes long blocks. Align final image size so that when it is burned into SPI NOR or NAND memory via U-Boot's commands (sf or mtd), we can use the $filesize variable directly as the length argument.
Signed-off-by: Pali Rohár pali@kernel.org Reviewed-by: Marek Behún marek.behun@nic.cz --- tools/kwbimage.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-)
diff --git a/tools/kwbimage.c b/tools/kwbimage.c index c775abf0e3..f40ba0994d 100644 --- a/tools/kwbimage.c +++ b/tools/kwbimage.c @@ -1510,6 +1510,17 @@ static int image_get_version(void) return e->version; }
+static int image_get_bootfrom(void) +{ + struct image_cfg_element *e; + + e = image_find_option(IMAGE_CFG_BOOT_FROM); + if (!e) + return -1; + + return e->bootfrom; +} + static void kwbimage_set_header(void *ptr, struct stat *sbuf, int ifd, struct image_tool_params *params) { @@ -1642,6 +1653,7 @@ static int kwbimage_generate(struct image_tool_params *params, FILE *fcfg; struct stat s; int alloc_len; + int bootfrom; int version; void *hdr; int ret; @@ -1678,6 +1690,7 @@ static int kwbimage_generate(struct image_tool_params *params, exit(EXIT_FAILURE); }
+ bootfrom = image_get_bootfrom(); version = image_get_version(); switch (version) { /* @@ -1717,8 +1730,12 @@ static int kwbimage_generate(struct image_tool_params *params, * The resulting image needs to be 4-byte aligned. At least * the Marvell hdrparser tool complains if its unaligned. * After the image data is stored 4-byte checksum. + * Final SPI and NAND images must be aligned to 256 bytes. */ - return 4 + (4 - s.st_size % 4) % 4; + if (bootfrom == IBR_HDR_SPI_ID || bootfrom == IBR_HDR_NAND_ID) + return 4 + (256 - (alloc_len + s.st_size + 4) % 256) % 256; + else + return 4 + (4 - s.st_size % 4) % 4; }
/*

On 08.07.21 19:30, Marek Behún wrote:
From: Pali Rohár pali@kernel.org
Writing into SPI NOR and NAND memory can be done only in 256 bytes long blocks. Align final image size so that when it is burned into SPI NOR or NAND memory via U-Boot's commands (sf or mtd), we can use the $filesize variable directly as the length argument.
Signed-off-by: Pali Rohár pali@kernel.org Reviewed-by: Marek Behún marek.behun@nic.cz
Reviewed-by: Stefan Roese sr@denx.de
Thanks, Stefan
tools/kwbimage.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-)
diff --git a/tools/kwbimage.c b/tools/kwbimage.c index c775abf0e3..f40ba0994d 100644 --- a/tools/kwbimage.c +++ b/tools/kwbimage.c @@ -1510,6 +1510,17 @@ static int image_get_version(void) return e->version; }
+static int image_get_bootfrom(void) +{
- struct image_cfg_element *e;
- e = image_find_option(IMAGE_CFG_BOOT_FROM);
- if (!e)
return -1;
- return e->bootfrom;
+}
- static void kwbimage_set_header(void *ptr, struct stat *sbuf, int ifd, struct image_tool_params *params) {
@@ -1642,6 +1653,7 @@ static int kwbimage_generate(struct image_tool_params *params, FILE *fcfg; struct stat s; int alloc_len;
- int bootfrom; int version; void *hdr; int ret;
@@ -1678,6 +1690,7 @@ static int kwbimage_generate(struct image_tool_params *params, exit(EXIT_FAILURE); }
- bootfrom = image_get_bootfrom(); version = image_get_version(); switch (version) { /*
@@ -1717,8 +1730,12 @@ static int kwbimage_generate(struct image_tool_params *params, * The resulting image needs to be 4-byte aligned. At least * the Marvell hdrparser tool complains if its unaligned. * After the image data is stored 4-byte checksum.
*/* Final SPI and NAND images must be aligned to 256 bytes.
- return 4 + (4 - s.st_size % 4) % 4;
if (bootfrom == IBR_HDR_SPI_ID || bootfrom == IBR_HDR_NAND_ID)
return 4 + (256 - (alloc_len + s.st_size + 4) % 256) % 256;
else
return 4 + (4 - s.st_size % 4) % 4;
}
/*
Viele Grüße, Stefan

Add constant for SDIO value of the bootfrom header field.
Signed-off-by: Marek Behún marek.behun@nic.cz --- tools/kwbimage.h | 1 + 1 file changed, 1 insertion(+)
diff --git a/tools/kwbimage.h b/tools/kwbimage.h index 0b6d05bef1..9856b44536 100644 --- a/tools/kwbimage.h +++ b/tools/kwbimage.h @@ -27,6 +27,7 @@ #define IBR_HDR_SATA_ID 0x78 #define IBR_HDR_PEX_ID 0x9C #define IBR_HDR_UART_ID 0x69 +#define IBR_HDR_SDIO_ID 0xAE #define IBR_DEF_ATTRIB 0x00
/* Structure of the main header, version 0 (Kirkwood, Dove) */

On 08.07.21 19:30, Marek Behún wrote:
Add constant for SDIO value of the bootfrom header field.
Signed-off-by: Marek Behún marek.behun@nic.cz
Reviewed-by: Stefan Roese sr@denx.de
Thanks, Stefan
tools/kwbimage.h | 1 + 1 file changed, 1 insertion(+)
diff --git a/tools/kwbimage.h b/tools/kwbimage.h index 0b6d05bef1..9856b44536 100644 --- a/tools/kwbimage.h +++ b/tools/kwbimage.h @@ -27,6 +27,7 @@ #define IBR_HDR_SATA_ID 0x78 #define IBR_HDR_PEX_ID 0x9C #define IBR_HDR_UART_ID 0x69 +#define IBR_HDR_SDIO_ID 0xAE #define IBR_DEF_ATTRIB 0x00
/* Structure of the main header, version 0 (Kirkwood, Dove) */
Viele Grüße, Stefan

From: Pali Rohár pali@kernel.org
SATA and SDIO images must be aligned to sector size (which in most cases is 512 bytes) and Source Address in main header is stored in number of sectors from the beginning of the drive. SATA image must be stored at sector 1 and SDIO image at sector 0. Source Address for PCIe image is not used and must be set to 0xFFFFFFFF.
Signed-off-by: Pali Rohár pali@kernel.org Reviewed-by: Marek Behún marek.behun@nic.cz --- tools/kwbimage.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+)
diff --git a/tools/kwbimage.c b/tools/kwbimage.c index f40ba0994d..44bf5ee026 100644 --- a/tools/kwbimage.c +++ b/tools/kwbimage.c @@ -1281,6 +1281,26 @@ static void *image_create_v1(size_t *imagesz, struct image_tool_params *params, main_hdr->destaddr = cpu_to_le32(params->addr); }
+ /* + * For SATA srcaddr is specified in number of sectors starting from + * sector 0. The main header is stored at sector number 1. + * This expects the sector size to be 512 bytes. + */ + if (main_hdr->blockid == IBR_HDR_SATA_ID) + main_hdr->srcaddr = cpu_to_le32((headersz + 511) / 512 + 1); + + /* + * For SDIO srcaddr is specified in number of sectors starting from + * sector 0. The main header is stored at sector number 0. + * This expects sector size to be 512 bytes. + */ + if (main_hdr->blockid == IBR_HDR_SDIO_ID) + main_hdr->srcaddr = cpu_to_le32((headersz + 511) / 512); + + /* For PCIe srcaddr is not used and must be set to 0xFFFFFFFF. */ + if (main_hdr->blockid == IBR_HDR_PEX_ID) + main_hdr->srcaddr = cpu_to_le32(0xFFFFFFFF); + #if defined(CONFIG_KWB_SECURE) if (image_get_csk_index() >= 0) { /* @@ -1734,6 +1754,8 @@ static int kwbimage_generate(struct image_tool_params *params, */ if (bootfrom == IBR_HDR_SPI_ID || bootfrom == IBR_HDR_NAND_ID) return 4 + (256 - (alloc_len + s.st_size + 4) % 256) % 256; + else if (bootfrom == IBR_HDR_SDIO_ID || bootfrom == IBR_HDR_PEX_ID) + return 4 + (512 - (alloc_len + s.st_size + 4) % 512) % 512; else return 4 + (4 - s.st_size % 4) % 4; }

On 08.07.21 19:30, Marek Behún wrote:
From: Pali Rohár pali@kernel.org
SATA and SDIO images must be aligned to sector size (which in most cases is 512 bytes) and Source Address in main header is stored in number of sectors from the beginning of the drive. SATA image must be stored at sector 1 and SDIO image at sector 0. Source Address for PCIe image is not used and must be set to 0xFFFFFFFF.
Signed-off-by: Pali Rohár pali@kernel.org Reviewed-by: Marek Behún marek.behun@nic.cz
Reviewed-by: Stefan Roese sr@denx.de
Thanks, Stefan
tools/kwbimage.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+)
diff --git a/tools/kwbimage.c b/tools/kwbimage.c index f40ba0994d..44bf5ee026 100644 --- a/tools/kwbimage.c +++ b/tools/kwbimage.c @@ -1281,6 +1281,26 @@ static void *image_create_v1(size_t *imagesz, struct image_tool_params *params, main_hdr->destaddr = cpu_to_le32(params->addr); }
- /*
* For SATA srcaddr is specified in number of sectors starting from
* sector 0. The main header is stored at sector number 1.
* This expects the sector size to be 512 bytes.
*/
- if (main_hdr->blockid == IBR_HDR_SATA_ID)
main_hdr->srcaddr = cpu_to_le32((headersz + 511) / 512 + 1);
- /*
* For SDIO srcaddr is specified in number of sectors starting from
* sector 0. The main header is stored at sector number 0.
* This expects sector size to be 512 bytes.
*/
- if (main_hdr->blockid == IBR_HDR_SDIO_ID)
main_hdr->srcaddr = cpu_to_le32((headersz + 511) / 512);
- /* For PCIe srcaddr is not used and must be set to 0xFFFFFFFF. */
- if (main_hdr->blockid == IBR_HDR_PEX_ID)
main_hdr->srcaddr = cpu_to_le32(0xFFFFFFFF);
- #if defined(CONFIG_KWB_SECURE) if (image_get_csk_index() >= 0) { /*
@@ -1734,6 +1754,8 @@ static int kwbimage_generate(struct image_tool_params *params, */ if (bootfrom == IBR_HDR_SPI_ID || bootfrom == IBR_HDR_NAND_ID) return 4 + (256 - (alloc_len + s.st_size + 4) % 256) % 256;
- else if (bootfrom == IBR_HDR_SDIO_ID || bootfrom == IBR_HDR_PEX_ID)
else return 4 + (4 - s.st_size % 4) % 4; }return 4 + (512 - (alloc_len + s.st_size + 4) % 512) % 512;
Viele Grüße, Stefan

From: Pali Rohár pali@kernel.org
In the case when the file name is specified relative to the current working directory, it does not contain '/' character and strrchr() returns NULL.
The following strcmp() function then crashes on NULL pointer dereference.
Signed-off-by: Pali Rohár pali@kernel.org Reviewed-by: Marek Behún marek.behun@nic.cz --- tools/kwbimage.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tools/kwbimage.c b/tools/kwbimage.c index 44bf5ee026..c08fb678d4 100644 --- a/tools/kwbimage.c +++ b/tools/kwbimage.c @@ -1277,7 +1277,7 @@ static void *image_create_v1(size_t *imagesz, struct image_tool_params *params, if (e) { char *s = strrchr(e->binary.file, '/');
- if (strcmp(s, "/binary.0") == 0) + if (s && strcmp(s, "/binary.0") == 0) main_hdr->destaddr = cpu_to_le32(params->addr); }

On 08.07.21 19:30, Marek Behún wrote:
From: Pali Rohár pali@kernel.org
In the case when the file name is specified relative to the current working directory, it does not contain '/' character and strrchr() returns NULL.
The following strcmp() function then crashes on NULL pointer dereference.
Signed-off-by: Pali Rohár pali@kernel.org Reviewed-by: Marek Behún marek.behun@nic.cz
Reviewed-by: Stefan Roese sr@denx.de
Thanks, Stefan
tools/kwbimage.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tools/kwbimage.c b/tools/kwbimage.c index 44bf5ee026..c08fb678d4 100644 --- a/tools/kwbimage.c +++ b/tools/kwbimage.c @@ -1277,7 +1277,7 @@ static void *image_create_v1(size_t *imagesz, struct image_tool_params *params, if (e) { char *s = strrchr(e->binary.file, '/');
if (strcmp(s, "/binary.0") == 0)
}if (s && strcmp(s, "/binary.0") == 0) main_hdr->destaddr = cpu_to_le32(params->addr);
Viele Grüße, Stefan

From: Pali Rohár pali@kernel.org
Extended header checksum for v0 image is present only in the case when extended header is present. Skip checksum validation if extended header is not present.
Signed-off-by: Pali Rohár pali@kernel.org Reviewed-by: Marek Behún marek.behun@nic.cz --- tools/kwbimage.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-)
diff --git a/tools/kwbimage.c b/tools/kwbimage.c index c08fb678d4..5192edb330 100644 --- a/tools/kwbimage.c +++ b/tools/kwbimage.c @@ -1653,15 +1653,19 @@ static int kwbimage_verify_header(unsigned char *ptr, int image_size,
/* Only version 0 extended header has checksum */ if (image_version((void *)ptr) == 0) { - struct ext_hdr_v0 *ext_hdr; + struct main_hdr_v0 *mhdr = (struct main_hdr_v0 *)ptr;
- ext_hdr = (struct ext_hdr_v0 *) + if (mhdr->ext & 0x1) { + struct ext_hdr_v0 *ext_hdr; + + ext_hdr = (struct ext_hdr_v0 *) (ptr + sizeof(struct main_hdr_v0)); - checksum = image_checksum8(ext_hdr, - sizeof(struct ext_hdr_v0) - - sizeof(uint8_t)); - if (checksum != ext_hdr->checksum) - return -FDT_ERR_BADSTRUCTURE; + checksum = image_checksum8(ext_hdr, + sizeof(struct ext_hdr_v0) + - sizeof(uint8_t)); + if (checksum != ext_hdr->checksum) + return -FDT_ERR_BADSTRUCTURE; + } }
return 0;

On 08.07.21 19:30, Marek Behún wrote:
From: Pali Rohár pali@kernel.org
Extended header checksum for v0 image is present only in the case when extended header is present. Skip checksum validation if extended header is not present.
Signed-off-by: Pali Rohár pali@kernel.org Reviewed-by: Marek Behún marek.behun@nic.cz
Reviewed-by: Stefan Roese sr@denx.de
Thanks, Stefan
tools/kwbimage.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-)
diff --git a/tools/kwbimage.c b/tools/kwbimage.c index c08fb678d4..5192edb330 100644 --- a/tools/kwbimage.c +++ b/tools/kwbimage.c @@ -1653,15 +1653,19 @@ static int kwbimage_verify_header(unsigned char *ptr, int image_size,
/* Only version 0 extended header has checksum */ if (image_version((void *)ptr) == 0) {
struct ext_hdr_v0 *ext_hdr;
struct main_hdr_v0 *mhdr = (struct main_hdr_v0 *)ptr;
ext_hdr = (struct ext_hdr_v0 *)
if (mhdr->ext & 0x1) {
struct ext_hdr_v0 *ext_hdr;
ext_hdr = (struct ext_hdr_v0 *) (ptr + sizeof(struct main_hdr_v0));
checksum = image_checksum8(ext_hdr,
sizeof(struct ext_hdr_v0)
- sizeof(uint8_t));
if (checksum != ext_hdr->checksum)
return -FDT_ERR_BADSTRUCTURE;
checksum = image_checksum8(ext_hdr,
sizeof(struct ext_hdr_v0)
- sizeof(uint8_t));
if (checksum != ext_hdr->checksum)
return -FDT_ERR_BADSTRUCTURE;
}
}
return 0;
Viele Grüße, Stefan

From: Pali Rohár pali@kernel.org
Add basic checks for extended headers of v1 images.
Signed-off-by: Pali Rohár pali@kernel.org Reviewed-by: Marek Behún marek.behun@nic.cz --- tools/kwbimage.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+)
diff --git a/tools/kwbimage.c b/tools/kwbimage.c index 5192edb330..5f7cb8376a 100644 --- a/tools/kwbimage.c +++ b/tools/kwbimage.c @@ -1668,6 +1668,34 @@ static int kwbimage_verify_header(unsigned char *ptr, int image_size, } }
+ if (image_version((void *)ptr) == 1) { + struct main_hdr_v1 *mhdr = (struct main_hdr_v1 *)ptr; + + if (mhdr->ext & 0x1) { + uint32_t ohdr_size; + struct opt_hdr_v1 *ohdr = (struct opt_hdr_v1 *) + (ptr + sizeof(*mhdr)); + + while (1) { + if ((uint8_t *)ohdr + sizeof(*ohdr) > + (uint8_t *)mhdr + header_size) + return -FDT_ERR_BADSTRUCTURE; + + ohdr_size = (ohdr->headersz_msb << 16) | + le16_to_cpu(ohdr->headersz_lsb); + + if ((uint8_t *)ohdr + 4 + ohdr_size + 4 > + (uint8_t *)mhdr + header_size) + return -FDT_ERR_BADSTRUCTURE; + + if (!(*((uint8_t *)ohdr + 4 + ohdr_size) & 0x1)) + break; + ohdr = (struct opt_hdr_v1 *)((uint8_t *)ohdr + + 4 + ohdr_size + 4); + } + } + } + return 0; }

On 08.07.21 19:30, Marek Behún wrote:
From: Pali Rohár pali@kernel.org
Add basic checks for extended headers of v1 images.
Signed-off-by: Pali Rohár pali@kernel.org Reviewed-by: Marek Behún marek.behun@nic.cz
Reviewed-by: Stefan Roese sr@denx.de
Thanks, Stefan
tools/kwbimage.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+)
diff --git a/tools/kwbimage.c b/tools/kwbimage.c index 5192edb330..5f7cb8376a 100644 --- a/tools/kwbimage.c +++ b/tools/kwbimage.c @@ -1668,6 +1668,34 @@ static int kwbimage_verify_header(unsigned char *ptr, int image_size, } }
- if (image_version((void *)ptr) == 1) {
struct main_hdr_v1 *mhdr = (struct main_hdr_v1 *)ptr;
if (mhdr->ext & 0x1) {
uint32_t ohdr_size;
struct opt_hdr_v1 *ohdr = (struct opt_hdr_v1 *)
(ptr + sizeof(*mhdr));
while (1) {
if ((uint8_t *)ohdr + sizeof(*ohdr) >
(uint8_t *)mhdr + header_size)
return -FDT_ERR_BADSTRUCTURE;
ohdr_size = (ohdr->headersz_msb << 16) |
le16_to_cpu(ohdr->headersz_lsb);
if ((uint8_t *)ohdr + 4 + ohdr_size + 4 >
(uint8_t *)mhdr + header_size)
return -FDT_ERR_BADSTRUCTURE;
if (!(*((uint8_t *)ohdr + 4 + ohdr_size) & 0x1))
break;
ohdr = (struct opt_hdr_v1 *)((uint8_t *)ohdr +
4 + ohdr_size + 4);
}
}
- }
- return 0; }
Viele Grüße, Stefan

From: Pali Rohár pali@kernel.org
The data part of v1 images contains 32-bit checksum after the data. Validate whether this checksum is correct.
Signed-off-by: Pali Rohár pali@kernel.org Reviewed-by: Marek Behún marek.behun@nic.cz --- tools/kwbimage.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+)
diff --git a/tools/kwbimage.c b/tools/kwbimage.c index 5f7cb8376a..de6eb3f075 100644 --- a/tools/kwbimage.c +++ b/tools/kwbimage.c @@ -1670,6 +1670,9 @@ static int kwbimage_verify_header(unsigned char *ptr, int image_size,
if (image_version((void *)ptr) == 1) { struct main_hdr_v1 *mhdr = (struct main_hdr_v1 *)ptr; + unsigned char *endptr = ptr + sizeof(*mhdr); + uint32_t offset; + uint32_t size;
if (mhdr->ext & 0x1) { uint32_t ohdr_size; @@ -1693,7 +1696,50 @@ static int kwbimage_verify_header(unsigned char *ptr, int image_size, ohdr = (struct opt_hdr_v1 *)((uint8_t *)ohdr + 4 + ohdr_size + 4); } + + endptr = ((uint8_t *)ohdr + 4 + ohdr_size + 4); + } + + offset = le32_to_cpu(mhdr->srcaddr); + + /* + * For SATA srcaddr is specified in number of sectors. + * The main header is must be stored at sector number 1. + * This expects that sector size is 512 bytes and recalculates + * data offset to bytes relative to the main header. + */ + if (mhdr->blockid == IBR_HDR_SATA_ID) { + if (offset < 1) + return -FDT_ERR_BADSTRUCTURE; + offset -= 1; + offset *= 512; } + + /* + * For SDIO srcaddr is specified in number of sectors. + * This expects that sector size is 512 bytes and recalculates + * data offset to bytes. + */ + if (mhdr->blockid == IBR_HDR_SDIO_ID) + offset *= 512; + + /* + * For PCIe srcaddr is always set to 0xFFFFFFFF. + * This expects that data starts after all headers. + */ + if (mhdr->blockid == IBR_HDR_PEX_ID && offset == 0xFFFFFFFF) + offset = endptr - ptr; + + if (offset > image_size || offset % 4 != 0) + return -FDT_ERR_BADSTRUCTURE; + + size = le32_to_cpu(mhdr->blocksize); + if (offset + size > image_size || size % 4 != 0) + return -FDT_ERR_BADSTRUCTURE; + + if (image_checksum32(ptr + offset, size - 4) != + *(uint32_t *)(ptr + offset + size - 4)) + return -FDT_ERR_BADSTRUCTURE; }
return 0;

On 08.07.21 19:30, Marek Behún wrote:
From: Pali Rohár pali@kernel.org
The data part of v1 images contains 32-bit checksum after the data. Validate whether this checksum is correct.
Signed-off-by: Pali Rohár pali@kernel.org Reviewed-by: Marek Behún marek.behun@nic.cz
Reviewed-by: Stefan Roese sr@denx.de
Thanks, Stefan
tools/kwbimage.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+)
diff --git a/tools/kwbimage.c b/tools/kwbimage.c index 5f7cb8376a..de6eb3f075 100644 --- a/tools/kwbimage.c +++ b/tools/kwbimage.c @@ -1670,6 +1670,9 @@ static int kwbimage_verify_header(unsigned char *ptr, int image_size,
if (image_version((void *)ptr) == 1) { struct main_hdr_v1 *mhdr = (struct main_hdr_v1 *)ptr;
unsigned char *endptr = ptr + sizeof(*mhdr);
uint32_t offset;
uint32_t size;
if (mhdr->ext & 0x1) { uint32_t ohdr_size;
@@ -1693,7 +1696,50 @@ static int kwbimage_verify_header(unsigned char *ptr, int image_size, ohdr = (struct opt_hdr_v1 *)((uint8_t *)ohdr + 4 + ohdr_size + 4); }
endptr = ((uint8_t *)ohdr + 4 + ohdr_size + 4);
}
offset = le32_to_cpu(mhdr->srcaddr);
/*
* For SATA srcaddr is specified in number of sectors.
* The main header is must be stored at sector number 1.
* This expects that sector size is 512 bytes and recalculates
* data offset to bytes relative to the main header.
*/
if (mhdr->blockid == IBR_HDR_SATA_ID) {
if (offset < 1)
return -FDT_ERR_BADSTRUCTURE;
offset -= 1;
offset *= 512;
}
/*
* For SDIO srcaddr is specified in number of sectors.
* This expects that sector size is 512 bytes and recalculates
* data offset to bytes.
*/
if (mhdr->blockid == IBR_HDR_SDIO_ID)
offset *= 512;
/*
* For PCIe srcaddr is always set to 0xFFFFFFFF.
* This expects that data starts after all headers.
*/
if (mhdr->blockid == IBR_HDR_PEX_ID && offset == 0xFFFFFFFF)
offset = endptr - ptr;
if (offset > image_size || offset % 4 != 0)
return -FDT_ERR_BADSTRUCTURE;
size = le32_to_cpu(mhdr->blocksize);
if (offset + size > image_size || size % 4 != 0)
return -FDT_ERR_BADSTRUCTURE;
if (image_checksum32(ptr + offset, size - 4) !=
*(uint32_t *)(ptr + offset + size - 4))
return -FDT_ERR_BADSTRUCTURE;
}
return 0;
Viele Grüße, Stefan

From: Pali Rohár pali@kernel.org
The binary header in kwbimage contains executable SPL code.
Print information about this binary header and not only information about it's data part.
Signed-off-by: Pali Rohár pali@kernel.org Reviewed-by: Marek Behún marek.behun@nic.cz --- tools/kwbimage.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+)
diff --git a/tools/kwbimage.c b/tools/kwbimage.c index de6eb3f075..d8a14cb093 100644 --- a/tools/kwbimage.c +++ b/tools/kwbimage.c @@ -1625,6 +1625,30 @@ static void kwbimage_print_header(const void *ptr) printf("Image Type: MVEBU Boot from %s Image\n", image_boot_mode_name(mhdr->blockid)); printf("Image version:%d\n", image_version((void *)ptr)); + if (image_version((void *)ptr) == 1) { + struct main_hdr_v1 *mhdr = (struct main_hdr_v1 *)ptr; + + if (mhdr->ext & 0x1) { + struct opt_hdr_v1 *ohdr = (struct opt_hdr_v1 *) + ((uint8_t *)ptr + + sizeof(*mhdr)); + + while (1) { + uint32_t ohdr_size; + + ohdr_size = (ohdr->headersz_msb << 16) | + ohdr->headersz_lsb; + if (ohdr->headertype == OPT_HDR_V1_BINARY_TYPE) { + printf("BIN Hdr Size: "); + genimg_print_size(ohdr_size); + } + if (!(*((uint8_t *)ohdr + 4 + ohdr_size) & 0x1)) + break; + ohdr = (struct opt_hdr_v1 *)((uint8_t *)ohdr + + 4 + ohdr_size + 4); + } + } + } printf("Data Size: "); genimg_print_size(mhdr->blocksize - sizeof(uint32_t)); printf("Load Address: %08x\n", mhdr->destaddr);

On 08.07.21 19:30, Marek Behún wrote:
From: Pali Rohár pali@kernel.org
The binary header in kwbimage contains executable SPL code.
Print information about this binary header and not only information about it's data part.
Signed-off-by: Pali Rohár pali@kernel.org Reviewed-by: Marek Behún marek.behun@nic.cz
Reviewed-by: Stefan Roese sr@denx.de
Thanks, Stefan
tools/kwbimage.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+)
diff --git a/tools/kwbimage.c b/tools/kwbimage.c index de6eb3f075..d8a14cb093 100644 --- a/tools/kwbimage.c +++ b/tools/kwbimage.c @@ -1625,6 +1625,30 @@ static void kwbimage_print_header(const void *ptr) printf("Image Type: MVEBU Boot from %s Image\n", image_boot_mode_name(mhdr->blockid)); printf("Image version:%d\n", image_version((void *)ptr));
- if (image_version((void *)ptr) == 1) {
struct main_hdr_v1 *mhdr = (struct main_hdr_v1 *)ptr;
if (mhdr->ext & 0x1) {
struct opt_hdr_v1 *ohdr = (struct opt_hdr_v1 *)
((uint8_t *)ptr +
sizeof(*mhdr));
while (1) {
uint32_t ohdr_size;
ohdr_size = (ohdr->headersz_msb << 16) |
ohdr->headersz_lsb;
if (ohdr->headertype == OPT_HDR_V1_BINARY_TYPE) {
printf("BIN Hdr Size: ");
genimg_print_size(ohdr_size);
}
if (!(*((uint8_t *)ohdr + 4 + ohdr_size) & 0x1))
break;
ohdr = (struct opt_hdr_v1 *)((uint8_t *)ohdr +
4 + ohdr_size + 4);
}
}
- } printf("Data Size: "); genimg_print_size(mhdr->blocksize - sizeof(uint32_t)); printf("Load Address: %08x\n", mhdr->destaddr);
Viele Grüße, Stefan

From: Pali Rohár pali@kernel.org
The 'buf' is a pointer and '_buf' is the array itself. Therefore we should pass sizeof(_buf) instead of sizeof(buf) to read().
Signed-off-by: Pali Rohár pali@kernel.org Reviewed-by: Marek Behún marek.behun@nic.cz --- tools/kwboot.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tools/kwboot.c b/tools/kwboot.c index 4be094c9c8..2edeb5a371 100644 --- a/tools/kwboot.c +++ b/tools/kwboot.c @@ -471,7 +471,7 @@ kwboot_term_pipe(int in, int out, char *quit, int *s) ssize_t nin, nout; char _buf[128], *buf = _buf;
- nin = read(in, buf, sizeof(buf)); + nin = read(in, buf, sizeof(_buf)); if (nin <= 0) return -1;

On 08.07.21 19:30, Marek Behún wrote:
From: Pali Rohár pali@kernel.org
The 'buf' is a pointer and '_buf' is the array itself. Therefore we should pass sizeof(_buf) instead of sizeof(buf) to read().
Signed-off-by: Pali Rohár pali@kernel.org Reviewed-by: Marek Behún marek.behun@nic.cz
Reviewed-by: Stefan Roese sr@denx.de
Thanks, Stefan
tools/kwboot.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tools/kwboot.c b/tools/kwboot.c index 4be094c9c8..2edeb5a371 100644 --- a/tools/kwboot.c +++ b/tools/kwboot.c @@ -471,7 +471,7 @@ kwboot_term_pipe(int in, int out, char *quit, int *s) ssize_t nin, nout; char _buf[128], *buf = _buf;
- nin = read(in, buf, sizeof(buf));
- nin = read(in, buf, sizeof(_buf)); if (nin <= 0) return -1;
Viele Grüße, Stefan

From: Pali Rohár pali@kernel.org
Call tcsetattr() only if the file descriptor is valid. It may be invalidated by previous lines (if it is not a tty descriptor).
Signed-off-by: Pali Rohár pali@kernel.org Reviewed-by: Marek Behún marek.behun@nic.cz --- tools/kwboot.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/tools/kwboot.c b/tools/kwboot.c index 2edeb5a371..7e8bf21d37 100644 --- a/tools/kwboot.c +++ b/tools/kwboot.c @@ -564,7 +564,8 @@ kwboot_terminal(int tty) } } while (quit[s] != 0);
- tcsetattr(in, TCSANOW, &otio); + if (in >= 0) + tcsetattr(in, TCSANOW, &otio); out: return rc; }

On 08.07.21 19:30, Marek Behún wrote:
From: Pali Rohár pali@kernel.org
Call tcsetattr() only if the file descriptor is valid. It may be invalidated by previous lines (if it is not a tty descriptor).
Signed-off-by: Pali Rohár pali@kernel.org Reviewed-by: Marek Behún marek.behun@nic.cz
Reviewed-by: Stefan Roese sr@denx.de
Thanks, Stefan
tools/kwboot.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/tools/kwboot.c b/tools/kwboot.c index 2edeb5a371..7e8bf21d37 100644 --- a/tools/kwboot.c +++ b/tools/kwboot.c @@ -564,7 +564,8 @@ kwboot_terminal(int tty) } } while (quit[s] != 0);
- tcsetattr(in, TCSANOW, &otio);
- if (in >= 0)
out: return rc; }tcsetattr(in, TCSANOW, &otio);
Viele Grüße, Stefan

From: Pali Rohár pali@kernel.org
Print trailing newline as the last printed byte can be something different.
Signed-off-by: Pali Rohár pali@kernel.org Reviewed-by: Marek Behún marek.behun@nic.cz --- tools/kwboot.c | 1 + 1 file changed, 1 insertion(+)
diff --git a/tools/kwboot.c b/tools/kwboot.c index 7e8bf21d37..6e66ad4ecf 100644 --- a/tools/kwboot.c +++ b/tools/kwboot.c @@ -566,6 +566,7 @@ kwboot_terminal(int tty)
if (in >= 0) tcsetattr(in, TCSANOW, &otio); + printf("\n"); out: return rc; }

On 08.07.21 19:30, Marek Behún wrote:
From: Pali Rohár pali@kernel.org
Print trailing newline as the last printed byte can be something different.
Signed-off-by: Pali Rohár pali@kernel.org Reviewed-by: Marek Behún marek.behun@nic.cz
Reviewed-by: Stefan Roese sr@denx.de
Thanks, Stefan
tools/kwboot.c | 1 + 1 file changed, 1 insertion(+)
diff --git a/tools/kwboot.c b/tools/kwboot.c index 7e8bf21d37..6e66ad4ecf 100644 --- a/tools/kwboot.c +++ b/tools/kwboot.c @@ -566,6 +566,7 @@ kwboot_terminal(int tty)
if (in >= 0) tcsetattr(in, TCSANOW, &otio);
- printf("\n"); out: return rc; }
Viele Grüße, Stefan

From: Pali Rohár pali@kernel.org
Add missing curly brackets for this else statement.
Signed-off-by: Pali Rohár pali@kernel.org Reviewed-by: Marek Behún marek.behun@nic.cz --- tools/kwboot.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/tools/kwboot.c b/tools/kwboot.c index 6e66ad4ecf..e4d4267e47 100644 --- a/tools/kwboot.c +++ b/tools/kwboot.c @@ -485,13 +485,14 @@ kwboot_term_pipe(int in, int out, char *quit, int *s) return 0; buf++; nin--; - } else + } else { while (*s > 0) { nout = write(out, quit, *s); if (nout <= 0) return -1; (*s) -= nout; } + } } }

On 08.07.21 19:30, Marek Behún wrote:
From: Pali Rohár pali@kernel.org
Add missing curly brackets for this else statement.
Signed-off-by: Pali Rohár pali@kernel.org Reviewed-by: Marek Behún marek.behun@nic.cz
Reviewed-by: Stefan Roese sr@denx.de
Thanks, Stefan
tools/kwboot.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/tools/kwboot.c b/tools/kwboot.c index 6e66ad4ecf..e4d4267e47 100644 --- a/tools/kwboot.c +++ b/tools/kwboot.c @@ -485,13 +485,14 @@ kwboot_term_pipe(int in, int out, char *quit, int *s) return 0; buf++; nin--;
} else
} else { while (*s > 0) { nout = write(out, quit, *s); if (nout <= 0) return -1; (*s) -= nout; }
} }}
Viele Grüße, Stefan

From: Pali Rohár pali@kernel.org
Too small invalid headers may cause kwboot to crash. Check for header size of v1 images.
Signed-off-by: Pali Rohár pali@kernel.org Reviewed-by: Marek Behún marek.behun@nic.cz --- tools/kwboot.c | 5 +++++ 1 file changed, 5 insertions(+)
diff --git a/tools/kwboot.c b/tools/kwboot.c index e4d4267e47..7f3489c55c 100644 --- a/tools/kwboot.c +++ b/tools/kwboot.c @@ -651,6 +651,11 @@ kwboot_img_patch_hdr(void *img, size_t size) else hdrsz = KWBHEADER_V1_SIZE(hdr);
+ if (size < hdrsz) { + errno = EINVAL; + goto out; + } + csum = kwboot_img_csum8(hdr, hdrsz) - hdr->checksum; if (csum != hdr->checksum) { errno = EINVAL;

On 08.07.21 19:30, Marek Behún wrote:
From: Pali Rohár pali@kernel.org
Too small invalid headers may cause kwboot to crash. Check for header size of v1 images.
Signed-off-by: Pali Rohár pali@kernel.org Reviewed-by: Marek Behún marek.behun@nic.cz
Reviewed-by: Stefan Roese sr@denx.de
Thanks, Stefan
tools/kwboot.c | 5 +++++ 1 file changed, 5 insertions(+)
diff --git a/tools/kwboot.c b/tools/kwboot.c index e4d4267e47..7f3489c55c 100644 --- a/tools/kwboot.c +++ b/tools/kwboot.c @@ -651,6 +651,11 @@ kwboot_img_patch_hdr(void *img, size_t size) else hdrsz = KWBHEADER_V1_SIZE(hdr);
- if (size < hdrsz) {
errno = EINVAL;
goto out;
- }
- csum = kwboot_img_csum8(hdr, hdrsz) - hdr->checksum; if (csum != hdr->checksum) { errno = EINVAL;
Viele Grüße, Stefan

Remove this space, since the constants are indented by tabs.
Signed-off-by: Marek Behún marek.behun@nic.cz --- tools/kwbimage.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tools/kwbimage.h b/tools/kwbimage.h index 9856b44536..cab3d95d13 100644 --- a/tools/kwbimage.h +++ b/tools/kwbimage.h @@ -28,7 +28,7 @@ #define IBR_HDR_PEX_ID 0x9C #define IBR_HDR_UART_ID 0x69 #define IBR_HDR_SDIO_ID 0xAE -#define IBR_DEF_ATTRIB 0x00 +#define IBR_DEF_ATTRIB 0x00
/* Structure of the main header, version 0 (Kirkwood, Dove) */ struct main_hdr_v0 {

On 08.07.21 19:30, Marek Behún wrote:
Remove this space, since the constants are indented by tabs.
Signed-off-by: Marek Behún marek.behun@nic.cz
Reviewed-by: Stefan Roese sr@denx.de
Thanks, Stefan
tools/kwbimage.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tools/kwbimage.h b/tools/kwbimage.h index 9856b44536..cab3d95d13 100644 --- a/tools/kwbimage.h +++ b/tools/kwbimage.h @@ -28,7 +28,7 @@ #define IBR_HDR_PEX_ID 0x9C #define IBR_HDR_UART_ID 0x69 #define IBR_HDR_SDIO_ID 0xAE -#define IBR_DEF_ATTRIB 0x00 +#define IBR_DEF_ATTRIB 0x00
/* Structure of the main header, version 0 (Kirkwood, Dove) */ struct main_hdr_v0 {
Viele Grüße, Stefan

From: Pali Rohár pali@kernel.org
The data part of v1 kwbimage currently contains U-Boot binary prepended by 64 bytes long Legacy U-Boot image header. This means that the load address is currently substracted by 64 bytes to ensure that U-Boot's entry point is at specified execution address.
As mkimage has already separate arguments for load (-a) and execution (-e) address, there is no need to derive fixed load address from execution address.
Therefore remove this load address hack from the kwbimage tool and support generating v1 kwbimage with arbitrary addresses for load and execution.
Finally, calculate correct load address by caller for mkimage tool in Makefile. File u-boot-spl.kwb is always a v1 kwbimage and it is the only v1 kwbimage which U-Boot's build system generates.
Remove also useless overwriting of destaddr for /binary.0 to the value which is already set on previous lines.
Signed-off-by: Pali Rohár pali@kernel.org Reviewed-by: Marek Behún marek.behun@nic.cz --- Makefile | 2 +- tools/kwbimage.c | 10 +--------- 2 files changed, 2 insertions(+), 10 deletions(-)
diff --git a/Makefile b/Makefile index 0d3192ceba..85bd8fc12d 100644 --- a/Makefile +++ b/Makefile @@ -1398,7 +1398,7 @@ MKIMAGEFLAGS_u-boot.kwb = -n $(KWD_CONFIG_FILE) \ -T kwbimage -a $(CONFIG_SYS_TEXT_BASE) -e $(CONFIG_SYS_TEXT_BASE)
MKIMAGEFLAGS_u-boot-spl.kwb = -n $(KWD_CONFIG_FILE) \ - -T kwbimage -a $(CONFIG_SYS_TEXT_BASE) -e $(CONFIG_SYS_TEXT_BASE) \ + -T kwbimage -a $(shell printf "0x%x" $$(($(CONFIG_SYS_TEXT_BASE)-64))) -e $(CONFIG_SYS_TEXT_BASE) \ $(if $(KEYDIR),-k $(KEYDIR))
MKIMAGEFLAGS_u-boot.pbl = -n $(srctree)/$(CONFIG_SYS_FSL_PBL_RCW:"%"=%) \ diff --git a/tools/kwbimage.c b/tools/kwbimage.c index d8a14cb093..acd57267f4 100644 --- a/tools/kwbimage.c +++ b/tools/kwbimage.c @@ -1252,8 +1252,7 @@ static void *image_create_v1(size_t *imagesz, struct image_tool_params *params, cpu_to_le32(payloadsz - headersz); main_hdr->headersz_lsb = cpu_to_le16(headersz & 0xFFFF); main_hdr->headersz_msb = (headersz & 0xFFFF0000) >> 16; - main_hdr->destaddr = cpu_to_le32(params->addr) - - sizeof(image_header_t); + main_hdr->destaddr = cpu_to_le32(params->addr); main_hdr->execaddr = cpu_to_le32(params->ep); main_hdr->srcaddr = cpu_to_le32(headersz); main_hdr->ext = hasext; @@ -1273,13 +1272,6 @@ static void *image_create_v1(size_t *imagesz, struct image_tool_params *params, e = image_find_option(IMAGE_CFG_DEBUG); if (e) main_hdr->flags = e->debug ? 0x1 : 0; - e = image_find_option(IMAGE_CFG_BINARY); - if (e) { - char *s = strrchr(e->binary.file, '/'); - - if (s && strcmp(s, "/binary.0") == 0) - main_hdr->destaddr = cpu_to_le32(params->addr); - }
/* * For SATA srcaddr is specified in number of sectors starting from

On 08.07.21 19:30, Marek Behún wrote:
From: Pali Rohár pali@kernel.org
The data part of v1 kwbimage currently contains U-Boot binary prepended by 64 bytes long Legacy U-Boot image header. This means that the load address is currently substracted by 64 bytes to ensure that U-Boot's entry point is at specified execution address.
As mkimage has already separate arguments for load (-a) and execution (-e) address, there is no need to derive fixed load address from execution address.
Therefore remove this load address hack from the kwbimage tool and support generating v1 kwbimage with arbitrary addresses for load and execution.
Finally, calculate correct load address by caller for mkimage tool in Makefile. File u-boot-spl.kwb is always a v1 kwbimage and it is the only v1 kwbimage which U-Boot's build system generates.
Remove also useless overwriting of destaddr for /binary.0 to the value which is already set on previous lines.
Signed-off-by: Pali Rohár pali@kernel.org Reviewed-by: Marek Behún marek.behun@nic.cz
Reviewed-by: Stefan Roese sr@denx.de
Thanks, Stefan
Makefile | 2 +- tools/kwbimage.c | 10 +--------- 2 files changed, 2 insertions(+), 10 deletions(-)
diff --git a/Makefile b/Makefile index 0d3192ceba..85bd8fc12d 100644 --- a/Makefile +++ b/Makefile @@ -1398,7 +1398,7 @@ MKIMAGEFLAGS_u-boot.kwb = -n $(KWD_CONFIG_FILE) \ -T kwbimage -a $(CONFIG_SYS_TEXT_BASE) -e $(CONFIG_SYS_TEXT_BASE)
MKIMAGEFLAGS_u-boot-spl.kwb = -n $(KWD_CONFIG_FILE) \
- -T kwbimage -a $(CONFIG_SYS_TEXT_BASE) -e $(CONFIG_SYS_TEXT_BASE) \
-T kwbimage -a $(shell printf "0x%x" $$(($(CONFIG_SYS_TEXT_BASE)-64))) -e $(CONFIG_SYS_TEXT_BASE) \ $(if $(KEYDIR),-k $(KEYDIR))
MKIMAGEFLAGS_u-boot.pbl = -n $(srctree)/$(CONFIG_SYS_FSL_PBL_RCW:"%"=%) \
diff --git a/tools/kwbimage.c b/tools/kwbimage.c index d8a14cb093..acd57267f4 100644 --- a/tools/kwbimage.c +++ b/tools/kwbimage.c @@ -1252,8 +1252,7 @@ static void *image_create_v1(size_t *imagesz, struct image_tool_params *params, cpu_to_le32(payloadsz - headersz); main_hdr->headersz_lsb = cpu_to_le16(headersz & 0xFFFF); main_hdr->headersz_msb = (headersz & 0xFFFF0000) >> 16;
- main_hdr->destaddr = cpu_to_le32(params->addr)
- sizeof(image_header_t);
- main_hdr->destaddr = cpu_to_le32(params->addr); main_hdr->execaddr = cpu_to_le32(params->ep); main_hdr->srcaddr = cpu_to_le32(headersz); main_hdr->ext = hasext;
@@ -1273,13 +1272,6 @@ static void *image_create_v1(size_t *imagesz, struct image_tool_params *params, e = image_find_option(IMAGE_CFG_DEBUG); if (e) main_hdr->flags = e->debug ? 0x1 : 0;
e = image_find_option(IMAGE_CFG_BINARY);
if (e) {
char *s = strrchr(e->binary.file, '/');
if (s && strcmp(s, "/binary.0") == 0)
main_hdr->destaddr = cpu_to_le32(params->addr);
}
/*
- For SATA srcaddr is specified in number of sectors starting from
Viele Grüße, Stefan

From: Pali Rohár pali@kernel.org
Register r0 should be set to return value 0x0 - NO_ERR.
Set r0 with return value after all registers are restored from the stack, so that the return value is always correct.
Signed-off-by: Pali Rohár pali@kernel.org Fixes: 944c7a317675 ("arm: mvebu: Add option to use UART xmodem protocol via kwboot") Reviewed-by: Marek Behún marek.behun@nic.cz --- arch/arm/mach-mvebu/lowlevel_spl.S | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/arch/arm/mach-mvebu/lowlevel_spl.S b/arch/arm/mach-mvebu/lowlevel_spl.S index 8718d7a43e..dde77b7652 100644 --- a/arch/arm/mach-mvebu/lowlevel_spl.S +++ b/arch/arm/mach-mvebu/lowlevel_spl.S @@ -13,8 +13,9 @@ ENDPROC(save_boot_params) ENTRY(return_to_bootrom) ldr r12, =CONFIG_SPL_BOOTROM_SAVE ldr sp, [r12] + ldmfd sp!, {r0 - r12, lr} /* @ restore registers from stack */ mov r0, #0x0 /* @ return value: 0x0 NO_ERR */ - ldmfd sp!, {r0 - r12, pc} /* @ restore regs and return */ + bx lr /* @ return to bootrom */ ENDPROC(return_to_bootrom)
/*

On 08.07.21 19:30, Marek Behún wrote:
From: Pali Rohár pali@kernel.org
Register r0 should be set to return value 0x0 - NO_ERR.
Set r0 with return value after all registers are restored from the stack, so that the return value is always correct.
Signed-off-by: Pali Rohár pali@kernel.org Fixes: 944c7a317675 ("arm: mvebu: Add option to use UART xmodem protocol via kwboot") Reviewed-by: Marek Behún marek.behun@nic.cz
Reviewed-by: Stefan Roese sr@denx.de
Thanks, Stefan
arch/arm/mach-mvebu/lowlevel_spl.S | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/arch/arm/mach-mvebu/lowlevel_spl.S b/arch/arm/mach-mvebu/lowlevel_spl.S index 8718d7a43e..dde77b7652 100644 --- a/arch/arm/mach-mvebu/lowlevel_spl.S +++ b/arch/arm/mach-mvebu/lowlevel_spl.S @@ -13,8 +13,9 @@ ENDPROC(save_boot_params) ENTRY(return_to_bootrom) ldr r12, =CONFIG_SPL_BOOTROM_SAVE ldr sp, [r12]
- ldmfd sp!, {r0 - r12, lr} /* @ restore registers from stack */ mov r0, #0x0 /* @ return value: 0x0 NO_ERR */
- ldmfd sp!, {r0 - r12, pc} /* @ restore regs and return */
bx lr /* @ return to bootrom */ ENDPROC(return_to_bootrom)
/*
Viele Grüße, Stefan

From: Pali Rohár pali@kernel.org
This function does not return, so add the appropriate compiler flag.
Signed-off-by: Pali Rohár pali@kernel.org Reviewed-by: Marek Behún marek.behun@nic.cz --- arch/arm/mach-mvebu/include/mach/cpu.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/arch/arm/mach-mvebu/include/mach/cpu.h b/arch/arm/mach-mvebu/include/mach/cpu.h index 52473ade7a..79858858c2 100644 --- a/arch/arm/mach-mvebu/include/mach/cpu.h +++ b/arch/arm/mach-mvebu/include/mach/cpu.h @@ -142,7 +142,7 @@ int mvebu_mbus_probe(struct mbus_win windows[], int count); int mvebu_soc_family(void); u32 mvebu_get_nand_clock(void);
-void return_to_bootrom(void); +void __noreturn return_to_bootrom(void);
#ifndef CONFIG_DM_MMC int mv_sdh_init(unsigned long regbase, u32 max_clk, u32 min_clk, u32 quirks);

On 08.07.21 19:30, Marek Behún wrote:
From: Pali Rohár pali@kernel.org
This function does not return, so add the appropriate compiler flag.
Signed-off-by: Pali Rohár pali@kernel.org Reviewed-by: Marek Behún marek.behun@nic.cz
Reviewed-by: Stefan Roese sr@denx.de
Thanks, Stefan
arch/arm/mach-mvebu/include/mach/cpu.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/arch/arm/mach-mvebu/include/mach/cpu.h b/arch/arm/mach-mvebu/include/mach/cpu.h index 52473ade7a..79858858c2 100644 --- a/arch/arm/mach-mvebu/include/mach/cpu.h +++ b/arch/arm/mach-mvebu/include/mach/cpu.h @@ -142,7 +142,7 @@ int mvebu_mbus_probe(struct mbus_win windows[], int count); int mvebu_soc_family(void); u32 mvebu_get_nand_clock(void);
-void return_to_bootrom(void); +void __noreturn return_to_bootrom(void);
#ifndef CONFIG_DM_MMC int mv_sdh_init(unsigned long regbase, u32 max_clk, u32 min_clk, u32 quirks);
Viele Grüße, Stefan

From: Pali Rohár pali@kernel.org
U-Boot's SPL framework already has an API for loading U-Boot via BootROM.
Implement the function board_return_to_bootrom() for mvebu SPL code.
Signed-off-by: Pali Rohár pali@kernel.org Reviewed-by: Marek Behún marek.behun@nic.cz --- arch/arm/mach-mvebu/Kconfig | 4 ++++ arch/arm/mach-mvebu/spl.c | 12 ++++++++++++ 2 files changed, 16 insertions(+)
diff --git a/arch/arm/mach-mvebu/Kconfig b/arch/arm/mach-mvebu/Kconfig index cda65f7478..2133d9a172 100644 --- a/arch/arm/mach-mvebu/Kconfig +++ b/arch/arm/mach-mvebu/Kconfig @@ -257,6 +257,7 @@ config MVEBU_SPL_BOOT_DEVICE_SPI select SPL_SPI_FLASH_SUPPORT select SPL_SPI_LOAD select SPL_SPI_SUPPORT + select SPL_BOOTROM_SUPPORT
config MVEBU_SPL_BOOT_DEVICE_MMC bool "SDIO/MMC card" @@ -267,14 +268,17 @@ config MVEBU_SPL_BOOT_DEVICE_MMC select SPL_GPIO_SUPPORT select SPL_LIBDISK_SUPPORT select SPL_MMC_SUPPORT + select SPL_BOOTROM_SUPPORT
config MVEBU_SPL_BOOT_DEVICE_SATA bool "SATA" select SPL_SATA_SUPPORT select SPL_LIBDISK_SUPPORT + select SPL_BOOTROM_SUPPORT
config MVEBU_SPL_BOOT_DEVICE_UART bool "UART" + select SPL_BOOTROM_SUPPORT
endchoice
diff --git a/arch/arm/mach-mvebu/spl.c b/arch/arm/mach-mvebu/spl.c index 16ebb7a59e..836eb18889 100644 --- a/arch/arm/mach-mvebu/spl.c +++ b/arch/arm/mach-mvebu/spl.c @@ -79,6 +79,18 @@ u32 spl_boot_device(void) return get_boot_device(); }
+int board_return_to_bootrom(struct spl_image_info *spl_image, + struct spl_boot_device *bootdev) +{ + u32 *regs = *(u32 **)CONFIG_SPL_BOOTROM_SAVE; + + printf("Returning to BootROM (return address 0x%08x)...\n", regs[13]); + return_to_bootrom(); + + /* NOTREACHED - return_to_bootrom() does not return */ + hang(); +} + void board_init_f(ulong dummy) { int ret;

On 08.07.21 19:30, Marek Behún wrote:
From: Pali Rohár pali@kernel.org
U-Boot's SPL framework already has an API for loading U-Boot via BootROM.
Implement the function board_return_to_bootrom() for mvebu SPL code.
Signed-off-by: Pali Rohár pali@kernel.org Reviewed-by: Marek Behún marek.behun@nic.cz
Reviewed-by: Stefan Roese sr@denx.de
Thanks, Stefan
arch/arm/mach-mvebu/Kconfig | 4 ++++ arch/arm/mach-mvebu/spl.c | 12 ++++++++++++ 2 files changed, 16 insertions(+)
diff --git a/arch/arm/mach-mvebu/Kconfig b/arch/arm/mach-mvebu/Kconfig index cda65f7478..2133d9a172 100644 --- a/arch/arm/mach-mvebu/Kconfig +++ b/arch/arm/mach-mvebu/Kconfig @@ -257,6 +257,7 @@ config MVEBU_SPL_BOOT_DEVICE_SPI select SPL_SPI_FLASH_SUPPORT select SPL_SPI_LOAD select SPL_SPI_SUPPORT
select SPL_BOOTROM_SUPPORT
config MVEBU_SPL_BOOT_DEVICE_MMC bool "SDIO/MMC card"
@@ -267,14 +268,17 @@ config MVEBU_SPL_BOOT_DEVICE_MMC select SPL_GPIO_SUPPORT select SPL_LIBDISK_SUPPORT select SPL_MMC_SUPPORT
select SPL_BOOTROM_SUPPORT
config MVEBU_SPL_BOOT_DEVICE_SATA bool "SATA" select SPL_SATA_SUPPORT select SPL_LIBDISK_SUPPORT
select SPL_BOOTROM_SUPPORT
config MVEBU_SPL_BOOT_DEVICE_UART bool "UART"
select SPL_BOOTROM_SUPPORT
endchoice
diff --git a/arch/arm/mach-mvebu/spl.c b/arch/arm/mach-mvebu/spl.c index 16ebb7a59e..836eb18889 100644 --- a/arch/arm/mach-mvebu/spl.c +++ b/arch/arm/mach-mvebu/spl.c @@ -79,6 +79,18 @@ u32 spl_boot_device(void) return get_boot_device(); }
+int board_return_to_bootrom(struct spl_image_info *spl_image,
struct spl_boot_device *bootdev)
+{
- u32 *regs = *(u32 **)CONFIG_SPL_BOOTROM_SAVE;
- printf("Returning to BootROM (return address 0x%08x)...\n", regs[13]);
- return_to_bootrom();
- /* NOTREACHED - return_to_bootrom() does not return */
- hang();
+}
- void board_init_f(ulong dummy) { int ret;
Viele Grüße, Stefan

From: Pali Rohár pali@kernel.org
Current code uses hack in board_init_f() which calls return_to_bootrom() to skip U-Boot SPL code and return back to BootROM to load U-Boot via UART or from NAND.
This change migrates that hack from the board_init_f() function and changes it to return BOOT_DEVICE_BOOTROM instead of returning to BootROM directly, so that U-Boot's SPL framework is used for returning to BootROM.
Signed-off-by: Pali Rohár pali@kernel.org Reviewed-by: Marek Behún marek.behun@nic.cz --- arch/arm/mach-mvebu/spl.c | 48 ++++++++++++++++++++------------------- 1 file changed, 25 insertions(+), 23 deletions(-)
diff --git a/arch/arm/mach-mvebu/spl.c b/arch/arm/mach-mvebu/spl.c index 836eb18889..3551c9de42 100644 --- a/arch/arm/mach-mvebu/spl.c +++ b/arch/arm/mach-mvebu/spl.c @@ -76,7 +76,31 @@ static u32 get_boot_device(void)
u32 spl_boot_device(void) { - return get_boot_device(); + u32 boot_device = get_boot_device(); + + /* + * Return to the BootROM to continue the Marvell xmodem + * UART boot protocol. As initiated by the kwboot tool. + * + * This can only be done by the BootROM and not by the + * U-Boot SPL infrastructure, since the beginning of the + * image is already read and interpreted by the BootROM. + * SPL has no chance to receive this information. So we + * need to return to the BootROM to enable this xmodem + * UART download. + * + * If booting from NAND lets let the BootROM load the + * rest of the bootloader. + */ + switch (boot_device) { + case BOOT_DEVICE_UART: +#if defined(CONFIG_ARMADA_38X) + case BOOT_DEVICE_NAND: +#endif + return BOOT_DEVICE_BOOTROM; + default: + return boot_device; + } }
int board_return_to_bootrom(struct spl_image_info *spl_image, @@ -147,26 +171,4 @@ void board_init_f(ulong dummy)
/* Update read timing control for PCIe */ mv_rtc_config(); - - /* - * Return to the BootROM to continue the Marvell xmodem - * UART boot protocol. As initiated by the kwboot tool. - * - * This can only be done by the BootROM and not by the - * U-Boot SPL infrastructure, since the beginning of the - * image is already read and interpreted by the BootROM. - * SPL has no chance to receive this information. So we - * need to return to the BootROM to enable this xmodem - * UART download. - * - * If booting from NAND lets let the BootROM load the - * rest of the bootloader. - */ - switch (get_boot_device()) { - case BOOT_DEVICE_UART: -#if defined(CONFIG_ARMADA_38X) - case BOOT_DEVICE_NAND: -#endif - return_to_bootrom(); - } }

On 08.07.21 19:30, Marek Behún wrote:
From: Pali Rohár pali@kernel.org
Current code uses hack in board_init_f() which calls return_to_bootrom() to skip U-Boot SPL code and return back to BootROM to load U-Boot via UART or from NAND.
This change migrates that hack from the board_init_f() function and changes it to return BOOT_DEVICE_BOOTROM instead of returning to BootROM directly, so that U-Boot's SPL framework is used for returning to BootROM.
Signed-off-by: Pali Rohár pali@kernel.org Reviewed-by: Marek Behún marek.behun@nic.cz
arch/arm/mach-mvebu/spl.c | 48 ++++++++++++++++++++------------------- 1 file changed, 25 insertions(+), 23 deletions(-)
diff --git a/arch/arm/mach-mvebu/spl.c b/arch/arm/mach-mvebu/spl.c index 836eb18889..3551c9de42 100644 --- a/arch/arm/mach-mvebu/spl.c +++ b/arch/arm/mach-mvebu/spl.c @@ -76,7 +76,31 @@ static u32 get_boot_device(void)
u32 spl_boot_device(void) {
- return get_boot_device();
- u32 boot_device = get_boot_device();
- /*
* Return to the BootROM to continue the Marvell xmodem
* UART boot protocol. As initiated by the kwboot tool.
*
* This can only be done by the BootROM and not by the
* U-Boot SPL infrastructure, since the beginning of the
* image is already read and interpreted by the BootROM.
* SPL has no chance to receive this information. So we
* need to return to the BootROM to enable this xmodem
* UART download.
The comment needs some updates as the SPL infrastructure is now used. Could you please update it accordingly in v2?
Other than this:
Reviewed-by: Stefan Roese sr@denx.de
Thanks, Stefan
*
* If booting from NAND lets let the BootROM load the
* rest of the bootloader.
*/
- switch (boot_device) {
case BOOT_DEVICE_UART:
+#if defined(CONFIG_ARMADA_38X)
case BOOT_DEVICE_NAND:
+#endif
return BOOT_DEVICE_BOOTROM;
default:
return boot_device;
} }
int board_return_to_bootrom(struct spl_image_info *spl_image,
@@ -147,26 +171,4 @@ void board_init_f(ulong dummy)
/* Update read timing control for PCIe */ mv_rtc_config();
- /*
* Return to the BootROM to continue the Marvell xmodem
* UART boot protocol. As initiated by the kwboot tool.
*
* This can only be done by the BootROM and not by the
* U-Boot SPL infrastructure, since the beginning of the
* image is already read and interpreted by the BootROM.
* SPL has no chance to receive this information. So we
* need to return to the BootROM to enable this xmodem
* UART download.
*
* If booting from NAND lets let the BootROM load the
* rest of the bootloader.
*/
- switch (get_boot_device()) {
case BOOT_DEVICE_UART:
-#if defined(CONFIG_ARMADA_38X)
case BOOT_DEVICE_NAND:
-#endif
return_to_bootrom();
- } }
Viele Grüße, Stefan

From: Pali Rohár pali@kernel.org
Now that proper load and execution addresses are set in v1 kwbimage, we can use BootROM to continue loading main U-Boot binary instead of U-Boot's SPL code.
This also reduces the size of U-Boot's SPL image.
The v1 kwbimage contains two separate executable parts: DDR training code (contains SPL) and bootloader (contains main U-Boot). BootROM first loads the first part, executes it and expects that the code returns back. Afterwards it loads the second part and executes it.
The current SPL code (used for the first part) for non-UART/NAND boots never returns back to BootROM and loads main U-Boot from external storage itself, and it lets BootROM think that it is still executing the first part - DDR training code.
With this change the SPL always returns execution back to BootROM and lets BootROM to load and execute U-Boot, like it was already done when booting from UART and NAND.
Note that the config options CONFIG_SPL_SPI_FLASH_SUPPORT, CONFIG_SPL_SPI_LOAD and CONFIG_SPL_SPI_SUPPORT needs to be enabled as config option CONFIG_SYS_U_BOOT_OFFS (used by kwbimage) depends on it.
Signed-off-by: Pali Rohár pali@kernel.org Reviewed-by: Marek Behún marek.behun@nic.cz --- arch/arm/mach-mvebu/Kconfig | 9 ---- arch/arm/mach-mvebu/spl.c | 84 +------------------------------------ 2 files changed, 1 insertion(+), 92 deletions(-)
diff --git a/arch/arm/mach-mvebu/Kconfig b/arch/arm/mach-mvebu/Kconfig index 2133d9a172..46ac43c7a0 100644 --- a/arch/arm/mach-mvebu/Kconfig +++ b/arch/arm/mach-mvebu/Kconfig @@ -253,7 +253,6 @@ choice config MVEBU_SPL_BOOT_DEVICE_SPI bool "SPI NOR flash" imply ENV_IS_IN_SPI_FLASH - select SPL_DM_SPI select SPL_SPI_FLASH_SUPPORT select SPL_SPI_LOAD select SPL_SPI_SUPPORT @@ -262,18 +261,10 @@ config MVEBU_SPL_BOOT_DEVICE_SPI config MVEBU_SPL_BOOT_DEVICE_MMC bool "SDIO/MMC card" imply ENV_IS_IN_MMC - # GPIO needed for eMMC/SD card presence detection - select SPL_DM_GPIO - select SPL_DM_MMC - select SPL_GPIO_SUPPORT - select SPL_LIBDISK_SUPPORT - select SPL_MMC_SUPPORT select SPL_BOOTROM_SUPPORT
config MVEBU_SPL_BOOT_DEVICE_SATA bool "SATA" - select SPL_SATA_SUPPORT - select SPL_LIBDISK_SUPPORT select SPL_BOOTROM_SUPPORT
config MVEBU_SPL_BOOT_DEVICE_UART diff --git a/arch/arm/mach-mvebu/spl.c b/arch/arm/mach-mvebu/spl.c index 3551c9de42..b13621b46a 100644 --- a/arch/arm/mach-mvebu/spl.c +++ b/arch/arm/mach-mvebu/spl.c @@ -16,91 +16,9 @@ #include <asm/arch/cpu.h> #include <asm/arch/soc.h>
-static u32 get_boot_device(void) -{ - u32 val; - u32 boot_device; - - /* - * First check, if UART boot-mode is active. This can only - * be done, via the bootrom error register. Here the - * MSB marks if the UART mode is active. - */ - val = readl(CONFIG_BOOTROM_ERR_REG); - boot_device = (val & BOOTROM_ERR_MODE_MASK) >> BOOTROM_ERR_MODE_OFFS; - debug("BOOTROM_REG=0x%08x boot_device=0x%x\n", val, boot_device); - if (boot_device == BOOTROM_ERR_MODE_UART) - return BOOT_DEVICE_UART; - -#ifdef CONFIG_ARMADA_38X - /* - * If the bootrom error code contains any other than zeros it's an - * error condition and the bootROM has fallen back to UART boot - */ - boot_device = (val & BOOTROM_ERR_CODE_MASK) >> BOOTROM_ERR_CODE_OFFS; - if (boot_device) - return BOOT_DEVICE_UART; -#endif - - /* - * Now check the SAR register for the strapped boot-device - */ - val = readl(CONFIG_SAR_REG); /* SAR - Sample At Reset */ - boot_device = (val & BOOT_DEV_SEL_MASK) >> BOOT_DEV_SEL_OFFS; - debug("SAR_REG=0x%08x boot_device=0x%x\n", val, boot_device); - switch (boot_device) { -#if defined(CONFIG_ARMADA_38X) - case BOOT_FROM_NAND: - return BOOT_DEVICE_NAND; -#endif -#ifdef CONFIG_SPL_MMC_SUPPORT - case BOOT_FROM_MMC: - case BOOT_FROM_MMC_ALT: - return BOOT_DEVICE_MMC1; -#endif - case BOOT_FROM_UART: -#ifdef BOOT_FROM_UART_ALT - case BOOT_FROM_UART_ALT: -#endif - return BOOT_DEVICE_UART; -#ifdef BOOT_FROM_SATA - case BOOT_FROM_SATA: - case BOOT_FROM_SATA_ALT: - return BOOT_DEVICE_SATA; -#endif - case BOOT_FROM_SPI: - default: - return BOOT_DEVICE_SPI; - }; -} - u32 spl_boot_device(void) { - u32 boot_device = get_boot_device(); - - /* - * Return to the BootROM to continue the Marvell xmodem - * UART boot protocol. As initiated by the kwboot tool. - * - * This can only be done by the BootROM and not by the - * U-Boot SPL infrastructure, since the beginning of the - * image is already read and interpreted by the BootROM. - * SPL has no chance to receive this information. So we - * need to return to the BootROM to enable this xmodem - * UART download. - * - * If booting from NAND lets let the BootROM load the - * rest of the bootloader. - */ - switch (boot_device) { - case BOOT_DEVICE_UART: -#if defined(CONFIG_ARMADA_38X) - case BOOT_DEVICE_NAND: -#endif - return BOOT_DEVICE_BOOTROM; - default: - return boot_device; - } + return BOOT_DEVICE_BOOTROM; }
int board_return_to_bootrom(struct spl_image_info *spl_image,

Hi Marek, Pali,
On Thu, Jul 08 2021, Marek Behún wrote:
From: Pali Rohár pali@kernel.org
Now that proper load and execution addresses are set in v1 kwbimage, we can use BootROM to continue loading main U-Boot binary instead of U-Boot's SPL code.
This also reduces the size of U-Boot's SPL image.
The v1 kwbimage contains two separate executable parts: DDR training code (contains SPL) and bootloader (contains main U-Boot). BootROM first loads the first part, executes it and expects that the code returns back. Afterwards it loads the second part and executes it.
The current SPL code (used for the first part) for non-UART/NAND boots never returns back to BootROM and loads main U-Boot from external storage itself, and it lets BootROM think that it is still executing the first part - DDR training code.
With this change the SPL always returns execution back to BootROM and lets BootROM to load and execute U-Boot, like it was already done when booting from UART and NAND.
Note that the config options CONFIG_SPL_SPI_FLASH_SUPPORT, CONFIG_SPL_SPI_LOAD and CONFIG_SPL_SPI_SUPPORT needs to be enabled as config option CONFIG_SYS_U_BOOT_OFFS (used by kwbimage) depends on it.
I think it's worth noting here that a subsequent commit will remove both.
baruch

From: Pali Rohár pali@kernel.org
Now that A38x SPL always calls return_to_bootrom() there is no need to provide custom spl_board_init() function which calls return_to_bootrom().
Remove it.
Signed-off-by: Pali Rohár pali@kernel.org Reviewed-by: Marek Behún marek.behun@nic.cz --- board/gdsys/a38x/Makefile | 2 +- board/gdsys/a38x/spl.c | 20 -------------------- 2 files changed, 1 insertion(+), 21 deletions(-) delete mode 100644 board/gdsys/a38x/spl.c
diff --git a/board/gdsys/a38x/Makefile b/board/gdsys/a38x/Makefile index 32fffab467..4b13859fed 100644 --- a/board/gdsys/a38x/Makefile +++ b/board/gdsys/a38x/Makefile @@ -4,7 +4,7 @@ # Copyright (C) 2015 Reinhard Pfau reinhard.pfau@gdsys.cc # Copyright (C) 2016 Mario Six mario.six@gdsys.cc
-obj-$(CONFIG_TARGET_CONTROLCENTERDC) += controlcenterdc.o hre.o spl.o keyprogram.o dt_helpers.o +obj-$(CONFIG_TARGET_CONTROLCENTERDC) += controlcenterdc.o hre.o keyprogram.o dt_helpers.o
ifeq ($(CONFIG_SPL_BUILD),) obj-$(CONFIG_TARGET_CONTROLCENTERDC) += hydra.o ihs_phys.o diff --git a/board/gdsys/a38x/spl.c b/board/gdsys/a38x/spl.c deleted file mode 100644 index 84864d1974..0000000000 --- a/board/gdsys/a38x/spl.c +++ /dev/null @@ -1,20 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0+ -/* - * (C) Copyright 2016 - * Mario Six, Guntermann & Drunck GmbH, mario.six@gdsys.cc - */ - -#include <common.h> -#include <config.h> -#include <asm/arch/cpu.h> - -void spl_board_init(void) -{ -#if CONFIG_SPL_BOOT_DEVICE == SPL_BOOT_SPI_NOR_FLASH - u32 *bootrom_save = (u32 *)CONFIG_SPL_BOOTROM_SAVE; - u32 *regs = (u32 *)(*bootrom_save); - - printf("Returning to BootROM (return address %08x)...\n", regs[13]); - return_to_bootrom(); -#endif -}

From: Pali Rohár pali@kernel.org
Now that BootROM always loads main U-Boot binary, the legacy 64-byte header is not used anymore. BootROM uses only kwbimage v1 headers where all necessary information about how to load and execute SPL / U-Boot is present.
Remove this 64-byte header by putting u-boot.bin binary (instead of u-boot.img) into kwbimage v1 and let BootROM to load U-Boot directly at its execution address.
Signed-off-by: Pali Rohár pali@kernel.org Reviewed-by: Marek Behún marek.behun@nic.cz --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/Makefile b/Makefile index 85bd8fc12d..fed46062b9 100644 --- a/Makefile +++ b/Makefile @@ -1398,7 +1398,7 @@ MKIMAGEFLAGS_u-boot.kwb = -n $(KWD_CONFIG_FILE) \ -T kwbimage -a $(CONFIG_SYS_TEXT_BASE) -e $(CONFIG_SYS_TEXT_BASE)
MKIMAGEFLAGS_u-boot-spl.kwb = -n $(KWD_CONFIG_FILE) \ - -T kwbimage -a $(shell printf "0x%x" $$(($(CONFIG_SYS_TEXT_BASE)-64))) -e $(CONFIG_SYS_TEXT_BASE) \ + -T kwbimage -a $(CONFIG_SYS_TEXT_BASE) -e $(CONFIG_SYS_TEXT_BASE) \ $(if $(KEYDIR),-k $(KEYDIR))
MKIMAGEFLAGS_u-boot.pbl = -n $(srctree)/$(CONFIG_SYS_FSL_PBL_RCW:"%"=%) \ @@ -1441,7 +1441,7 @@ u-boot.itb: u-boot-nodtb.bin \ $(BOARD_SIZE_CHECK) endif
-u-boot-spl.kwb: u-boot.img spl/u-boot-spl.bin FORCE +u-boot-spl.kwb: u-boot.bin spl/u-boot-spl.bin FORCE $(call if_changed,mkimage)
u-boot.sha1: u-boot.bin

From: Pali Rohár pali@kernel.org
This padding depends on board config file and therere it makes the mkimage binary tool board specific, which is not correct. One cannot use mkimage tool built as a result for board A to generate images for board B, even if both A and B are on the same platform.
This CONFIG_SYS_U_BOOT_OFFS padding was needed when v1 kwbimage contained SPL code which loaded main U-Boot binary itself, insted of letting BootROM do it.
Now that SPL code does not load main U-Boot itself and leaves this job to BootROM, there is no need for this padding anymore. BootROM correctly locates the second part (main U-Boot binary) in v1 kwbimage, loads it at correct address as specified in v1 kwbimage header and also jumps to correct execution address.
Therefore this CONFIG_SYS_U_BOOT_OFFS padding is not needed anymore.
By removing it we also reduce the size of SPL code and therefore also decrease the final size of v1 kwbimage. This means there is more space for main U-Boot binary.
Signed-off-by: Pali Rohár pali@kernel.org Reviewed-by: Marek Behún marek.behun@nic.cz --- tools/kwbimage.c | 13 ------------- 1 file changed, 13 deletions(-)
diff --git a/tools/kwbimage.c b/tools/kwbimage.c index acd57267f4..656f3f9ae9 100644 --- a/tools/kwbimage.c +++ b/tools/kwbimage.c @@ -998,19 +998,6 @@ static size_t image_headersz_v1(int *hasext) } #endif
-#if defined(CONFIG_SYS_U_BOOT_OFFS) - if (headersz > CONFIG_SYS_U_BOOT_OFFS) { - fprintf(stderr, - "Error: Image header (incl. SPL image) too big!\n"); - fprintf(stderr, "header=0x%x CONFIG_SYS_U_BOOT_OFFS=0x%x!\n", - (int)headersz, CONFIG_SYS_U_BOOT_OFFS); - fprintf(stderr, "Increase CONFIG_SYS_U_BOOT_OFFS!\n"); - return 0; - } - - headersz = CONFIG_SYS_U_BOOT_OFFS; -#endif - /* * The payload should be aligned on some reasonable * boundary

I'll take a proper look at the rest of the series this weekend. Just noticed a couple of typos in the commit message of this patch.
On Fri, Jul 9, 2021 at 5:30 AM Marek Behún marek.behun@nic.cz wrote:
From: Pali Rohár pali@kernel.org
This padding depends on board config file and therere it makes the
s/therere/therefore/
mkimage binary tool board specific, which is not correct. One cannot use mkimage tool built as a result for board A to generate images for board B, even if both A and B are on the same platform.
This CONFIG_SYS_U_BOOT_OFFS padding was needed when v1 kwbimage contained SPL code which loaded main U-Boot binary itself, insted of letting
s/insted/instead/
BootROM do it.
Now that SPL code does not load main U-Boot itself and leaves this job to BootROM, there is no need for this padding anymore. BootROM correctly locates the second part (main U-Boot binary) in v1 kwbimage, loads it at correct address as specified in v1 kwbimage header and also jumps to correct execution address.
Therefore this CONFIG_SYS_U_BOOT_OFFS padding is not needed anymore.
By removing it we also reduce the size of SPL code and therefore also decrease the final size of v1 kwbimage. This means there is more space for main U-Boot binary.
Signed-off-by: Pali Rohár pali@kernel.org Reviewed-by: Marek Behún marek.behun@nic.cz
tools/kwbimage.c | 13 ------------- 1 file changed, 13 deletions(-)
diff --git a/tools/kwbimage.c b/tools/kwbimage.c index acd57267f4..656f3f9ae9 100644 --- a/tools/kwbimage.c +++ b/tools/kwbimage.c @@ -998,19 +998,6 @@ static size_t image_headersz_v1(int *hasext) } #endif
-#if defined(CONFIG_SYS_U_BOOT_OFFS)
if (headersz > CONFIG_SYS_U_BOOT_OFFS) {
fprintf(stderr,
"Error: Image header (incl. SPL image) too big!\n");
fprintf(stderr, "header=0x%x CONFIG_SYS_U_BOOT_OFFS=0x%x!\n",
(int)headersz, CONFIG_SYS_U_BOOT_OFFS);
fprintf(stderr, "Increase CONFIG_SYS_U_BOOT_OFFS!\n");
return 0;
}
headersz = CONFIG_SYS_U_BOOT_OFFS;
-#endif
/* * The payload should be aligned on some reasonable * boundary
-- 2.31.1

From: Pali Rohár pali@kernel.org
Macro CONFIG_SYS_U_BOOT_OFFS is set but not used anymore. Remove it.
Remove also mvebu dependency on options CONFIG_SPL_SPI_FLASH_SUPPORT, CONFIG_SPL_SPI_LOAD and CONFIG_SPL_SPI_SUPPORT as they were needed only for CONFIG_SYS_U_BOOT_OFFS.
Signed-off-by: Pali Rohár pali@kernel.org Reviewed-by: Marek Behún marek.behun@nic.cz --- arch/arm/mach-mvebu/Kconfig | 3 --- include/configs/clearfog.h | 6 +----- include/configs/controlcenterdc.h | 8 +------- include/configs/db-88f6720.h | 3 --- include/configs/db-88f6820-amc.h | 5 ----- include/configs/db-88f6820-gp.h | 6 ------ include/configs/db-mv784mp-gp.h | 3 --- include/configs/ds414.h | 5 ----- include/configs/helios4.h | 6 +----- include/configs/theadorable.h | 3 --- include/configs/turris_omnia.h | 6 ------ include/configs/x530.h | 3 --- scripts/config_whitelist.txt | 1 - tools/Makefile | 4 ---- 14 files changed, 3 insertions(+), 59 deletions(-)
diff --git a/arch/arm/mach-mvebu/Kconfig b/arch/arm/mach-mvebu/Kconfig index 46ac43c7a0..c8118c5a22 100644 --- a/arch/arm/mach-mvebu/Kconfig +++ b/arch/arm/mach-mvebu/Kconfig @@ -253,9 +253,6 @@ choice config MVEBU_SPL_BOOT_DEVICE_SPI bool "SPI NOR flash" imply ENV_IS_IN_SPI_FLASH - select SPL_SPI_FLASH_SUPPORT - select SPL_SPI_LOAD - select SPL_SPI_SUPPORT select SPL_BOOTROM_SUPPORT
config MVEBU_SPL_BOOT_DEVICE_MMC diff --git a/include/configs/clearfog.h b/include/configs/clearfog.h index c9852a72b9..197c6064df 100644 --- a/include/configs/clearfog.h +++ b/include/configs/clearfog.h @@ -69,13 +69,9 @@ #define CONFIG_SPL_STACK (0x40000000 + ((192 - 16) << 10)) #define CONFIG_SPL_BOOTROM_SAVE (CONFIG_SPL_STACK + 4)
-#if defined(CONFIG_MVEBU_SPL_BOOT_DEVICE_SPI) -/* SPL related SPI defines */ -#define CONFIG_SYS_U_BOOT_OFFS CONFIG_SYS_SPI_U_BOOT_OFFS -#elif defined(CONFIG_MVEBU_SPL_BOOT_DEVICE_MMC) || defined(CONFIG_MVEBU_SPL_BOOT_DEVICE_SATA) +#if defined(CONFIG_MVEBU_SPL_BOOT_DEVICE_MMC) || defined(CONFIG_MVEBU_SPL_BOOT_DEVICE_SATA) /* SPL related MMC defines */ #define CONFIG_SYS_MMC_U_BOOT_OFFS (160 << 10) -#define CONFIG_SYS_U_BOOT_OFFS CONFIG_SYS_MMC_U_BOOT_OFFS #ifdef CONFIG_SPL_BUILD #define CONFIG_FIXED_SDHCI_ALIGNED_BUFFER 0x00180000 /* in SDRAM */ #endif diff --git a/include/configs/controlcenterdc.h b/include/configs/controlcenterdc.h index 869b94bc9b..c72d5be369 100644 --- a/include/configs/controlcenterdc.h +++ b/include/configs/controlcenterdc.h @@ -85,18 +85,12 @@ #define CONFIG_SPL_LIBGENERIC_SUPPORT #define CONFIG_SPL_I2C_SUPPORT
-#if CONFIG_SPL_BOOT_DEVICE == SPL_BOOT_SPI_NOR_FLASH -/* SPL related SPI defines */ -#define CONFIG_SYS_U_BOOT_OFFS CONFIG_SYS_SPI_U_BOOT_OFFS -#endif - #if CONFIG_SPL_BOOT_DEVICE == SPL_BOOT_SDIO_MMC_CARD /* SPL related MMC defines */ #define CONFIG_SPL_MMC_SUPPORT #define CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_PARTITION 1 #define CONFIG_SYS_MMC_U_BOOT_OFFS (168 << 10) -#define CONFIG_SYS_U_BOOT_OFFS CONFIG_SYS_MMC_U_BOOT_OFFS -#define CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_SECTOR (CONFIG_SYS_U_BOOT_OFFS / 512) +#define CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_SECTOR (CONFIG_SYS_MMC_U_BOOT_OFFS / 512) #ifdef CONFIG_SPL_BUILD #define CONFIG_FIXED_SDHCI_ALIGNED_BUFFER 0x00180000 /* in SDRAM */ #endif diff --git a/include/configs/db-88f6720.h b/include/configs/db-88f6720.h index 213883ef0f..cbb9270f93 100644 --- a/include/configs/db-88f6720.h +++ b/include/configs/db-88f6720.h @@ -65,7 +65,4 @@ #define CONFIG_SPL_STACK (0x40000000 + ((192 - 16) << 10)) #define CONFIG_SPL_BOOTROM_SAVE (CONFIG_SPL_STACK + 4)
-/* SPL related SPI defines */ -#define CONFIG_SYS_U_BOOT_OFFS CONFIG_SYS_SPI_U_BOOT_OFFS - #endif /* _CONFIG_DB_88F6720_H */ diff --git a/include/configs/db-88f6820-amc.h b/include/configs/db-88f6820-amc.h index fe9a7ab563..757fbc0b9b 100644 --- a/include/configs/db-88f6820-amc.h +++ b/include/configs/db-88f6820-amc.h @@ -59,11 +59,6 @@ #define CONFIG_SPL_STACK (0x40000000 + ((192 - 16) << 10)) #define CONFIG_SPL_BOOTROM_SAVE (CONFIG_SPL_STACK + 4)
-#if CONFIG_SPL_BOOT_DEVICE == SPL_BOOT_SPI_NOR_FLASH -/* SPL related SPI defines */ -#define CONFIG_SYS_U_BOOT_OFFS CONFIG_SYS_SPI_U_BOOT_OFFS -#endif - /* * mv-common.h should be defined after CMD configs since it used them * to enable certain macros diff --git a/include/configs/db-88f6820-gp.h b/include/configs/db-88f6820-gp.h index ed851bc670..82d959d7b2 100644 --- a/include/configs/db-88f6820-gp.h +++ b/include/configs/db-88f6820-gp.h @@ -71,15 +71,9 @@ #define CONFIG_SPL_STACK (0x40000000 + ((192 - 16) << 10)) #define CONFIG_SPL_BOOTROM_SAVE (CONFIG_SPL_STACK + 4)
-#if CONFIG_SPL_BOOT_DEVICE == SPL_BOOT_SPI_NOR_FLASH -/* SPL related SPI defines */ -#define CONFIG_SYS_U_BOOT_OFFS CONFIG_SYS_SPI_U_BOOT_OFFS -#endif - #if CONFIG_SPL_BOOT_DEVICE == SPL_BOOT_SDIO_MMC_CARD /* SPL related MMC defines */ #define CONFIG_SYS_MMC_U_BOOT_OFFS (160 << 10) -#define CONFIG_SYS_U_BOOT_OFFS CONFIG_SYS_MMC_U_BOOT_OFFS #ifdef CONFIG_SPL_BUILD #define CONFIG_FIXED_SDHCI_ALIGNED_BUFFER 0x00180000 /* in SDRAM */ #endif diff --git a/include/configs/db-mv784mp-gp.h b/include/configs/db-mv784mp-gp.h index 3e20516e94..ef7eebd081 100644 --- a/include/configs/db-mv784mp-gp.h +++ b/include/configs/db-mv784mp-gp.h @@ -78,9 +78,6 @@ #define CONFIG_SPL_STACK (0x40000000 + ((192 - 16) << 10)) #define CONFIG_SPL_BOOTROM_SAVE (CONFIG_SPL_STACK + 4)
-/* SPL related SPI defines */ -#define CONFIG_SYS_U_BOOT_OFFS CONFIG_SYS_SPI_U_BOOT_OFFS - /* Enable DDR support in SPL (DDR3 training from Marvell bin_hdr) */ #define CONFIG_SPD_EEPROM 0x4e #define CONFIG_BOARD_ECC_SUPPORT /* this board supports ECC */ diff --git a/include/configs/ds414.h b/include/configs/ds414.h index c8b45066cc..4bbb244fa2 100644 --- a/include/configs/ds414.h +++ b/include/configs/ds414.h @@ -68,11 +68,6 @@ #define CONFIG_SPL_STACK (0x40000000 + ((192 - 16) << 10)) #define CONFIG_SPL_BOOTROM_SAVE (CONFIG_SPL_STACK + 4)
-#if defined(CONFIG_MVEBU_SPL_BOOT_DEVICE_SPI) -/* SPL related SPI defines */ -#define CONFIG_SYS_U_BOOT_OFFS CONFIG_SYS_SPI_U_BOOT_OFFS -#endif - /* DS414 bus width is 32bits */ #define CONFIG_DDR_32BIT
diff --git a/include/configs/helios4.h b/include/configs/helios4.h index 2cda05c85a..0ab09517c3 100644 --- a/include/configs/helios4.h +++ b/include/configs/helios4.h @@ -69,13 +69,9 @@ #define CONFIG_SPL_STACK (0x40000000 + ((192 - 16) << 10)) #define CONFIG_SPL_BOOTROM_SAVE (CONFIG_SPL_STACK + 4)
-#if defined(CONFIG_MVEBU_SPL_BOOT_DEVICE_SPI) -/* SPL related SPI defines */ -#define CONFIG_SYS_U_BOOT_OFFS CONFIG_SYS_SPI_U_BOOT_OFFS -#elif defined(CONFIG_MVEBU_SPL_BOOT_DEVICE_MMC) || defined(CONFIG_MVEBU_SPL_BOOT_DEVICE_SATA) +#if defined(CONFIG_MVEBU_SPL_BOOT_DEVICE_MMC) || defined(CONFIG_MVEBU_SPL_BOOT_DEVICE_SATA) /* SPL related MMC defines */ #define CONFIG_SYS_MMC_U_BOOT_OFFS (160 << 10) -#define CONFIG_SYS_U_BOOT_OFFS CONFIG_SYS_MMC_U_BOOT_OFFS #ifdef CONFIG_SPL_BUILD #define CONFIG_FIXED_SDHCI_ALIGNED_BUFFER 0x00180000 /* in SDRAM */ #endif diff --git a/include/configs/theadorable.h b/include/configs/theadorable.h index 587b134a1b..31852fb248 100644 --- a/include/configs/theadorable.h +++ b/include/configs/theadorable.h @@ -93,9 +93,6 @@ #define CONFIG_SPL_STACK (0x40000000 + ((192 - 16) << 10)) #define CONFIG_SPL_BOOTROM_SAVE (CONFIG_SPL_STACK + 4)
-/* SPL related SPI defines */ -#define CONFIG_SYS_U_BOOT_OFFS CONFIG_SYS_SPI_U_BOOT_OFFS - /* Enable DDR support in SPL (DDR3 training from Marvell bin_hdr) */ #define CONFIG_DDR_FIXED_SIZE (2 << 20) /* 2GiB */
diff --git a/include/configs/turris_omnia.h b/include/configs/turris_omnia.h index 7da18f97db..b8b8bf327f 100644 --- a/include/configs/turris_omnia.h +++ b/include/configs/turris_omnia.h @@ -45,15 +45,9 @@ #define CONFIG_SPL_BOOTROM_SAVE (CONFIG_SPL_STACK + 4) #define CONFIG_SPL_DRIVERS_MISC_SUPPORT
-#ifdef CONFIG_MVEBU_SPL_BOOT_DEVICE_SPI -/* SPL related SPI defines */ -# define CONFIG_SYS_U_BOOT_OFFS CONFIG_SYS_SPI_U_BOOT_OFFS -#endif - #ifdef CONFIG_MVEBU_SPL_BOOT_DEVICE_MMC /* SPL related MMC defines */ # define CONFIG_SYS_MMC_U_BOOT_OFFS (160 << 10) -# define CONFIG_SYS_U_BOOT_OFFS CONFIG_SYS_MMC_U_BOOT_OFFS # ifdef CONFIG_SPL_BUILD # define CONFIG_FIXED_SDHCI_ALIGNED_BUFFER 0x00180000 /* in SDRAM */ # endif diff --git a/include/configs/x530.h b/include/configs/x530.h index 4446510df4..515c6e7ff4 100644 --- a/include/configs/x530.h +++ b/include/configs/x530.h @@ -97,7 +97,4 @@ #define CONFIG_SPL_STACK (0x40000000 + ((192 - 16) << 10)) #define CONFIG_SPL_BOOTROM_SAVE (CONFIG_SPL_STACK + 4)
-/* SPL related SPI defines */ -#define CONFIG_SYS_U_BOOT_OFFS CONFIG_SYS_SPI_U_BOOT_OFFS - #endif /* _CONFIG_X530_H */ diff --git a/scripts/config_whitelist.txt b/scripts/config_whitelist.txt index 042ca116e9..1f88212625 100644 --- a/scripts/config_whitelist.txt +++ b/scripts/config_whitelist.txt @@ -3301,7 +3301,6 @@ CONFIG_SYS_USE_NAND CONFIG_SYS_USE_NANDFLASH CONFIG_SYS_USE_NORFLASH CONFIG_SYS_USR_EXCEP -CONFIG_SYS_U_BOOT_OFFS CONFIG_SYS_VCXK_ACKNOWLEDGE_DDR CONFIG_SYS_VCXK_ACKNOWLEDGE_PIN CONFIG_SYS_VCXK_ACKNOWLEDGE_PORT diff --git a/tools/Makefile b/tools/Makefile index fadf3135d6..794a6cc1ae 100644 --- a/tools/Makefile +++ b/tools/Makefile @@ -155,10 +155,6 @@ ifdef CONFIG_FIT_CIPHER HOST_EXTRACFLAGS += -DCONFIG_FIT_CIPHER endif
-ifneq ($(CONFIG_SYS_U_BOOT_OFFS),) -HOSTCFLAGS_kwbimage.o += -DCONFIG_SYS_U_BOOT_OFFS=$(CONFIG_SYS_U_BOOT_OFFS) -endif - ifneq ($(CONFIG_ARMADA_38X),) HOSTCFLAGS_kwbimage.o += -DCONFIG_KWB_SECURE endif

From: Pali Rohár pali@kernel.org
The kwbimage v1 format supports multiple BINARY executable headers. Add support for it into mkimage/kwbimage tool.
Signed-off-by: Pali Rohár pali@kernel.org Reviewed-by: Marek Behún marek.behun@nic.cz --- tools/kwbimage.c | 44 ++++++++++++++++++++------------------------ 1 file changed, 20 insertions(+), 24 deletions(-)
diff --git a/tools/kwbimage.c b/tools/kwbimage.c index 656f3f9ae9..08c9ba99d4 100644 --- a/tools/kwbimage.c +++ b/tools/kwbimage.c @@ -942,6 +942,7 @@ static size_t image_headersz_v1(int *hasext) { struct image_cfg_element *binarye; size_t headersz; + int cfgi;
/* * Calculate the size of the header and the size of the @@ -949,21 +950,19 @@ static size_t image_headersz_v1(int *hasext) */ headersz = sizeof(struct main_hdr_v1);
- if (image_count_options(IMAGE_CFG_BINARY) > 1) { - fprintf(stderr, "More than one binary blob, not supported\n"); - return 0; - } - if (image_count_options(IMAGE_CFG_PAYLOAD) > 1) { fprintf(stderr, "More than one payload, not possible\n"); return 0; }
- binarye = image_find_option(IMAGE_CFG_BINARY); - if (binarye) { + for (cfgi = 0; cfgi < cfgn; cfgi++) { int ret; struct stat s;
+ binarye = &image_cfg[cfgi]; + if (binarye->type != IMAGE_CFG_BINARY) + continue; + ret = stat(binarye->binary.file, &s); if (ret < 0) { char cwd[PATH_MAX]; @@ -1005,9 +1004,9 @@ static size_t image_headersz_v1(int *hasext) return ALIGN(headersz, 4096); }
-int add_binary_header_v1(uint8_t *cur) +int add_binary_header_v1(uint8_t *cur, uint8_t **next_ext, + struct image_cfg_element *binarye) { - struct image_cfg_element *binarye; struct opt_hdr_v1 *hdr = (struct opt_hdr_v1 *)cur; uint32_t *args; size_t binhdrsz; @@ -1016,11 +1015,6 @@ int add_binary_header_v1(uint8_t *cur) FILE *bin; int ret;
- binarye = image_find_option(IMAGE_CFG_BINARY); - - if (!binarye) - return 0; - hdr->headertype = OPT_HDR_V1_BINARY_TYPE;
bin = fopen(binarye->binary.file, "r"); @@ -1071,13 +1065,8 @@ int add_binary_header_v1(uint8_t *cur)
cur += ALIGN(s.st_size, 4);
- /* - * For now, we don't support more than one binary - * header, and no other header types are - * supported. So, the binary header is necessarily the - * last one - */ - *((uint32_t *)cur) = 0x00000000; + **next_ext = 1; + *next_ext = cur;
cur += sizeof(uint32_t);
@@ -1212,6 +1201,7 @@ static void *image_create_v1(size_t *imagesz, struct image_tool_params *params, uint8_t *image, *cur; int hasext = 0; uint8_t *next_ext = NULL; + int cfgi;
/* * Calculate the size of the header and the size of the @@ -1288,13 +1278,19 @@ static void *image_create_v1(size_t *imagesz, struct image_tool_params *params, */ secure_hdr = (struct secure_hdr_v1 *)cur; cur += sizeof(struct secure_hdr_v1); + *next_ext = 1; next_ext = &secure_hdr->next; } #endif - *next_ext = 1;
- if (add_binary_header_v1(cur)) - return NULL; + for (cfgi = 0; cfgi < cfgn; cfgi++) { + e = &image_cfg[cfgi]; + if (e->type != IMAGE_CFG_BINARY) + continue; + + if (add_binary_header_v1(cur, &next_ext, e)) + return NULL; + }
#if defined(CONFIG_KWB_SECURE) if (secure_hdr && add_secure_header_v1(params, ptr, payloadsz,

From: Pali Rohár pali@kernel.org
The PAYLOAD keyword does nothing. No code is using it and both mkimage and kwbimage completely ignore it. It looks like a relict from the past. The payload image itself can be specified only via -d parameter to mkimage.
Signed-off-by: Pali Rohár pali@kernel.org Reviewed-by: Marek Behún marek.behun@nic.cz --- tools/kwbimage.c | 13 ------------- 1 file changed, 13 deletions(-)
diff --git a/tools/kwbimage.c b/tools/kwbimage.c index 08c9ba99d4..689a4f7a4e 100644 --- a/tools/kwbimage.c +++ b/tools/kwbimage.c @@ -103,7 +103,6 @@ enum image_cfg_type { IMAGE_CFG_NAND_ECC_MODE, IMAGE_CFG_NAND_PAGESZ, IMAGE_CFG_BINARY, - IMAGE_CFG_PAYLOAD, IMAGE_CFG_DATA, IMAGE_CFG_BAUDRATE, IMAGE_CFG_DEBUG, @@ -131,7 +130,6 @@ static const char * const id_strs[] = { [IMAGE_CFG_NAND_ECC_MODE] = "NAND_ECC_MODE", [IMAGE_CFG_NAND_PAGESZ] = "NAND_PAGE_SIZE", [IMAGE_CFG_BINARY] = "BINARY", - [IMAGE_CFG_PAYLOAD] = "PAYLOAD", [IMAGE_CFG_DATA] = "DATA", [IMAGE_CFG_BAUDRATE] = "BAUDRATE", [IMAGE_CFG_DEBUG] = "DEBUG", @@ -157,7 +155,6 @@ struct image_cfg_element { unsigned int args[BINARY_MAX_ARGS]; unsigned int nargs; } binary; - const char *payload; unsigned int dstaddr; unsigned int execaddr; unsigned int nandblksz; @@ -874,11 +871,6 @@ static void *image_create_v0(size_t *imagesz, struct image_tool_params *params, headersz += sizeof(struct ext_hdr_v0); }
- if (image_count_options(IMAGE_CFG_PAYLOAD) > 1) { - fprintf(stderr, "More than one payload, not possible\n"); - return NULL; - } - image = malloc(headersz); if (!image) { fprintf(stderr, "Cannot allocate memory for image\n"); @@ -950,11 +942,6 @@ static size_t image_headersz_v1(int *hasext) */ headersz = sizeof(struct main_hdr_v1);
- if (image_count_options(IMAGE_CFG_PAYLOAD) > 1) { - fprintf(stderr, "More than one payload, not possible\n"); - return 0; - } - for (cfgi = 0; cfgi < cfgn; cfgi++) { int ret; struct stat s;

From: Pali Rohár pali@kernel.org
The DATA command is already supported by mkimage for v0 images, but not for v1 images.
BootROM code which executes v1 images also supports DATA command via an optional extended v1 header OPT_HDR_V1_REGISTER_TYPE.
Implement support for DATA command for v1 images.
Signed-off-by: Pali Rohár pali@kernel.org Reviewed-by: Marek Behún marek.behun@nic.cz --- tools/kwbimage.c | 32 +++++++++++++++++++++++++++++++- tools/kwbimage.h | 27 +++++++++++++++++++++++++++ 2 files changed, 58 insertions(+), 1 deletion(-)
diff --git a/tools/kwbimage.c b/tools/kwbimage.c index 689a4f7a4e..dc2b0a12e6 100644 --- a/tools/kwbimage.c +++ b/tools/kwbimage.c @@ -933,6 +933,7 @@ static void *image_create_v0(size_t *imagesz, struct image_tool_params *params, static size_t image_headersz_v1(int *hasext) { struct image_cfg_element *binarye; + unsigned int count; size_t headersz; int cfgi;
@@ -942,6 +943,10 @@ static size_t image_headersz_v1(int *hasext) */ headersz = sizeof(struct main_hdr_v1);
+ count = image_count_options(IMAGE_CFG_DATA); + if (count > 0) + headersz += sizeof(struct register_set_hdr_v1) + 8 * count + 4; + for (cfgi = 0; cfgi < cfgn; cfgi++) { int ret; struct stat s; @@ -1181,6 +1186,7 @@ static void *image_create_v1(size_t *imagesz, struct image_tool_params *params, { struct image_cfg_element *e; struct main_hdr_v1 *main_hdr; + struct register_set_hdr_v1 *register_set_hdr; #if defined(CONFIG_KWB_SECURE) struct secure_hdr_v1 *secure_hdr = NULL; #endif @@ -1188,7 +1194,7 @@ static void *image_create_v1(size_t *imagesz, struct image_tool_params *params, uint8_t *image, *cur; int hasext = 0; uint8_t *next_ext = NULL; - int cfgi; + int cfgi, datai, size;
/* * Calculate the size of the header and the size of the @@ -1270,6 +1276,30 @@ static void *image_create_v1(size_t *imagesz, struct image_tool_params *params, } #endif
+ datai = 0; + register_set_hdr = (struct register_set_hdr_v1 *)cur; + for (cfgi = 0; cfgi < cfgn; cfgi++) { + e = &image_cfg[cfgi]; + if (e->type != IMAGE_CFG_DATA) + continue; + register_set_hdr->data[datai].entry.address = + cpu_to_le32(e->regdata.raddr); + register_set_hdr->data[datai].entry.value = + cpu_to_le32(e->regdata.rdata); + datai++; + } + if (datai != 0) { + size = 8 * datai + 4; + register_set_hdr->headertype = OPT_HDR_V1_REGISTER_TYPE; + register_set_hdr->headersz_lsb = cpu_to_le16(size & 0xFFFF); + register_set_hdr->headersz_msb = size >> 16; + /* Set delay to the smallest possible value 1ms. */ + register_set_hdr->data[datai].last_entry.delay = 1; + cur += sizeof(struct register_set_hdr_v1) + size; + *next_ext = 1; + next_ext = ®ister_set_hdr->data[datai].last_entry.next; + } + for (cfgi = 0; cfgi < cfgn; cfgi++) { e = &image_cfg[cfgi]; if (e->type != IMAGE_CFG_BINARY) diff --git a/tools/kwbimage.h b/tools/kwbimage.h index cab3d95d13..9f86da46e8 100644 --- a/tools/kwbimage.h +++ b/tools/kwbimage.h @@ -148,6 +148,33 @@ struct secure_hdr_v1 { uint16_t reserved5; /* 0x25E2 - 0x25E3 */ };
+/* + * Structure of register set + */ +struct register_set_hdr_v1 { + uint8_t headertype; /* 0x0 */ + uint8_t headersz_msb; /* 0x1 */ + uint16_t headersz_lsb; /* 0x2 - 0x3 */ + union { + struct { + uint32_t address; /* 0x4+8*N - 0x7+8*N */ + uint32_t value; /* 0x8+8*N - 0xB+8*N */ + } entry; + struct { + uint8_t next; /* 0xC+8*N */ + uint8_t delay; /* 0xD+8*N */ + uint16_t reserved; /* 0xE+8*N - 0xF+8*N */ + } last_entry; + } data[]; +}; + +/* + * Value 0 in register_set_hdr_v1 delay field is special. + * Instead of delay it setup SDRAM Controller. + */ +#define REGISTER_SET_HDR_OPT_DELAY_SDRAM_SETUP 0 +#define REGISTER_SET_HDR_OPT_DELAY_MS(val) ((val) ?: 1) + /* * Various values for the opt_hdr_v1->headertype field, describing the * different types of optional headers. The "secure" header contains

From: Pali Rohár pali@kernel.org
This command is supported only by v1 images and specifies a milliseconds delay after executing some set of DATA commands. The special string value SDRAM_SETUP instructs BootROM to setup SDRAM controller instead of executing delay. SDRAM_SETUP may be specified only once and after the last DATA command.
Signed-off-by: Pali Rohár pali@kernel.org Reviewed-by: Marek Behún marek.behun@nic.cz --- tools/kwbimage.c | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-)
diff --git a/tools/kwbimage.c b/tools/kwbimage.c index dc2b0a12e6..99c74b081a 100644 --- a/tools/kwbimage.c +++ b/tools/kwbimage.c @@ -104,6 +104,7 @@ enum image_cfg_type { IMAGE_CFG_NAND_PAGESZ, IMAGE_CFG_BINARY, IMAGE_CFG_DATA, + IMAGE_CFG_DATA_DELAY, IMAGE_CFG_BAUDRATE, IMAGE_CFG_DEBUG, IMAGE_CFG_KAK, @@ -131,6 +132,7 @@ static const char * const id_strs[] = { [IMAGE_CFG_NAND_PAGESZ] = "NAND_PAGE_SIZE", [IMAGE_CFG_BINARY] = "BINARY", [IMAGE_CFG_DATA] = "DATA", + [IMAGE_CFG_DATA_DELAY] = "DATA_DELAY", [IMAGE_CFG_BAUDRATE] = "BAUDRATE", [IMAGE_CFG_DEBUG] = "DEBUG", [IMAGE_CFG_KAK] = "KAK", @@ -162,6 +164,7 @@ struct image_cfg_element { unsigned int nandeccmode; unsigned int nandpagesz; struct ext_hdr_v0_reg regdata; + unsigned int regdata_delay; unsigned int baudrate; unsigned int debug; const char *key_name; @@ -1280,8 +1283,21 @@ static void *image_create_v1(size_t *imagesz, struct image_tool_params *params, register_set_hdr = (struct register_set_hdr_v1 *)cur; for (cfgi = 0; cfgi < cfgn; cfgi++) { e = &image_cfg[cfgi]; - if (e->type != IMAGE_CFG_DATA) + if (e->type != IMAGE_CFG_DATA && + e->type != IMAGE_CFG_DATA_DELAY) continue; + if (e->type == IMAGE_CFG_DATA_DELAY) { + size = 8 * datai + 4; + register_set_hdr->headertype = OPT_HDR_V1_REGISTER_TYPE; + register_set_hdr->headersz_lsb = cpu_to_le16(size & 0xFFFF); + register_set_hdr->headersz_msb = size >> 16; + register_set_hdr->data[datai].last_entry.delay = e->regdata_delay; + cur += sizeof(struct register_set_hdr_v1) + size; + *next_ext = 1; + next_ext = ®ister_set_hdr->data[datai].last_entry.next; + datai = 0; + continue; + } register_set_hdr->data[datai].entry.address = cpu_to_le32(e->regdata.raddr); register_set_hdr->data[datai].entry.value = @@ -1420,6 +1436,12 @@ static int image_create_config_parse_oneline(char *line, el->regdata.raddr = strtoul(value1, NULL, 16); el->regdata.rdata = strtoul(value2, NULL, 16); break; + case IMAGE_CFG_DATA_DELAY: + if (!strcmp(value1, "SDRAM_SETUP")) + el->regdata_delay = REGISTER_SET_HDR_OPT_DELAY_SDRAM_SETUP; + else + el->regdata_delay = REGISTER_SET_HDR_OPT_DELAY_MS(strtoul(value1, NULL, 10)); + break; case IMAGE_CFG_BAUDRATE: el->baudrate = strtoul(value1, NULL, 10); break;

From: Pali Rohár pali@kernel.org
The mkimage host tool can be used to generate kwbimage v1 image with secure header on host system for A38x plaform also when U-Boot is being compiled for different platform. So there is no reason to not allow compiling of mkimage/kwbimage with secure header support for e.g. x86-64 host.
Signed-off-by: Pali Rohár pali@kernel.org Reviewed-by: Marek Behún marek.behun@nic.cz --- tools/Makefile | 4 ---- tools/kwbimage.c | 22 ---------------------- 2 files changed, 26 deletions(-)
diff --git a/tools/Makefile b/tools/Makefile index 794a6cc1ae..11a5a15bc2 100644 --- a/tools/Makefile +++ b/tools/Makefile @@ -155,10 +155,6 @@ ifdef CONFIG_FIT_CIPHER HOST_EXTRACFLAGS += -DCONFIG_FIT_CIPHER endif
-ifneq ($(CONFIG_ARMADA_38X),) -HOSTCFLAGS_kwbimage.o += -DCONFIG_KWB_SECURE -endif - # MXSImage needs LibSSL ifneq ($(CONFIG_MX23)$(CONFIG_MX28)$(CONFIG_ARMADA_38X)$(CONFIG_FIT_SIGNATURE)$(CONFIG_FIT_CIPHER),) HOSTCFLAGS_kwbimage.o += \ diff --git a/tools/kwbimage.c b/tools/kwbimage.c index 99c74b081a..82dd904e25 100644 --- a/tools/kwbimage.c +++ b/tools/kwbimage.c @@ -16,7 +16,6 @@ #include <stdint.h> #include "kwbimage.h"
-#ifdef CONFIG_KWB_SECURE #include <openssl/bn.h> #include <openssl/rsa.h> #include <openssl/pem.h> @@ -42,13 +41,10 @@ void EVP_MD_CTX_cleanup(EVP_MD_CTX *ctx) EVP_MD_CTX_reset(ctx); } #endif -#endif
static struct image_cfg_element *image_cfg; static int cfgn; -#ifdef CONFIG_KWB_SECURE static int verbose_mode; -#endif
struct boot_mode { unsigned int id; @@ -243,8 +239,6 @@ image_count_options(unsigned int optiontype) return count; }
-#if defined(CONFIG_KWB_SECURE) - static int image_get_csk_index(void) { struct image_cfg_element *e; @@ -267,8 +261,6 @@ static bool image_get_spezialized_img(void) return e->sec_specialized_img; }
-#endif - /* * Compute a 8-bit checksum of a memory area. This algorithm follows * the requirements of the Marvell SoC BootROM specifications. @@ -363,7 +355,6 @@ static uint8_t baudrate_to_option(unsigned int baudrate) } }
-#if defined(CONFIG_KWB_SECURE) static void kwb_msg(const char *fmt, ...) { if (verbose_mode) { @@ -852,8 +843,6 @@ done: return ret; }
-#endif - static void *image_create_v0(size_t *imagesz, struct image_tool_params *params, int payloadsz) { @@ -984,13 +973,11 @@ static size_t image_headersz_v1(int *hasext) *hasext = 1; }
-#if defined(CONFIG_KWB_SECURE) if (image_get_csk_index() >= 0) { headersz += sizeof(struct secure_hdr_v1); if (hasext) *hasext = 1; } -#endif
/* * The payload should be aligned on some reasonable @@ -1073,8 +1060,6 @@ err_close: return -1; }
-#if defined(CONFIG_KWB_SECURE) - int export_pub_kak_hash(RSA *kak, struct secure_hdr_v1 *secure_hdr) { FILE *hashf; @@ -1182,7 +1167,6 @@ int add_secure_header_v1(struct image_tool_params *params, uint8_t *ptr,
return 0; } -#endif
static void *image_create_v1(size_t *imagesz, struct image_tool_params *params, uint8_t *ptr, int payloadsz) @@ -1190,9 +1174,7 @@ static void *image_create_v1(size_t *imagesz, struct image_tool_params *params, struct image_cfg_element *e; struct main_hdr_v1 *main_hdr; struct register_set_hdr_v1 *register_set_hdr; -#if defined(CONFIG_KWB_SECURE) struct secure_hdr_v1 *secure_hdr = NULL; -#endif size_t headersz; uint8_t *image, *cur; int hasext = 0; @@ -1266,7 +1248,6 @@ static void *image_create_v1(size_t *imagesz, struct image_tool_params *params, if (main_hdr->blockid == IBR_HDR_PEX_ID) main_hdr->srcaddr = cpu_to_le32(0xFFFFFFFF);
-#if defined(CONFIG_KWB_SECURE) if (image_get_csk_index() >= 0) { /* * only reserve the space here; we fill the header later since @@ -1277,7 +1258,6 @@ static void *image_create_v1(size_t *imagesz, struct image_tool_params *params, *next_ext = 1; next_ext = &secure_hdr->next; } -#endif
datai = 0; register_set_hdr = (struct register_set_hdr_v1 *)cur; @@ -1325,11 +1305,9 @@ static void *image_create_v1(size_t *imagesz, struct image_tool_params *params, return NULL; }
-#if defined(CONFIG_KWB_SECURE) if (secure_hdr && add_secure_header_v1(params, ptr, payloadsz, headersz, image, secure_hdr)) return NULL; -#endif
/* Calculate and set the header checksum */ main_hdr->checksum = image_checksum8(main_hdr, headersz);

Hi Marek & Pali,
On 08.07.21 19:30, Marek Behún wrote:
Hi Stefan and others,
this is a series of improvements to kwboot, kwbimage and mvebu.
The main goal of this series is to correctly use BootROM's code for loading U-Boot from NOR / NAND: currently only SPL is read by BootROM and the main U-Boot is read by SPL. By using BootROM to also load main U-Boot we can reduce the size of SPL image, since it does not need to contain code for reading NOR / NAND.
Before going into a review of the patches, let me ask about the motivation of this patchset. Is the reduction of the SPL image size the main motivation for this series? Or did you experiece some problems with the SPL code for U-Boot proper loading?
BTW: This patch / mail subject "kwboot / kwbimage improvements" does not really match its content AFAIU. Here, the SPL returns always back to the BootROM for U-Boot proper loading part is missing. Or do I misunderstand something?
BTW2: Could you please list the affected MVEBU SoC's that are affected by this series so that this is clear?
Before merging, this series should be tested on as many relevant boards as possible.
I fully agree. I very much welcome any "Tested-by" tags and reviews from others.
Thanks, Stefan
Marek & Pali
Marek Behún (2): tools: kwbimage: Add constant for SDIO bootfrom tools: kwbimage: Cosmetic fix - remove redundant space character
Pali Rohár (29): tools: kwbimage: Fix compilation without CONFIG_SYS_U_BOOT_OFFS tools: kwbimage: Simplify aligning and calculating checksum tools: kwbimage: Align SPI and NAND images to 256 bytes tools: kwbimage: Fix generation of SATA, SDIO and PCIe images tools: kwbimage: Don't crash when binary file name does not contain '/' tools: kwbimage: Fix check for v0 extended header checksum tools: kwbimage: Validate extended headers of v1 images tools: kwbimage: Validate data checksum of v1 images tools: kwbimage: Print size of binary header in kwbimage_print_header() tools: kwboot: Fix wrong parameter passed to read() tools: kwboot: Fix restoring terminal tools: kwboot: Print trailing newline after terminal is terminated tools: kwboot: Cosmetic fix - add missing curly brackets tools: kwboot: Check for v1 header size tools: kwbimage: Use -a parameter (load address) for v1 images arm: mvebu: Fix return_to_bootrom() arm: mvebu: Mark return_to_bootrom() as a noreturn function arm: mvebu: Implement return_to_bootrom() via U-Boot's SPL framework arm: mvebu: Use U-Boot's SPL BootROM framework for booting from NAND/UART arm: mvebu: Always use BootROM for loading the rest of U-Boot's binary arm: mvebu: gdsys: Remove custom spl_board_init() arm: mvebu: Remove legacy U-Boot header from kwbimage v1 files tools: kwbimage: Remove v1 kwbimage SPL padding to CONFIG_SYS_U_BOOT_OFFS bytes arm: mvebu: Remove unused macro CONFIG_SYS_U_BOOT_OFFS tools: kwbimage: Add support for more BINARY headers tools: kwbimage: Don't parse PAYLOAD keyword tools: kwbimage: Add support for DATA command also for v1 images tools: kwbimage: Add support for a new DATA_DELAY command tools: kwbimage: Do not hide usage of secure header under CONFIG_ARMADA_38X
Makefile | 2 +- arch/arm/mach-mvebu/Kconfig | 16 +- arch/arm/mach-mvebu/include/mach/cpu.h | 2 +- arch/arm/mach-mvebu/lowlevel_spl.S | 3 +- arch/arm/mach-mvebu/spl.c | 90 +------ board/gdsys/a38x/Makefile | 2 +- board/gdsys/a38x/spl.c | 20 -- include/configs/clearfog.h | 6 +- include/configs/controlcenterdc.h | 8 +- include/configs/db-88f6720.h | 3 - include/configs/db-88f6820-amc.h | 5 - include/configs/db-88f6820-gp.h | 6 - include/configs/db-mv784mp-gp.h | 3 - include/configs/ds414.h | 5 - include/configs/helios4.h | 6 +- include/configs/theadorable.h | 3 - include/configs/turris_omnia.h | 6 - include/configs/x530.h | 3 - scripts/config_whitelist.txt | 1 - tools/Makefile | 8 - tools/kwbimage.c | 339 +++++++++++++++++-------- tools/kwbimage.h | 30 ++- tools/kwboot.c | 14 +- 23 files changed, 296 insertions(+), 285 deletions(-) delete mode 100644 board/gdsys/a38x/spl.c
Viele Grüße, Stefan

Hi Stefan
On Fri, 9 Jul 2021 08:05:40 +0200 Stefan Roese sr@denx.de wrote:
The main goal of this series is to correctly use BootROM's code for loading U-Boot from NOR / NAND: currently only SPL is read by BootROM and the main U-Boot is read by SPL. By using BootROM to also load main U-Boot we can reduce the size of SPL image, since it does not need to contain code for reading NOR / NAND.
Before going into a review of the patches, let me ask about the motivation of this patchset. Is the reduction of the SPL image size the main motivation for this series? Or did you experiece some problems with the SPL code for U-Boot proper loading?
The motivation is reduction of SPL code size. Pali started working on something different (adding support for higher baudrates to kwboot, so that a bricked board can be booted over UART faster), and he is still working on it, but when he started studying the kwbimage/kwboot code and A38x documentation, he noticed that these things could be improved, so first he did this series.
BTW: This patch / mail subject "kwboot / kwbimage improvements" does not really match its content AFAIU. Here, the SPL returns always back to the BootROM for U-Boot proper loading part is missing. Or do I misunderstand something?
You are right, the subject of the series could have been better. I shall change it in v2.
BTW2: Could you please list the affected MVEBU SoC's that are affected by this series so that this is clear?
OK.
Marek

Hi Marek,
On 09.07.21 13:22, Marek Behún wrote:
Hi Stefan
On Fri, 9 Jul 2021 08:05:40 +0200 Stefan Roese sr@denx.de wrote:
The main goal of this series is to correctly use BootROM's code for loading U-Boot from NOR / NAND: currently only SPL is read by BootROM and the main U-Boot is read by SPL. By using BootROM to also load main U-Boot we can reduce the size of SPL image, since it does not need to contain code for reading NOR / NAND.
Before going into a review of the patches, let me ask about the motivation of this patchset. Is the reduction of the SPL image size the main motivation for this series? Or did you experiece some problems with the SPL code for U-Boot proper loading?
The motivation is reduction of SPL code size. Pali started working on something different (adding support for higher baudrates to kwboot, so that a bricked board can be booted over UART faster), and he is still working on it, but when he started studying the kwbimage/kwboot code and A38x documentation, he noticed that these things could be improved, so first he did this series.
BTW: This patch / mail subject "kwboot / kwbimage improvements" does not really match its content AFAIU. Here, the SPL returns always back to the BootROM for U-Boot proper loading part is missing. Or do I misunderstand something?
You are right, the subject of the series could have been better. I shall change it in v2.
BTW2: Could you please list the affected MVEBU SoC's that are affected by this series so that this is clear?
OK.
Thanks. And could you please also do one (or more) boot-time comparisons, old vs. new version? This way we can see, if and how the boot-time is affected (perhaps improved, which would be great) by this patch series.
Thanks, Stefan
Marek
Viele Grüße, Stefan

On Fri, 9 Jul 2021 14:35:15 +0200 Stefan Roese sr@denx.de wrote:
Thanks. And could you please also do one (or more) boot-time comparisons, old vs. new version? This way we can see, if and how the boot-time is affected (perhaps improved, which would be great) by this patch series.
For Turris Omnia, the size of the u-boot-spl.kwb binary decreases by ~37 KiB, mainly due to not needing padding anymore. The size of the SPL binary itself (u-boot-spl.bin) decreases by 7.5 KiB (due to code reduction - no SPI NOR code).
Unfortunately the boot time increases by 815 ms, from 2341 ms (on average) to 3156 ms (on average). This is probably because BootROM read the memory differently (lower frequency or some other reason).
I think this 815 ms increase in boot time into U-Boot prompt is worth the 37 KiB saved space for U-Boot code (mainly because on Omnia we have 960 KiB for U-Boot and currently we are at 860 KiB, so enabling some other features in the future may push us to the limit), but others may not agree.
I am going to put this information also into v2 cover letter.
Marek

Hi Marek,
On 09.07.21 16:08, Marek Behún wrote:
On Fri, 9 Jul 2021 14:35:15 +0200 Stefan Roese sr@denx.de wrote:
Thanks. And could you please also do one (or more) boot-time comparisons, old vs. new version? This way we can see, if and how the boot-time is affected (perhaps improved, which would be great) by this patch series.
For Turris Omnia, the size of the u-boot-spl.kwb binary decreases by ~37 KiB, mainly due to not needing padding anymore. The size of the SPL binary itself (u-boot-spl.bin) decreases by 7.5 KiB (due to code reduction - no SPI NOR code).
Unfortunately the boot time increases by 815 ms, from 2341 ms (on average) to 3156 ms (on average).
Ups. This boot-time increase is quite big. And there might be some Armada / MVEBU U-Boot targets that are tuned for fast booting. I can speak for the Armada XP theadorable board, where boot-time is quite critical. I remember that we tuned and optimized here and an increase of perhaps 100ms would be acceptable. But an increase of nearly 1 second is definitely not acceptable here, I'm afraid.
Please see below.
This is probably because BootROM read the memory differently (lower frequency or some other reason).
I think this 815 ms increase in boot time into U-Boot prompt is worth the 37 KiB saved space for U-Boot code (mainly because on Omnia we have 960 KiB for U-Boot and currently we are at 860 KiB, so enabling some other features in the future may push us to the limit), but others may not agree.
Yes, I disagree here. Boot-time is critical for some platforms and this increase is just too high. I might be able to do some tests on theadorable to get actual numbers for this platform.
Could you perhaps add this "SPL returns to BootROM" support as an optional feature that can be selected on a per-board basis?
Thanks, Stefan
I am going to put this information also into v2 cover letter.
Marek

On Saturday 10 July 2021 02:31:32 Stefan Roese wrote:
Could you perhaps add this "SPL returns to BootROM" support as an optional feature that can be selected on a per-board basis?
Hi Stefan! I was thinking about it and it should not be hard. Based on defconfig options you decide if you want to use SPL NOR code or stick with return to BootROM. It is acceptable?
What is needed is just to extend SPL SPI NOR code to parse also kwbimage header (at offset zero) instead of legacy U-Boot header which is removing by this patch series and which was on variable offset.

On Saturday 10 July 2021 02:43:12 Pali Rohár wrote:
On Saturday 10 July 2021 02:31:32 Stefan Roese wrote:
Could you perhaps add this "SPL returns to BootROM" support as an optional feature that can be selected on a per-board basis?
Hi Stefan! I was thinking about it and it should not be hard. Based on defconfig options you decide if you want to use SPL NOR code or stick with return to BootROM. It is acceptable?
What is needed is just to extend SPL SPI NOR code to parse also kwbimage header (at offset zero) instead of legacy U-Boot header which is removing by this patch series and which was on variable offset.
Anyway, this switch "return to BootROM" is done in patch 22. Previous patches 01 - 21 can be applied and used without later patches. So meanwhile could you look at patches 01 - 21 if they are OK and if they could be merged independently of "return to BootROM" patches?

On 10.07.21 02:59, Pali Rohár wrote:
On Saturday 10 July 2021 02:43:12 Pali Rohár wrote:
On Saturday 10 July 2021 02:31:32 Stefan Roese wrote:
Could you perhaps add this "SPL returns to BootROM" support as an optional feature that can be selected on a per-board basis?
Hi Stefan! I was thinking about it and it should not be hard. Based on defconfig options you decide if you want to use SPL NOR code or stick with return to BootROM. It is acceptable?
What is needed is just to extend SPL SPI NOR code to parse also kwbimage header (at offset zero) instead of legacy U-Boot header which is removing by this patch series and which was on variable offset.
Anyway, this switch "return to BootROM" is done in patch 22. Previous patches 01 - 21 can be applied and used without later patches. So meanwhile could you look at patches 01 - 21 if they are OK and if they could be merged independently of "return to BootROM" patches?
I'll try to find some time next week to review these patches.
Thanks, Stefan

On 10.07.21 02:43, Pali Rohár wrote:
On Saturday 10 July 2021 02:31:32 Stefan Roese wrote:
Could you perhaps add this "SPL returns to BootROM" support as an optional feature that can be selected on a per-board basis?
Hi Stefan! I was thinking about it and it should not be hard. Based on defconfig options you decide if you want to use SPL NOR code or stick with return to BootROM. It is acceptable?
I think so, yes. If you patches add features / enhancements for some boards and this can be selected on a per-board basis to not affect other targets then yes, this can be accepted AFAICT.
What is needed is just to extend SPL SPI NOR code to parse also kwbimage header (at offset zero) instead of legacy U-Boot header which is removing by this patch series and which was on variable offset.
It would be helpful, if you could add a Kconfig option to selectively enable "return to BootROM" - disabled per default and enabled for your targets to this patchset.
Thanks, Stefan

Hi Marek, Pali,
On Thu, Jul 08 2021, Marek Behún wrote:
Hi Stefan and others,
this is a series of improvements to kwboot, kwbimage and mvebu.
The main goal of this series is to correctly use BootROM's code for loading U-Boot from NOR / NAND: currently only SPL is read by BootROM and the main U-Boot is read by SPL. By using BootROM to also load main U-Boot we can reduce the size of SPL image, since it does not need to contain code for reading NOR / NAND.
Before merging, this series should be tested on as many relevant boards as possible.
Is this series available for pull at a public git repo? If not, what commit is this series based on?
What platforms have you tested?
baruch
Marek Behún (2): tools: kwbimage: Add constant for SDIO bootfrom tools: kwbimage: Cosmetic fix - remove redundant space character
Pali Rohár (29): tools: kwbimage: Fix compilation without CONFIG_SYS_U_BOOT_OFFS tools: kwbimage: Simplify aligning and calculating checksum tools: kwbimage: Align SPI and NAND images to 256 bytes tools: kwbimage: Fix generation of SATA, SDIO and PCIe images tools: kwbimage: Don't crash when binary file name does not contain '/' tools: kwbimage: Fix check for v0 extended header checksum tools: kwbimage: Validate extended headers of v1 images tools: kwbimage: Validate data checksum of v1 images tools: kwbimage: Print size of binary header in kwbimage_print_header() tools: kwboot: Fix wrong parameter passed to read() tools: kwboot: Fix restoring terminal tools: kwboot: Print trailing newline after terminal is terminated tools: kwboot: Cosmetic fix - add missing curly brackets tools: kwboot: Check for v1 header size tools: kwbimage: Use -a parameter (load address) for v1 images arm: mvebu: Fix return_to_bootrom() arm: mvebu: Mark return_to_bootrom() as a noreturn function arm: mvebu: Implement return_to_bootrom() via U-Boot's SPL framework arm: mvebu: Use U-Boot's SPL BootROM framework for booting from NAND/UART arm: mvebu: Always use BootROM for loading the rest of U-Boot's binary arm: mvebu: gdsys: Remove custom spl_board_init() arm: mvebu: Remove legacy U-Boot header from kwbimage v1 files tools: kwbimage: Remove v1 kwbimage SPL padding to CONFIG_SYS_U_BOOT_OFFS bytes arm: mvebu: Remove unused macro CONFIG_SYS_U_BOOT_OFFS tools: kwbimage: Add support for more BINARY headers tools: kwbimage: Don't parse PAYLOAD keyword tools: kwbimage: Add support for DATA command also for v1 images tools: kwbimage: Add support for a new DATA_DELAY command tools: kwbimage: Do not hide usage of secure header under CONFIG_ARMADA_38X
Makefile | 2 +- arch/arm/mach-mvebu/Kconfig | 16 +- arch/arm/mach-mvebu/include/mach/cpu.h | 2 +- arch/arm/mach-mvebu/lowlevel_spl.S | 3 +- arch/arm/mach-mvebu/spl.c | 90 +------ board/gdsys/a38x/Makefile | 2 +- board/gdsys/a38x/spl.c | 20 -- include/configs/clearfog.h | 6 +- include/configs/controlcenterdc.h | 8 +- include/configs/db-88f6720.h | 3 - include/configs/db-88f6820-amc.h | 5 - include/configs/db-88f6820-gp.h | 6 - include/configs/db-mv784mp-gp.h | 3 - include/configs/ds414.h | 5 - include/configs/helios4.h | 6 +- include/configs/theadorable.h | 3 - include/configs/turris_omnia.h | 6 - include/configs/x530.h | 3 - scripts/config_whitelist.txt | 1 - tools/Makefile | 8 - tools/kwbimage.c | 339 +++++++++++++++++-------- tools/kwbimage.h | 30 ++- tools/kwboot.c | 14 +- 23 files changed, 296 insertions(+), 285 deletions(-) delete mode 100644 board/gdsys/a38x/spl.c

On Fri, 09 Jul 2021 17:54:25 +0300 Baruch Siach baruch@tkos.co.il wrote:
Hi Marek, Pali,
On Thu, Jul 08 2021, Marek Behún wrote:
Hi Stefan and others,
this is a series of improvements to kwboot, kwbimage and mvebu.
The main goal of this series is to correctly use BootROM's code for loading U-Boot from NOR / NAND: currently only SPL is read by BootROM and the main U-Boot is read by SPL. By using BootROM to also load main U-Boot we can reduce the size of SPL image, since it does not need to contain code for reading NOR / NAND.
Before merging, this series should be tested on as many relevant boards as possible.
Is this series available for pull at a public git repo? If not, what commit is this series based on?
What platforms have you tested?
Based on current u-boot master, commit fd075f77ca56ffb07e0b1979f0cb47fc8831600f
Tested only on Turris Omnia (Armada 385).
Marek

On Fri, Jul 9, 2021 at 5:30 AM Marek Behún marek.behun@nic.cz wrote:
Hi Stefan and others,
this is a series of improvements to kwboot, kwbimage and mvebu.
The main goal of this series is to correctly use BootROM's code for loading U-Boot from NOR / NAND: currently only SPL is read by BootROM and the main U-Boot is read by SPL. By using BootROM to also load main U-Boot we can reduce the size of SPL image, since it does not need to contain code for reading NOR / NAND.
Before merging, this series should be tested on as many relevant boards as possible.
I've given the series a look over. Aside from a couple of typos in one commit message which I replied to, the rest looked pretty good.
Review-by: Chris Packham judge.packham@gmail.com
For DB-88f6820-AMC and x530
Tested-by: Chris Packham judge.packham@gmail.com
Marek & Pali
Marek Behún (2): tools: kwbimage: Add constant for SDIO bootfrom tools: kwbimage: Cosmetic fix - remove redundant space character
Pali Rohár (29): tools: kwbimage: Fix compilation without CONFIG_SYS_U_BOOT_OFFS tools: kwbimage: Simplify aligning and calculating checksum tools: kwbimage: Align SPI and NAND images to 256 bytes tools: kwbimage: Fix generation of SATA, SDIO and PCIe images tools: kwbimage: Don't crash when binary file name does not contain '/' tools: kwbimage: Fix check for v0 extended header checksum tools: kwbimage: Validate extended headers of v1 images tools: kwbimage: Validate data checksum of v1 images tools: kwbimage: Print size of binary header in kwbimage_print_header() tools: kwboot: Fix wrong parameter passed to read() tools: kwboot: Fix restoring terminal tools: kwboot: Print trailing newline after terminal is terminated tools: kwboot: Cosmetic fix - add missing curly brackets tools: kwboot: Check for v1 header size tools: kwbimage: Use -a parameter (load address) for v1 images arm: mvebu: Fix return_to_bootrom() arm: mvebu: Mark return_to_bootrom() as a noreturn function arm: mvebu: Implement return_to_bootrom() via U-Boot's SPL framework arm: mvebu: Use U-Boot's SPL BootROM framework for booting from NAND/UART arm: mvebu: Always use BootROM for loading the rest of U-Boot's binary arm: mvebu: gdsys: Remove custom spl_board_init() arm: mvebu: Remove legacy U-Boot header from kwbimage v1 files tools: kwbimage: Remove v1 kwbimage SPL padding to CONFIG_SYS_U_BOOT_OFFS bytes arm: mvebu: Remove unused macro CONFIG_SYS_U_BOOT_OFFS tools: kwbimage: Add support for more BINARY headers tools: kwbimage: Don't parse PAYLOAD keyword tools: kwbimage: Add support for DATA command also for v1 images tools: kwbimage: Add support for a new DATA_DELAY command tools: kwbimage: Do not hide usage of secure header under CONFIG_ARMADA_38X
Makefile | 2 +- arch/arm/mach-mvebu/Kconfig | 16 +- arch/arm/mach-mvebu/include/mach/cpu.h | 2 +- arch/arm/mach-mvebu/lowlevel_spl.S | 3 +- arch/arm/mach-mvebu/spl.c | 90 +------ board/gdsys/a38x/Makefile | 2 +- board/gdsys/a38x/spl.c | 20 -- include/configs/clearfog.h | 6 +- include/configs/controlcenterdc.h | 8 +- include/configs/db-88f6720.h | 3 - include/configs/db-88f6820-amc.h | 5 - include/configs/db-88f6820-gp.h | 6 - include/configs/db-mv784mp-gp.h | 3 - include/configs/ds414.h | 5 - include/configs/helios4.h | 6 +- include/configs/theadorable.h | 3 - include/configs/turris_omnia.h | 6 - include/configs/x530.h | 3 - scripts/config_whitelist.txt | 1 - tools/Makefile | 8 - tools/kwbimage.c | 339 +++++++++++++++++-------- tools/kwbimage.h | 30 ++- tools/kwboot.c | 14 +- 23 files changed, 296 insertions(+), 285 deletions(-) delete mode 100644 board/gdsys/a38x/spl.c
-- 2.31.1
participants (5)
-
Baruch Siach
-
Chris Packham
-
Marek Behún
-
Pali Rohár
-
Stefan Roese