aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPali Rohár <pali@kernel.org>2023-01-21 20:11:28 +0100
committerStefan Roese <sr@denx.de>2023-03-01 06:39:17 +0100
commit3a521f08677914821479647008d488bb4f15b17a (patch)
tree72586b25d1c743a0bf37838b27411b1e9dc072d6
parentb07965b8a9a9887a37f41254d6155f8fc38ad006 (diff)
downloadu-boot-3a521f08677914821479647008d488bb4f15b17a.zip
u-boot-3a521f08677914821479647008d488bb4f15b17a.tar.gz
u-boot-3a521f08677914821479647008d488bb4f15b17a.tar.bz2
tools: kwbimage: Add support for creating an image with no data
This change add support for mkimage's -s option to kwbimage format. It will create an kwbimage with empty data part of image (data part would contain only required 32-bit checksum). mkimage's -s option is indicated by skipcpy flag and it is basically in conflict with mkimage's -d (datafile) option. "Empty" kwbimage with no data can still contain headers. For example it can contain binary executable header which is copied by BootROM into L2SRAM. This is useful for example for small images which can do not require DDR RAM and can be run in L2SRAM (which do not require any initialization). Signed-off-by: Pali Rohár <pali@kernel.org>
-rw-r--r--tools/kwbimage.c28
1 files changed, 25 insertions, 3 deletions
diff --git a/tools/kwbimage.c b/tools/kwbimage.c
index 7ebb625..309657a 100644
--- a/tools/kwbimage.c
+++ b/tools/kwbimage.c
@@ -1887,7 +1887,9 @@ static void kwbimage_set_header(void *ptr, struct stat *sbuf, int ifd,
* Do not use sbuf->st_size as it contains size with padding.
* We need original image data size, so stat original file.
*/
- if (stat(params->datafile, &s)) {
+ if (params->skipcpy) {
+ s.st_size = 0;
+ } else if (stat(params->datafile, &s)) {
fprintf(stderr, "Could not stat data file %s: %s\n",
params->datafile, strerror(errno));
exit(EXIT_FAILURE);
@@ -2106,6 +2108,8 @@ static int kwbimage_verify_header(unsigned char *ptr, int image_size,
return 0;
}
+static int kwbimage_align_size(int bootfrom, int alloc_len, struct stat s);
+
static int kwbimage_generate(struct image_tool_params *params,
struct image_type_params *tparams)
{
@@ -2124,7 +2128,9 @@ static int kwbimage_generate(struct image_tool_params *params,
exit(EXIT_FAILURE);
}
- if (stat(params->datafile, &s)) {
+ if (params->skipcpy) {
+ s.st_size = 0;
+ } else if (stat(params->datafile, &s)) {
fprintf(stderr, "Could not stat data file %s: %s\n",
params->datafile, strerror(errno));
exit(EXIT_FAILURE);
@@ -2196,6 +2202,22 @@ static int kwbimage_generate(struct image_tool_params *params,
tparams->hdr = hdr;
/*
+ * This function should return aligned size of the datafile.
+ * When skipcpy is set (datafile is skipped) then return value of this
+ * function is ignored, so we have to put required kwbimage aligning
+ * into the preallocated header size.
+ */
+ if (params->skipcpy) {
+ tparams->header_size += kwbimage_align_size(bootfrom, alloc_len, s);
+ return 0;
+ } else {
+ return kwbimage_align_size(bootfrom, alloc_len, s);
+ }
+}
+
+static int kwbimage_align_size(int bootfrom, int alloc_len, struct stat s)
+{
+ /*
* 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.
@@ -2510,7 +2532,7 @@ static int kwbimage_check_params(struct image_tool_params *params)
return 1;
}
- return (params->dflag && (params->fflag || params->lflag)) ||
+ return (params->dflag && (params->fflag || params->lflag || params->skipcpy)) ||
(params->fflag) ||
(params->lflag && (params->dflag || params->fflag));
}