[U-Boot] [PATCH v2 0/3] Fix rockchip spl loader mkimage flow

This series patch fix rockchip spl loader mkimage flow, use imagename to select spl loader size & tag for different chip.
Changes in v2: - Fix some coding style
Jeffy Chen (3): Revert "rockchip: Add max spl size & spl header configs" rockchip: mkimage: use imagename to select spl hdr & spl size rockchip: doc: add imagename
arch/arm/mach-rockchip/Kconfig | 15 -------- arch/arm/mach-rockchip/rk3036/Kconfig | 6 --- arch/arm/mach-rockchip/rk3288/Kconfig | 6 --- doc/README.rockchip | 8 ++-- tools/Makefile | 8 +--- tools/rkcommon.c | 72 ++++++++++++++++++++++++++++++++++- tools/rkcommon.h | 32 +++++++++++++++- tools/rkimage.c | 4 +- tools/rksd.c | 26 ++++--------- tools/rkspi.c | 23 ++++------- 10 files changed, 125 insertions(+), 75 deletions(-)

This reverts commit 10b4615f9d7e177ec7fe644fbb2616e0e0956f6e
Conflicts: tools/rkcommon.h
Signed-off-by: Jeffy Chen jeffy.chen@rock-chips.com
---
Changes in v2: - Fix some coding style
arch/arm/mach-rockchip/Kconfig | 15 --------------- arch/arm/mach-rockchip/rk3036/Kconfig | 6 ------ arch/arm/mach-rockchip/rk3288/Kconfig | 6 ------ tools/Makefile | 8 +------- tools/rkcommon.c | 2 +- tools/rkimage.c | 2 +- tools/rksd.c | 4 ++-- tools/rkspi.c | 4 ++-- 8 files changed, 7 insertions(+), 40 deletions(-)
diff --git a/arch/arm/mach-rockchip/Kconfig b/arch/arm/mach-rockchip/Kconfig index ccff81a..746d9f6 100644 --- a/arch/arm/mach-rockchip/Kconfig +++ b/arch/arm/mach-rockchip/Kconfig @@ -17,21 +17,6 @@ config ROCKCHIP_RK3036 and video codec support. Peripherals include Gigabit Ethernet, USB2 host and OTG, SDIO, I2S, UART, SPI, I2C and PWMs.
-config ROCKCHIP_SPL_HDR - string "Header of rockchip's spl loader" - help - Rockchip's bootrom requires the spl loader to start with a 4-bytes - header. The content of this header depends on the chip type. - -config ROCKCHIP_MAX_SPL_SIZE - hex "Max size of rockchip's spl loader" - help - Different chip may have different sram size. And if we want to jump - back to the bootrom after spl, we may need to reserve some sram space - for the bootrom. - The max spl loader size should be sram size minus reserved - size(if needed) - config SYS_MALLOC_F default y
diff --git a/arch/arm/mach-rockchip/rk3036/Kconfig b/arch/arm/mach-rockchip/rk3036/Kconfig index 95fb2b9..0fbc58e 100644 --- a/arch/arm/mach-rockchip/rk3036/Kconfig +++ b/arch/arm/mach-rockchip/rk3036/Kconfig @@ -9,12 +9,6 @@ config SYS_SOC config SYS_MALLOC_F_LEN default 0x400
-config ROCKCHIP_SPL_HDR - default "RK30" - -config ROCKCHIP_MAX_SPL_SIZE - default 0x1000 - config ROCKCHIP_COMMON bool "Support rk common fuction"
diff --git a/arch/arm/mach-rockchip/rk3288/Kconfig b/arch/arm/mach-rockchip/rk3288/Kconfig index 3de3878..d0a7276 100644 --- a/arch/arm/mach-rockchip/rk3288/Kconfig +++ b/arch/arm/mach-rockchip/rk3288/Kconfig @@ -16,12 +16,6 @@ config TARGET_CHROMEBOOK_JERRY WiFi. It includes a Chrome OS EC (Cortex-M3) to provide access to the keyboard and battery functions.
-config ROCKCHIP_SPL_HDR - default "RK32" - -config ROCKCHIP_MAX_SPL_SIZE - default 0x8000 - config SYS_SOC default "rockchip"
diff --git a/tools/Makefile b/tools/Makefile index 117b07e..9082bda 100644 --- a/tools/Makefile +++ b/tools/Makefile @@ -64,7 +64,7 @@ RSA_OBJS-$(CONFIG_FIT_SIGNATURE) := $(addprefix lib/rsa/, \ rsa-sign.o rsa-verify.o rsa-checksum.o \ rsa-mod-exp.o)
-ROCKCHIP_OBS = $(if $(CONFIG_ARCH_ROCKCHIP),lib/rc4.o rkcommon.o rkimage.o rksd.o,) +ROCKCHIP_OBS = lib/rc4.o rkcommon.o rkimage.o rksd.o
# common objs for dumpimage and mkimage dumpimage-mkimage-objs := aisimage.o \ @@ -108,12 +108,6 @@ fit_check_sign-objs := $(dumpimage-mkimage-objs) fit_check_sign.o
# TODO(sjg@chromium.org): Is this correct on Mac OS?
-ifneq ($(CONFIG_ARCH_ROCKCHIP),) -HOST_EXTRACFLAGS += \ - -DCONFIG_ROCKCHIP_MAX_SPL_SIZE=$(CONFIG_ROCKCHIP_MAX_SPL_SIZE) \ - -DCONFIG_ROCKCHIP_SPL_HDR=""$(CONFIG_ROCKCHIP_SPL_HDR)"" -endif - ifneq ($(CONFIG_MX23)$(CONFIG_MX28),) # Add CONFIG_MXS into host CFLAGS, so we can check whether or not register # the mxsimage support within tools/mxsimage.c . diff --git a/tools/rkcommon.c b/tools/rkcommon.c index 249c862..9e2173f 100644 --- a/tools/rkcommon.c +++ b/tools/rkcommon.c @@ -49,7 +49,7 @@ int rkcommon_set_header(void *buf, uint file_size) { struct header0_info *hdr;
- if (file_size > CONFIG_ROCKCHIP_MAX_SPL_SIZE) + if (file_size > RK_MAX_CODE1_SIZE) return -ENOSPC;
memset(buf, '\0', RK_INIT_OFFSET * RK_BLK_SIZE); diff --git a/tools/rkimage.c b/tools/rkimage.c index 73634e3..7b292f4 100644 --- a/tools/rkimage.c +++ b/tools/rkimage.c @@ -30,7 +30,7 @@ static void rkimage_print_header(const void *buf) static void rkimage_set_header(void *buf, struct stat *sbuf, int ifd, struct image_tool_params *params) { - memcpy(buf, CONFIG_ROCKCHIP_SPL_HDR, 4); + memcpy(buf, "RK32", 4); }
static int rkimage_extract_subimage(void *buf, struct image_tool_params *params) diff --git a/tools/rksd.c b/tools/rksd.c index f660d56..39f5c75 100644 --- a/tools/rksd.c +++ b/tools/rksd.c @@ -50,7 +50,7 @@ static void rksd_set_header(void *buf, struct stat *sbuf, int ifd, size); }
- memcpy(buf + RKSD_SPL_HDR_START, CONFIG_ROCKCHIP_SPL_HDR, 4); + memcpy(buf + RKSD_SPL_HDR_START, "RK32", 4); }
static int rksd_extract_subimage(void *buf, struct image_tool_params *params) @@ -72,7 +72,7 @@ static int rksd_vrec_header(struct image_tool_params *params, { int pad_size;
- pad_size = RKSD_SPL_HDR_START + CONFIG_ROCKCHIP_MAX_SPL_SIZE; + pad_size = RKSD_SPL_HDR_START + RK_MAX_CODE1_SIZE; debug("pad_size %x\n", pad_size);
return pad_size - params->file_size; diff --git a/tools/rkspi.c b/tools/rkspi.c index 69a12f0..eb8119b 100644 --- a/tools/rkspi.c +++ b/tools/rkspi.c @@ -53,7 +53,7 @@ static void rkspi_set_header(void *buf, struct stat *sbuf, int ifd, size); }
- memcpy(buf + RKSPI_SPL_HDR_START, CONFIG_ROCKCHIP_SPL_HDR, 4); + memcpy(buf + RKSPI_SPL_HDR_START, "RK32", 4);
/* * Spread the image out so we only use the first 2KB of each 4KB @@ -89,7 +89,7 @@ static int rkspi_vrec_header(struct image_tool_params *params, { int pad_size;
- pad_size = (CONFIG_ROCKCHIP_MAX_SPL_SIZE + 0x7ff) / 0x800 * 0x800; + pad_size = (RK_MAX_CODE1_SIZE + 0x7ff) / 0x800 * 0x800; params->orig_file_size = pad_size;
/* We will double the image size due to the SPI format */

On 26 November 2015 at 20:07, Jeffy Chen jeffy.chen@rock-chips.com wrote:
This reverts commit 10b4615f9d7e177ec7fe644fbb2616e0e0956f6e
Conflicts: tools/rkcommon.h
Signed-off-by: Jeffy Chen jeffy.chen@rock-chips.com
Changes in v2:
- Fix some coding style
arch/arm/mach-rockchip/Kconfig | 15 --------------- arch/arm/mach-rockchip/rk3036/Kconfig | 6 ------ arch/arm/mach-rockchip/rk3288/Kconfig | 6 ------ tools/Makefile | 8 +------- tools/rkcommon.c | 2 +- tools/rkimage.c | 2 +- tools/rksd.c | 4 ++-- tools/rkspi.c | 4 ++-- 8 files changed, 7 insertions(+), 40 deletions(-)
Acked-by: Simon Glass sjg@chromium.org

Applied to u-boot-rockchip, thanks!

Our chips may have different spl size and spl header, so use imagename(passed by "mkimage -n") to select them now.
Signed-off-by: Jeffy Chen jeffy.chen@rock-chips.com ---
Changes in v2: None
tools/rkcommon.c | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-- tools/rkcommon.h | 32 ++++++++++++++++++++++++- tools/rkimage.c | 4 +++- tools/rksd.c | 26 +++++++------------- tools/rkspi.c | 23 +++++++----------- 5 files changed, 120 insertions(+), 37 deletions(-)
diff --git a/tools/rkcommon.c b/tools/rkcommon.c index 9e2173f..72621fd 100644 --- a/tools/rkcommon.c +++ b/tools/rkcommon.c @@ -40,16 +40,84 @@ struct header0_info { uint8_t reserved2[2]; };
+/** + * struct spl_info - spl info for each chip + * + * @imagename: Image name(passed by "mkimage -n") + * @spl_hdr: Boot ROM requires a 4-bytes spl header + * @spl_size: Spl size(include extra 4-bytes spl header) + */ +struct spl_info { + const char *imagename; + const char *spl_hdr; + const uint32_t spl_size; +}; + +static struct spl_info spl_infos[] = { + { "rk3036", "RK30", 0x1000 }, + { "rk3288", "RK32", 0x8000 }, +}; + static unsigned char rc4_key[16] = { 124, 78, 3, 4, 85, 5, 9, 7, 45, 44, 123, 56, 23, 13, 23, 17 };
-int rkcommon_set_header(void *buf, uint file_size) +static struct spl_info *rkcommon_get_spl_info(char *imagename) +{ + int i; + + for (i = 0; i < ARRAY_SIZE(spl_infos); i++) + if (!strncmp(imagename, spl_infos[i].imagename, 6)) + return spl_infos + i; + + return NULL; +} + +int rkcommon_check_params(struct image_tool_params *params) +{ + int i; + + if (rkcommon_get_spl_info(params->imagename) != NULL) + return 0; + + fprintf(stderr, "ERROR: imagename (%s) is not supported!\n", + strlen(params->imagename) > 0 ? params->imagename : "NULL"); + + fprintf(stderr, "Available imagename:"); + for (i = 0; i < ARRAY_SIZE(spl_infos); i++) + fprintf(stderr, "\t%s", spl_infos[i].imagename); + fprintf(stderr, "\n"); + + return -1; +} + +const char *rkcommon_get_spl_hdr(struct image_tool_params *params) +{ + struct spl_info *info = rkcommon_get_spl_info(params->imagename); + + /* + * info would not be NULL, because of we checked params before. + */ + return info->spl_hdr; +} + +int rkcommon_get_spl_size(struct image_tool_params *params) +{ + struct spl_info *info = rkcommon_get_spl_info(params->imagename); + + /* + * info would not be NULL, because of we checked params before. + */ + return info->spl_size; +} + +int rkcommon_set_header(void *buf, uint file_size, + struct image_tool_params *params) { struct header0_info *hdr;
- if (file_size > RK_MAX_CODE1_SIZE) + if (file_size > rkcommon_get_spl_size(params)) return -ENOSPC;
memset(buf, '\0', RK_INIT_OFFSET * RK_BLK_SIZE); diff --git a/tools/rkcommon.h b/tools/rkcommon.h index 0fc1e96..c69540f 100644 --- a/tools/rkcommon.h +++ b/tools/rkcommon.h @@ -12,9 +12,38 @@ enum { RK_BLK_SIZE = 512, RK_INIT_OFFSET = 4, RK_MAX_BOOT_SIZE = 512 << 10, + RK_SPL_HDR_START = RK_INIT_OFFSET * RK_BLK_SIZE, + RK_SPL_HDR_SIZE = 4, + RK_SPL_START = RK_SPL_HDR_START + RK_SPL_HDR_SIZE, + RK_IMAGE_HEADER_LEN = RK_SPL_START, };
/** + * rkcommon_check_params() - check params + * + * @return 0 if OK, -1 if ERROR. + */ +int rkcommon_check_params(struct image_tool_params *params); + +/** + * rkcommon_get_spl_hdr() - get 4-bytes spl hdr for a Rockchip boot image + * + * Rockchip's bootrom requires the spl loader to start with a 4-bytes + * header. The content of this header depends on the chip type. + */ +const char *rkcommon_get_spl_hdr(struct image_tool_params *params); + +/** + * rkcommon_get_spl_size() - get spl size for a Rockchip boot image + * + * Different chip may have different sram size. And if we want to jump + * back to the bootrom after spl, we may need to reserve some sram space + * for the bootrom. + * The spl loader size should be sram size minus reserved size(if needed) + */ +int rkcommon_get_spl_size(struct image_tool_params *params); + +/** * rkcommon_set_header() - set up the header for a Rockchip boot image * * This sets up a 2KB header which can be interpreted by the Rockchip boot ROM. @@ -23,6 +52,7 @@ enum { * @file_size: Size of the file we want the boot ROM to load, in bytes * @return 0 if OK, -ENOSPC if too large */ -int rkcommon_set_header(void *buf, uint file_size); +int rkcommon_set_header(void *buf, uint file_size, + struct image_tool_params *params);
#endif diff --git a/tools/rkimage.c b/tools/rkimage.c index 7b292f4..f9fdcfa 100644 --- a/tools/rkimage.c +++ b/tools/rkimage.c @@ -9,6 +9,7 @@
#include "imagetool.h" #include <image.h> +#include "rkcommon.h"
static uint32_t header;
@@ -30,7 +31,8 @@ static void rkimage_print_header(const void *buf) static void rkimage_set_header(void *buf, struct stat *sbuf, int ifd, struct image_tool_params *params) { - memcpy(buf, "RK32", 4); + memcpy(buf + RK_SPL_HDR_START, rkcommon_get_spl_hdr(params), + RK_SPL_HDR_SIZE); }
static int rkimage_extract_subimage(void *buf, struct image_tool_params *params) diff --git a/tools/rksd.c b/tools/rksd.c index 39f5c75..a2baa74 100644 --- a/tools/rksd.c +++ b/tools/rksd.c @@ -13,18 +13,7 @@ #include "mkimage.h" #include "rkcommon.h"
-enum { - RKSD_SPL_HDR_START = RK_INIT_OFFSET * RK_BLK_SIZE, - RKSD_SPL_START = RKSD_SPL_HDR_START + 4, - RKSD_HEADER_LEN = RKSD_SPL_START, -}; - -static char dummy_hdr[RKSD_HEADER_LEN]; - -static int rksd_check_params(struct image_tool_params *params) -{ - return 0; -} +static char dummy_hdr[RK_IMAGE_HEADER_LEN];
static int rksd_verify_header(unsigned char *buf, int size, struct image_tool_params *params) @@ -42,15 +31,16 @@ static void rksd_set_header(void *buf, struct stat *sbuf, int ifd, unsigned int size; int ret;
- size = params->file_size - RKSD_SPL_HDR_START; - ret = rkcommon_set_header(buf, size); + size = params->file_size - RK_SPL_HDR_START; + ret = rkcommon_set_header(buf, size, params); if (ret) { /* TODO(sjg@chromium.org): This method should return an error */ printf("Warning: SPL image is too large (size %#x) and will not boot\n", size); }
- memcpy(buf + RKSD_SPL_HDR_START, "RK32", 4); + memcpy(buf + RK_SPL_HDR_START, rkcommon_get_spl_hdr(params), + RK_SPL_HDR_SIZE); }
static int rksd_extract_subimage(void *buf, struct image_tool_params *params) @@ -72,7 +62,7 @@ static int rksd_vrec_header(struct image_tool_params *params, { int pad_size;
- pad_size = RKSD_SPL_HDR_START + RK_MAX_CODE1_SIZE; + pad_size = RK_SPL_HDR_START + rkcommon_get_spl_size(params); debug("pad_size %x\n", pad_size);
return pad_size - params->file_size; @@ -84,9 +74,9 @@ static int rksd_vrec_header(struct image_tool_params *params, U_BOOT_IMAGE_TYPE( rksd, "Rockchip SD Boot Image support", - RKSD_HEADER_LEN, + RK_IMAGE_HEADER_LEN, dummy_hdr, - rksd_check_params, + rkcommon_check_params, rksd_verify_header, rksd_print_header, rksd_set_header, diff --git a/tools/rkspi.c b/tools/rkspi.c index eb8119b..800e235 100644 --- a/tools/rkspi.c +++ b/tools/rkspi.c @@ -14,18 +14,10 @@ #include "rkcommon.h"
enum { - RKSPI_SPL_HDR_START = RK_INIT_OFFSET * RK_BLK_SIZE, - RKSPI_SPL_START = RKSPI_SPL_HDR_START + 4, - RKSPI_HEADER_LEN = RKSPI_SPL_START, RKSPI_SECT_LEN = RK_BLK_SIZE * 4, };
-static char dummy_hdr[RKSPI_HEADER_LEN]; - -static int rkspi_check_params(struct image_tool_params *params) -{ - return 0; -} +static char dummy_hdr[RK_IMAGE_HEADER_LEN];
static int rkspi_verify_header(unsigned char *buf, int size, struct image_tool_params *params) @@ -45,7 +37,7 @@ static void rkspi_set_header(void *buf, struct stat *sbuf, int ifd, int ret;
size = params->orig_file_size; - ret = rkcommon_set_header(buf, size); + ret = rkcommon_set_header(buf, size, params); debug("size %x\n", size); if (ret) { /* TODO(sjg@chromium.org): This method should return an error */ @@ -53,7 +45,8 @@ static void rkspi_set_header(void *buf, struct stat *sbuf, int ifd, size); }
- memcpy(buf + RKSPI_SPL_HDR_START, "RK32", 4); + memcpy(buf + RK_SPL_HDR_START, rkcommon_get_spl_hdr(params), + RK_SPL_HDR_SIZE);
/* * Spread the image out so we only use the first 2KB of each 4KB @@ -89,12 +82,12 @@ static int rkspi_vrec_header(struct image_tool_params *params, { int pad_size;
- pad_size = (RK_MAX_CODE1_SIZE + 0x7ff) / 0x800 * 0x800; + pad_size = (rkcommon_get_spl_size(params) + 0x7ff) / 0x800 * 0x800; params->orig_file_size = pad_size;
/* We will double the image size due to the SPI format */ pad_size *= 2; - pad_size += RKSPI_SPL_HDR_START; + pad_size += RK_SPL_HDR_START; debug("pad_size %x\n", pad_size);
return pad_size - params->file_size; @@ -106,9 +99,9 @@ static int rkspi_vrec_header(struct image_tool_params *params, U_BOOT_IMAGE_TYPE( rkspi, "Rockchip SPI Boot Image support", - RKSPI_HEADER_LEN, + RK_IMAGE_HEADER_LEN, dummy_hdr, - rkspi_check_params, + rkcommon_check_params, rkspi_verify_header, rkspi_print_header, rkspi_set_header,

On 26 November 2015 at 20:07, Jeffy Chen jeffy.chen@rock-chips.com wrote:
Our chips may have different spl size and spl header, so use imagename(passed by "mkimage -n") to select them now.
Signed-off-by: Jeffy Chen jeffy.chen@rock-chips.com
Changes in v2: None
tools/rkcommon.c | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-- tools/rkcommon.h | 32 ++++++++++++++++++++++++- tools/rkimage.c | 4 +++- tools/rksd.c | 26 +++++++------------- tools/rkspi.c | 23 +++++++----------- 5 files changed, 120 insertions(+), 37 deletions(-)
Acked-by: Simon Glass sjg@chromium.org

Applied to u-boot-rockchip, thanks!

We now using imagename to select rockchip's spl hdr & spl size.
Signed-off-by: Jeffy Chen jeffy.chen@rock-chips.com Acked-by: Simon Glass sjg@chromium.org ---
Changes in v2: None
doc/README.rockchip | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/doc/README.rockchip b/doc/README.rockchip index 874441c..b455f6f 100644 --- a/doc/README.rockchip +++ b/doc/README.rockchip @@ -71,7 +71,7 @@ Connect your board's OTG port to your computer.
To create a suitable image and write it to the board:
- ./firefly-rk3288/tools/mkimage -T rkimage -d \ + ./firefly-rk3288/tools/mkimage -n rk3288 -T rkimage -d \ ./firefly-rk3288/spl/u-boot-spl-dtb.bin out && \ cat out | openssl rc4 -K 7c4e0304550509072d2c7b38170d1711 | rkflashtool l
@@ -94,7 +94,7 @@ Booting from an SD card
To write an image that boots from an SD card (assumed to be /dev/sdc):
- ./firefly-rk3288/tools/mkimage -T rksd -d \ + ./firefly-rk3288/tools/mkimage -n rk3288 -T rksd -d \ firefly-rk3288/spl/u-boot-spl-dtb.bin out && \ sudo dd if=out of=/dev/sdc seek=64 && \ sudo dd if=firefly-rk3288/u-boot-dtb.img of=/dev/sdc seek=256 @@ -123,7 +123,7 @@ something like: =>
For evb_rk3036 board: - ./evb-rk3036/tools/mkimage -T rksd -d evb-rk3036/spl/u-boot-spl.bin out && \ + ./evb-rk3036/tools/mkimage -n rk3036 -T rksd -d evb-rk3036/spl/u-boot-spl.bin out && \ cat evb-rk3036/u-boot-dtb.bin >> out && \ sudo dd if=out of=/dev/sdc seek=64
@@ -135,7 +135,7 @@ Booting from SPI
To write an image that boots from SPI flash (e.g. for the Haier Chromebook):
- ./chromebook_jerry/tools/mkimage -T rkspi -d chromebook_jerry/spl/u-boot-spl-dtb.bin out + ./chromebook_jerry/tools/mkimage -n rk3036 -T rkspi -d chromebook_jerry/spl/u-boot-spl-dtb.bin out dd if=spl.bin of=out.bin bs=128K conv=sync cat chromebook_jerry/u-boot-dtb.img out.bin dd if=out.bin of=out.bin.pad bs=4M conv=sync

Applied to u-boot-rockchip, thanks!
participants (2)
-
Jeffy Chen
-
Simon Glass