tool: Move ALIGN_MASK to header as common MACRO
PATCH v3 1/8 tool: Move ALIGN_MASK to header as common MACRO
The ALIGN code is need by many files who need handle structure or image align, so move the macro to imagetool.h file.
---
Changes in v3: None
Changes in v2: None
include/imx8image.h | 1 - tools/ifwitool.c | 4 +--- tools/imagetool.h | 3 +++ tools/imx8mimage.c | 2 -- tools/mksunxiboot.c | 4 +--- 5 files changed, 5 insertions(+), 9 deletions(-)
include/imx8image.h +0 -1
@@ -11,7 +11,6 @@#include <image.h> #include <inttypes.h> #include "imagetool.h" -#include "linux/kernel.h" #define __packed __attribute__((packed))
tools/ifwitool.c +1 -3
@@ -8,15 +8,13 @@#include <assert.h> #include <stdbool.h> #include <getopt.h> +#include "imagetool.h" #include "os_support.h" #ifndef __packed#define __packed __attribute__((packed))#endif #define KiB 1024 -#define ALIGN (x, a) __ALIGN_MASK((x), (typeof(x))(a) - 1) -#define __ALIGN_MASK (x, mask) (((x) + (mask)) & ~(mask)) -#define ARRAY_SIZE (x) (sizeof(x) / sizeof((x)[0]))/* * min()/max()/clamp() macros that also do
tools/imagetool.h +3 -0
@@ -25,6 +25,9 @@#define ARRAY_SIZE (x) (sizeof(x) / sizeof((x)[0])) +#define __ALIGN_MASK (x, mask) (((x) + (mask)) & ~(mask)) +#define ALIGN (x, a) __ALIGN_MASK((x), (typeof(x))(a) - 1) +#define IH_ARCH_DEFAULT IH_ARCH_INVALID/* Information about a file that needs to be placed into the FIT */
tools/imx8mimage.c +0 -2
@@ -32,8 +32,6 @@ static uint32_t rom_version = ROM_V1;#define HDMI_FW_SIZE 0x17000/* Use Last 0x1000 for IVT and CSF */ #define ALIGN_SIZE 0x1000 -#define ALIGN (x,a) __ALIGN_MASK((x), (__typeof__(x))(a) - 1, a) -#define __ALIGN_MASK (x,mask,mask2) (((x) + (mask)) / (mask2) * (mask2))static uint32_t get_cfg_value (char *token,char *name,int linenr) {
tools/mksunxiboot.c +1 -3
@@ -14,6 +14,7 @@#include <errno.h> #include <sys/types.h> #include <sys/stat.h> +#include "imagetool.h" #include "../arch/arm/include/asm/arch-sunxi/spl.h" #define STAMP_VALUE 0x5F0A6C39
@@ -44,9 +45,6 @@ int gen_check_sum(struct boot_file_head *head_p)return 0 ; } -#define ALIGN (x, a) __ALIGN_MASK((x), (typeof(x))(a)-1) -#define __ALIGN_MASK (x, mask) (((x)+(mask))&~(mask)) -#define SUNXI_SRAM_SIZE 0x8000/* SoC with smaller size are limited before */ #define SRAM_LOAD_MAX_SIZE (SUNXI_SRAM_SIZE - sizeof(struct boot_file_head))
Signature · 1 line
2.17.1
PATCH v3 2/8 tool: aisimage: use ALIGN instead of self defiend macro
The ALIGN() is available at imagetool.h, no need to self define one.
---
Changes in v3: None
Changes in v2: None
tools/aisimage.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
tools/aisimage.c +4 -4
@@ -10,7 +10,6 @@#define IS_FNC_EXEC (c) (cmd_table[c].AIS_cmd == AIS_CMD_FNLOAD)#define WORD_ALIGN0 4 -#define WORD_ALIGN (len) (((len)+WORD_ALIGN0-1) & ~(WORD_ALIGN0-1))#define MAX_CMD_BUFFER 4096static uint32_t ais_img_size;
@@ -202,8 +201,9 @@ static uint32_t *ais_alloc_buffer(struct image_tool_params *params)* is not left to the main program, because after the datafile * the header must be terminated with the Jump & Close command. */ - ais_img_size =WORD_ALIGN (sbuf.st_size) +MAX_CMD_BUFFER ; - ptr = (uint32_t *)malloc (WORD_ALIGN (sbuf.st_size) +MAX_CMD_BUFFER ); + ais_img_size =ALIGN (sbuf.st_size,WORD_ALIGN0 ) +MAX_CMD_BUFFER ; + ptr = (uint32_t *)malloc (ALIGN (sbuf.st_size,WORD_ALIGN0 ) + +MAX_CMD_BUFFER );if (!ptr) {fprintf (stderr,"%s: malloc return failure: %s\n" , params->cmdname,strerror (errno));
@@ -242,7 +242,7 @@ static uint32_t *ais_copy_image(struct image_tool_params *params, *aisptr++ = params->ep; *aisptr++ = sbuf.st_size;memcpy ((void *)aisptr, ptr, sbuf.st_size); - aisptr +=WORD_ALIGN (sbuf.st_size) /sizeof (uint32_t ); + aisptr +=ALIGN (sbuf.st_size,WORD_ALIGN0 ) /sizeof (uint32_t ); (void )munmap ((void *)ptr, sbuf.st_size); (void )close (dfd);
Signature · 1 line
2.17.1
PATCH v3 2/8 tool: aisimage: use ALIGN instead of self defiend macro
Quoted 3 lines · Kever Yang
The
ALIGN()is available atimagetool.h, no need to self define one.Signed-off-by Kever Yang <[email protected]>
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 659 bytes Desc: not available URL: <https://lists.denx.de/pipermail/u-boot/attachments/20200327/7c54ae86/attachment.sig>
PATCH v3 3/8 tools: mkimage: use common ALIGN to do the size align
In reply to Kever YangThe ALIGN() is now available at imagetool.h, migrate to use it.
---
Changes in v3: None
Changes in v2: None
tools/mkimage.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
tools/mkimage.c +3 -2
@@ -7,6 +7,7 @@* Wolfgang Denk, wd at denx.de */ +#include "imagetool.h" #include "mkimage.h" #include "imximage.h" #include <image.h>
@@ -557,8 +558,8 @@ int main(int argc, char **argv) }if (params.type ==IH_TYPE_FIRMWARE_IVT ) {/* Add alignment and IVT */ -uint32_t aligned_filesize = (params.file_size +0x1000 - -1 ) & ~(0x1000 -1 ); +uint32_t aligned_filesize =ALIGN (params.file_size, +0x1000 );flash_header_v2_t ivt_header = { {0xd1 ,0x2000 ,0x40 }, params.addr,0 ,0 ,0 , params.addr + aligned_filesize
Signature · 1 line
2.17.1
PATCH v3 3/8 tools: mkimage: use common ALIGN to do the size align
Quoted 3 lines · Kever Yang
The
ALIGN()is now available atimagetool.h, migrate to use it.Signed-off-by Kever Yang <[email protected]>
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 659 bytes Desc: not available URL: <https://lists.denx.de/pipermail/u-boot/attachments/20200327/6177e089/attachment.sig>
PATCH v3 4/8 tools: kwbimage: use common ALIGN to do the size align
In reply to Kever YangThe ALIGN() is now available at imagetool.h, migrate to use it.
---
Changes in v3: None
Changes in v2: None
tools/kwbimage.c | 8 ++++---- tools/kwbimage.h | 2 -- 2 files changed, 4 insertions(+), 6 deletions(-)
tools/kwbimage.c +4 -4
@@ -1015,7 +1015,7 @@ static size_t image_headersz_v1(int *hasext)* The payload should be aligned on some reasonable * boundary */ -return ALIGN_SUP (headersz,4096 ); +return ALIGN (headersz,4096 ); }int add_binary_header_v1 (uint8_t *cur)
@@ -1058,7 +1058,7 @@ int add_binary_header_v1(uint8_t *cur)* up to a 4-byte boundary. Plus 4 bytes for the * next-header byte and 3-byte alignment at the end. */ - binhdrsz =ALIGN_SUP (binhdrsz,4 ) +4 ; + binhdrsz =ALIGN (binhdrsz,4 ) +4 ; hdr->headersz_lsb =cpu_to_le16 (binhdrsz &0xFFFF ); hdr->headersz_msb = (binhdrsz &0xFFFF0000 ) >>16 ;
@@ -1082,7 +1082,7 @@ int add_binary_header_v1(uint8_t *cur)fclose (bin); - cur +=ALIGN_SUP (s.st_size,4 ); + cur +=ALIGN (s.st_size,4 );/* * For now, we don't support more than one binary
@@ -1548,7 +1548,7 @@ static void kwbimage_set_header(void *ptr, struct stat *sbuf, int ifd, }/* The MVEBU BootROM does not allow non word aligned payloads */ - sbuf->st_size =ALIGN_SUP (sbuf->st_size,4 ); + sbuf->st_size =ALIGN (sbuf->st_size,4 ); version =image_get_version ();switch (version) {
tools/kwbimage.h +0 -2
@@ -29,8 +29,6 @@#define IBR_HDR_UART_ID 0x69#define IBR_DEF_ATTRIB 0x00 -#define ALIGN_SUP (x, a) (((x) + (a - 1)) & ~(a - 1)) -/* Structure of the main header, version 0 (Kirkwood, Dove) */ struct main_hdr_v0 {uint8_t blockid;/* 0x0 */
Signature · 1 line
2.17.1
PATCH v3 4/8 tools: kwbimage: use common ALIGN to do the size align
Quoted 3 lines · Kever Yang
The
ALIGN()is now available atimagetool.h, migrate to use it.Signed-off-by Kever Yang <[email protected]>
Thanks,
Stefan
Quoted 55 lines
---
Changes in v3: None
Changes in v2: Nonetools/kwbimage.c | 8 ++++---- tools/kwbimage.h | 2 -- 2 files changed, 4 insertions(+), 6 deletions(-)tools/kwbimage.c +4
-4@@ -1015,7 +1015,7 @@ static size_t image_headersz_v1(int *hasext)* The payload should be aligned on some reasonable * boundary */ -return ALIGN_SUP (headersz,4096 ); +return ALIGN (headersz,4096 ); }int add_binary_header_v1 (uint8_t *cur)@@ -1058,7 +1058,7 @@ int add_binary_header_v1(uint8_t *cur)* up to a 4-byte boundary. Plus 4 bytes for the * next-header byte and 3-byte alignment at the end. */ - binhdrsz =ALIGN_SUP (binhdrsz,4 ) +4 ; + binhdrsz =ALIGN (binhdrsz,4 ) +4 ; hdr->headersz_lsb =cpu_to_le16 (binhdrsz &0xFFFF ); hdr->headersz_msb = (binhdrsz &0xFFFF0000 ) >>16 ;@@ -1082,7 +1082,7 @@ int add_binary_header_v1(uint8_t *cur)fclose (bin); - cur +=ALIGN_SUP (s.st_size,4 ); + cur +=ALIGN (s.st_size,4 );/* * For now, we don't support more than one binary @@ -1548,7 +1548,7 @@ static void kwbimage_set_header(void *ptr, struct stat *sbuf, int ifd, }/* The MVEBU BootROM does not allow non word aligned payloads */ - sbuf->st_size =ALIGN_SUP (sbuf->st_size,4 ); + sbuf->st_size =ALIGN (sbuf->st_size,4 ); version =image_get_version ();switch (version) {tools/kwbimage.h +0
-0
tools/kwbimage.h line 34
Quoted 8 lines
tools/kwbimage.h +0
-2@@ -29,8 +29,6 @@#define IBR_HDR_UART_ID 0x69#define IBR_DEF_ATTRIB 0x00 -#define ALIGN_SUP (x, a) (((x) + (a - 1)) & ~(a - 1)) -/* Structure of the main header, version 0 (Kirkwood, Dove) */ struct main_hdr_v0 {uint8_t blockid;/* 0x0 */
Viele Gr??e,
Stefan
Signature · 3 lines
DENX Software Engineering GmbH, Managing Director: Wolfgang Denk HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: (+49)-8142-66989-51 Fax: (+49)-8142-66989-80 Email: sr at denx.de
PATCH v3 4/8 tools: kwbimage: use common ALIGN to do the size align
In reply to Kever YangQuoted 3 lines · Kever Yang
The
ALIGN()is now available atimagetool.h, migrate to use it.Signed-off-by Kever Yang <[email protected]>
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 659 bytes Desc: not available URL: <https://lists.denx.de/pipermail/u-boot/attachments/20200327/6eca8176/attachment.sig>
PATCH v3 5/8 tools: imx8mimage: remove redundant code
In reply to Kever YangThe align for fit_size has been done twice, remove the first one for it does not make any sense.
---
Changes in v3: None
Changes in v2: None
tools/imx8mimage.c | 1 - 1 file changed, 1 deletion(-)
tools/imx8mimage.c +0 -1
@@ -341,7 +341,6 @@ static int generate_ivt_for_fit(int fd, int fit_offset, uint32_t ep, } fit_size =fdt_totalsize (&image_header); - fit_size = (fit_size +3 ) & ~3 ; fit_size =ALIGN (fit_size,ALIGN_SIZE );
Signature · 1 line
2.17.1
PATCH v3 5/8 tools: imx8mimage: remove redundant code
Quoted 4 lines · Kever Yang
The align for
fit_sizehas been done twice, remove the first one for it does not make any sense.Signed-off-by Kever Yang <[email protected]>
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 659 bytes Desc: not available URL: <https://lists.denx.de/pipermail/u-boot/attachments/20200327/3c3fac6d/attachment.sig>
PATCH v3 6/8 tool: use ALIGN() to align the size
In reply to Kever YangUse the ALIGN() for size align so that the code is more readable.
---
Changes in v3: None
Changes in v2: None
tools/fit_image.c | 2 +- tools/socfpgaimage.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
tools/fit_image.c +1 -1
@@ -540,7 +540,7 @@ static int fit_import_data(struct image_tool_params *params, const char *fname)if (fd <0 )return -EIO ; fit_size =fdt_totalsize (old_fdt); - data_base = (fit_size +3 ) & ~3 ; + data_base =ALIGN (fit_size,4 );/* Allocate space to hold the new FIT */ size = sbuf.st_size +16384 ;
tools/socfpgaimage.c +1 -1
@@ -203,7 +203,7 @@ static int sfp_sign_buffer(uint8_t *buf, uint8_t ver, uint8_t flags,uint32_t calc_crc;/* Align the length up */ - len = (len +3 ) & ~3 ; + len =ALIGN (len,4 );/* Build header, adding 4 bytes to length to hold the CRC32. */ sfp_build_header (buf +HEADER_OFFSET , ver, flags, len +4 );
Signature · 1 line
2.17.1
PATCH v3 6/8 tool: use ALIGN() to align the size
Quoted 3 lines · Kever Yang
Use the
ALIGN()for size align so that the code is more readable.Signed-off-by Kever Yang <[email protected]>
Quoted 36 lines
---
Changes in v3: None
Changes in v2: Nonetools/fit_image.c | 2 +- tools/socfpgaimage.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)tools/fit_image.c +1
-1@@ -540,7 +540,7 @@ static int fit_import_data(struct image_tool_params *params, const char *fname)if (fd <0 )return -EIO ; fit_size =fdt_totalsize (old_fdt); - data_base = (fit_size +3 ) & ~3 ; + data_base =ALIGN (fit_size,4 );/* Allocate space to hold the new FIT */ size = sbuf.st_size +16384 ;tools/socfpgaimage.c +1
-1@@ -203,7 +203,7 @@ static int sfp_sign_buffer(uint8_t *buf, uint8_t ver, uint8_t flags,uint32_t calc_crc;/* Align the length up */ - len = (len +3 ) & ~3 ; + len =ALIGN (len,4 );/* Build header, adding 4 bytes to length to hold the CRC32. */ sfp_build_header (buf +HEADER_OFFSET , ver, flags, len +4 );
PATCH v3 6/8 tool: use ALIGN() to align the size
In reply to Kever YangQuoted 3 lines · Kever Yang
Use the
ALIGN()for size align so that the code is more readable.Signed-off-by Kever Yang <[email protected]>
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 659 bytes Desc: not available URL: <https://lists.denx.de/pipermail/u-boot/attachments/20200327/1f35add1/attachment.sig>
PATCH v3 7/8 libfdt: Make fdtdec_get_child_count() available for HOST
In reply to Kever YangThe tool need to use fdtdec_get_child_count(), make it available for HOST_CC.
---
Changes in v3: None
Changes in v2: None
include/fdt_support.h | 1 + lib/fdtdec.c | 11 ----------- lib/fdtdec_common.c | 11 +++++++++++ 3 files changed, 12 insertions(+), 11 deletions(-)
include/fdt_support.h +1 -0
@@ -329,6 +329,7 @@ int fdt_get_cells_len(const void *blob, char *nr_cells_name);#ifdef USE_HOSTCC int fdtdec_get_int (const void *blob,int node,const char *prop_name,int default_val); +int fdtdec_get_child_count (const void *blob,int node);#endif #ifdef CONFIG_FMAN_ENET int fdt_update_ethernet_dt (void *blob);
lib/fdtdec.c +0 -11
@@ -807,17 +807,6 @@ int fdtdec_parse_phandle_with_args(const void *blob, int src_node,return rc; } -int fdtdec_get_child_count (const void *blob,int node) -{ -int subnode; -int num =0 ; - -fdt_for_each_subnode (subnode, blob, node) - num++; - -return num; -} -int fdtdec_get_byte_array (const void *blob,int node,const char *prop_name,u8 *array,int count) {
lib/fdtdec_common.c +11 -0
@@ -53,3 +53,14 @@ unsigned int fdtdec_get_uint(const void *blob, int node, const char *prop_name,debug ("(not found)\n" );return default_val; } + +int fdtdec_get_child_count (const void *blob,int node) +{ +int subnode; +int num =0 ; + +fdt_for_each_subnode (subnode, blob, node) + num++; + +return num; +}
Signature · 1 line
2.17.1
PATCH v3 7/8 libfdt: Make fdtdec_get_child_count() available for HOST
Hi Kever,
Quoted 20 lines · Kever Yang
The tool need to use
fdtdec_get_child_count(), make it available forHOST_CC.Signed-off-by Kever Yang <[email protected]>---
Changes in v3: None
Changes in v2: Noneinclude/fdt_support.h | 1 + lib/fdtdec.c | 11 ----------- lib/fdtdec_common.c | 11 +++++++++++ 3 files changed, 12 insertions(+), 11 deletions(-)include/fdt_support.h +0
-0
include/fdt_support.h int fdt_get_cells_len(const void *blob, char *nr_cells_name); · line 332
Quoted 4 lines
include/fdt_support.h +1
-0@@ -329,6 +329,7 @@ int fdt_get_cells_len(const void *blob, char *nr_cells_name);#ifdef USE_HOSTCC int fdtdec_get_int (const void *blob,int node,const char *prop_name,int default_val); +int fdtdec_get_child_count (const void *blob,int node);
Please can you add a function comment for this?
Quoted 45 lines
include/fdt_support.h +0
-0#endif #ifdef CONFIG_FMAN_ENET int fdt_update_ethernet_dt (void *blob);lib/fdtdec.c +0
-11@@ -807,17 +807,6 @@ int fdtdec_parse_phandle_with_args(const void *blob, int src_node,return rc; } -int fdtdec_get_child_count (const void *blob,int node) -{ -int subnode; -int num =0 ; - -fdt_for_each_subnode (subnode, blob, node) - num++; - -return num; -} -int fdtdec_get_byte_array (const void *blob,int node,const char *prop_name,u8 *array,int count) {lib/fdtdec_common.c +11
-1@@ -53,3 +53,14 @@ unsigned int fdtdec_get_uint(const void *blob, int node, const char *prop_name,debug ("(not found)\n" );return default_val; } + +int fdtdec_get_child_count (const void *blob,int node) +{ +int subnode; +int num =0 ; + +fdt_for_each_subnode (subnode, blob, node) + num++; + +return num; +} --
Quoted 2 lines
2.17.1
Regards,
SImon
PATCH v3 8/8 mkimage: fit_image: Add option to make fit header align
In reply to Kever YangThe image is usually stored in block device like emmc, SD card, make the offset of image data aligned to block(512 byte) can avoid data copy during boot process.
eg. SPL boot from FIT image with external data:
- SPL read the first block of FIT image, and then parse the header;
- SPL read image data separately;
- The first image offset is the base_offset which is the header size;
- The second image offset is just after the first image;
- If the offset of imge does not aligned, SPL will do memcpy; The header size is a ramdon number, which is very possible not aligned, so add '-B' to specify the align size in hex for better performance.
example usage:
./tools/mkimage -E -f u-boot.its -B 200 u-boot.itb
---
Changes in v3:
- add common ALIGN() at imagetool.h
- migrate to use imagetool.h for all other files under tools/
Changes in v2:
- use '-B' to take a argument as a align block lenth;
- add new variable to indecate align_size
- address commens from Heinrich, Rasmus, Tom, Punit;
doc/uImage.FIT/source_file_format.txt | 5 ++++ tools/fit_image.c | 33 ++++++++++++++++----------- tools/imagetool.h | 1 + tools/mkimage.c | 14 ++++++++++-- 4 files changed, 38 insertions(+), 15 deletions(-)
doc/uImage.FIT/source_file_format.txt +5 -0
@@ -304,6 +304,11 @@ Normal kernel FIT image has data embedded within FIT structure. U-Boot image for SPL boot has external data. Existence of 'data-offset' can be used to identify which format is used. +For FIT image with external data, it would be better to align each blob of data +to block(512 byte) for block device, so that we don't need to do the copy when +read the image data in SPL. Pass '-B 200' to mkimage to align the FIT structure +and data to 512 byte or other value for other align size. + 9) Examples -----------
tools/fit_image.c +20 -13
@@ -415,7 +415,7 @@ err_buf:*/ static int fit_extract_data (struct image_tool_params *params,const char *fname) { -void *buf; +void *buf =NULL ;int buf_ptr;int fit_size, new_size;int fd;
@@ -424,26 +424,33 @@ static int fit_extract_data(struct image_tool_params *params, const char *fname)int ret;int images;int node; +int image_number; +int align_size; + align_size = params->bl_len ? params->bl_len :4 ; fd =mmap_fdt (params->cmdname, fname,0 , &fdt, &sbuf, false, false);if (fd <0 )return -EIO ; fit_size =fdt_totalsize (fdt); -/* Allocate space to hold the image data we will extract */ - buf =malloc (fit_size); -if (!buf) { - ret = -ENOMEM ; - goto err_munmap; - } - buf_ptr =0 ; - images =fdt_path_offset (fdt,FIT_IMAGES_PATH );if (images <0 ) {debug ("%s: Cannot find /images node: %d\n" , __func__, images); ret = -EINVAL ; goto err_munmap; } + image_number =fdtdec_get_child_count (fdt, images); + +/* +* Allocate space to hold the image data we will extract, +* extral space allocate for image alignment to prevent overflow. +*/ + buf =malloc (fit_size + (align_size * image_number)); +if (!buf) { + ret = -ENOMEM ; + goto err_munmap; + } + buf_ptr =0 ; for (node = fdt_first_subnode(fdt, images); node >= 0;
@@ -471,17 +478,17 @@ static int fit_extract_data(struct image_tool_params *params, const char *fname) buf_ptr); }fdt_setprop_u32 (fdt, node,FIT_DATA_SIZE_PROP , len); - - buf_ptr += (len +3 ) & ~3 ; + buf_ptr +=ALIGN (len, align_size); }/* Pack the FDT and place the data after it */ fdt_pack (fdt); + new_size =fdt_totalsize (fdt); + new_size =ALIGN (new_size, align_size); +fdt_set_totalsize (fdt, new_size);debug ("Size reduced from %x to %x\n" , fit_size,fdt_totalsize (fdt));debug ("External data size %x\n" , buf_ptr); - new_size =fdt_totalsize (fdt); - new_size = (new_size +3 ) & ~3 ;munmap (fdt, sbuf.st_size);if (ftruncate (fd, new_size)) {
tools/imagetool.h +1 -0
@@ -79,6 +79,7 @@ struct image_tool_params {bool external_data;/* Store data outside the FIT */ bool quiet;/* Don't output text in normal operation */ unsigned int external_offset;/* Add padding to external data */ +int bl_len;/* Block length in byte for external data */ const char *engine_id;/* Engine to use for signing */ };
tools/mkimage.c +12 -2
@@ -98,8 +98,9 @@ static void usage(const char *msg) " -i => input filename for ramdisk file\n");#ifdef CONFIG_FIT_SIGNATURE fprintf (stderr, -"Signing / verified boot options: [-E] [-k keydir] [-K dtb] [ -c <comment>] [-p addr] [-r] [-N engine]\n" +"Signing / verified boot options: [-E] [-B] [-k keydir] [-K dtb] [ -c <comment>] [-p addr] [-r] [-N engine]\n" " -E => place data outside of the FIT structure\n" +" -B => align FIT structure and header to block\n" " -k => set directory containing private keys\n" " -K => write public keys to this .dtb file\n" " -c => add comment in signature node\n"
@@ -144,7 +145,7 @@ static void process_args(int argc, char **argv)int opt;while ((opt =getopt (argc, argv, -"a:A:b:c:C:d:D:e:Ef:Fk:i:K:ln:N:p:O:rR:qsT:vVx" )) !=-1 ) { +"a:A:b:B:c:C:d:D:e:Ef:Fk:i:K:ln:N:p:O:rR:qsT:vVx" )) !=-1 ) {switch (opt) {case 'a' : params.addr =strtoull (optarg, &ptr,16 );
@@ -168,6 +169,15 @@ static void process_args(int argc, char **argv) params.cmdname, optarg);exit (EXIT_FAILURE ); } +break ; +case 'B' : + params.bl_len =strtoull (optarg, &ptr,16 ); +if (*ptr) { +fprintf (stderr,"%s: invalid block length %s\n" , + params.cmdname, optarg); +exit (EXIT_FAILURE ); + } +break ;case 'c' : params.comment = optarg;
Signature · 1 line
2.17.1
PATCH v3 8/8 mkimage: fit_image: Add option to make fit header align
Quoted 12 lines · Kever Yang
The image is usually stored in block device like emmc, SD card, make the offset of image data aligned to block(512 byte) can avoid data copy during boot process.
eg. SPL boot from FIT image with external data:
- SPL read the first block of FIT image, and then parse the header;
- SPL read image data separately;
- The first image offset is thebase_offsetwhich is the header size;
- The second image offset is just after the first image;
- If the offset of imge does not aligned, SPL will do memcpy; The header size is a ramdon number, which is very possible not aligned, so add '-B' to specify the align size in hex for better performance.
Quoted 2 lines
example usage:
./tools/mkimage-E -f u-boot.its -B 200 u-boot.itb
OK, so we're taking a hex input, and that's not clear in the documentation. The example should also be 0x200 for clarity. In fact, being user-space, we need to make this user friendly and sanity check the input and if we're going to take hex in, enforce '0x' as a prefix even I think. Thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 659 bytes Desc: not available URL: <https://lists.denx.de/pipermail/u-boot/attachments/20200327/44876c39/attachment.sig>
PATCH v3 8/8 mkimage: fit_image: Add option to make fit header align
Hi Tom,
Quoted 14 lines · Tom Rini
Quoted 12 lines · Kever Yang
The image is usually stored in block device like emmc, SD card, make the offset of image data aligned to block(512 byte) can avoid data copy during boot process.
eg. SPL boot from FIT image with external data:
- SPL read the first block of FIT image, and then parse the header;
- SPL read image data separately;
- The first image offset is thebase_offsetwhich is the header size;
- The second image offset is just after the first image;
- If the offset of imge does not aligned, SPL will do memcpy; The header size is a ramdon number, which is very possible not aligned, so add '-B' to specify the align size in hex for better performance.
Quoted 7 lines
Quoted 2 lines
example usage:
./tools/mkimage -E -f u-boot.its -B 200 u-boot.itbOK, so we're taking a hex input, and that's not clear in the documentation. The example should also be
0x200for clarity. In fact, being user-space, we need to make this user friendly and sanity check the input and if we're going to take hex in, enforce '0x' as a prefix even I think. Thanks!
I use hex input because all of other parameters for mkimage tool are using
hex format instead of decimal format.
I will update ot use 0x200.
Thanks,
- Kever
Quoted 1 line
PATCH v3 1/8 tool: Move ALIGN_MASK to header as common MACRO
In reply to Kever YangHi Kever,
Quoted 4 lines · Kever Yang
The ALIGN code is need by many files who need handle structure or image align, so move the macro to
imagetool.hfile.Signed-off-by Kever Yang <[email protected]>
Thanks for updating the patches.
For the series -
Thanks,
Punit
Quoted 93 lines
---
Changes in v3: None
Changes in v2: Noneinclude/imx8image.h | 1 - tools/ifwitool.c | 4 +--- tools/imagetool.h | 3 +++ tools/imx8mimage.c | 2 -- tools/mksunxiboot.c | 4 +--- 5 files changed, 5 insertions(+), 9 deletions(-)include/imx8image.h +0
-1@@ -11,7 +11,6 @@#include <image.h> #include <inttypes.h> #include "imagetool.h" -#include "linux/kernel.h" #define __packed __attribute__((packed))tools/ifwitool.c +1
-3@@ -8,15 +8,13 @@#include <assert.h> #include <stdbool.h> #include <getopt.h> +#include "imagetool.h" #include "os_support.h" #ifndef __packed#define __packed __attribute__((packed))#endif #define KiB 1024 -#define ALIGN (x, a) __ALIGN_MASK((x), (typeof(x))(a) - 1) -#define __ALIGN_MASK (x, mask) (((x) + (mask)) & ~(mask)) -#define ARRAY_SIZE (x) (sizeof(x) / sizeof((x)[0]))/* * min()/max()/clamp() macros that also do tools/imagetool.h +3
-0@@ -25,6 +25,9 @@#define ARRAY_SIZE (x) (sizeof(x) / sizeof((x)[0])) +#define __ALIGN_MASK (x, mask) (((x) + (mask)) & ~(mask)) +#define ALIGN (x, a) __ALIGN_MASK((x), (typeof(x))(a) - 1) +#define IH_ARCH_DEFAULT IH_ARCH_INVALID/* Information about a file that needs to be placed into the FIT */ tools/imx8mimage.c +0
-2@@ -32,8 +32,6 @@ static uint32_t rom_version = ROM_V1;#define HDMI_FW_SIZE 0x17000/* Use Last 0x1000 for IVT and CSF */ #define ALIGN_SIZE 0x1000 -#define ALIGN (x,a) __ALIGN_MASK((x), (__typeof__(x))(a) - 1, a) -#define __ALIGN_MASK (x,mask,mask2) (((x) + (mask)) / (mask2) * (mask2))static uint32_t get_cfg_value (char *token,char *name,int linenr) {tools/mksunxiboot.c +1
-3@@ -14,6 +14,7 @@#include <errno.h> #include <sys/types.h> #include <sys/stat.h> +#include "imagetool.h" #include "../arch/arm/include/asm/arch-sunxi/spl.h" #define STAMP_VALUE 0x5F0A6C39@@ -44,9 +45,6 @@ int gen_check_sum(struct boot_file_head *head_p)return 0 ; } -#define ALIGN (x, a) __ALIGN_MASK((x), (typeof(x))(a)-1) -#define __ALIGN_MASK (x, mask) (((x)+(mask))&~(mask)) -#define SUNXI_SRAM_SIZE 0x8000/* SoC with smaller size are limited before */ #define SRAM_LOAD_MAX_SIZE (SUNXI_SRAM_SIZE - sizeof(struct boot_file_head))
PATCH v3 1/8 tool: Move ALIGN_MASK to header as common MACRO
In reply to Kever YangQuoted 4 lines · Kever Yang
The ALIGN code is need by many files who need handle structure or image align, so move the macro to
imagetool.hfile.Signed-off-by Kever Yang <[email protected]>
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 659 bytes Desc: not available URL: <https://lists.denx.de/pipermail/u-boot/attachments/20200327/fe07eb19/attachment.sig>