Skip to content

Commit 8276468

Browse files
author
Uwe Kleine-König
committed
image-rauc: allow to specify an offset to skip input bytes
This is useful for barebox images on (at least) i.MX8 to be written to eMMC. There the first 32K of the image must be skipped. Signed-off-by: Uwe Kleine-König <[email protected]>
1 parent fbad79c commit 8276468

File tree

4 files changed

+38
-6
lines changed

4 files changed

+38
-6
lines changed

genimage.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ struct partition {
4545
cfg_bool_t no_automount;
4646
cfg_bool_t fill;
4747
const char *image;
48+
off_t imageoffset;
4849
struct list_head list;
4950
int autoresize;
5051
int in_partition_table;

image-rauc.c

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <string.h>
2020
#include <stdlib.h>
2121
#include <errno.h>
22+
#include <unistd.h>
2223

2324
#include "genimage.h"
2425

@@ -68,6 +69,7 @@ static int rauc_generate(struct image *image)
6869
struct image *child = image_get(part->image);
6970
const char *file = imageoutfile(child);
7071
const char *target = part->name;
72+
char *tmptarget;
7173
char *path, *tmp;
7274

7375
if (part->partition_type == RAUC_CERT)
@@ -105,10 +107,34 @@ static int rauc_generate(struct image *image)
105107
goto out;
106108
}
107109

108-
image_info(image, "adding file '%s' as '%s' ...\n",
109-
child->file, target);
110-
ret = systemp(image, "cp --remove-destination '%s' '%s/%s'",
111-
file, tmpdir, target);
110+
xasprintf(&tmptarget, "%s/%s", tmpdir, target);
111+
112+
image_info(image, "adding file '%s' as '%s' (offset=%lld)...\n",
113+
child->file, target, (long long)part->imageoffset);
114+
115+
if (part->imageoffset) {
116+
unlink(tmptarget);
117+
118+
/*
119+
* Starting with coreutils 9.1 you can use a 'B' suffix for
120+
* skip=N instead of iflag=skip_bytes to have N count bytes, not
121+
* (input) blocks.
122+
*
123+
* Note that dd doesn't behave as optimal as cp in the
124+
* else branch below because it doesn't preserve holes.
125+
* To improve here insert_image() should be extended to
126+
* support part->imageoffset != 0 and then it can
127+
* replace both commands.
128+
*/
129+
ret = systemp(image, "dd if='%s' of='%s' iflag=skip_bytes skip=%lld",
130+
file, tmptarget, (long long)part->imageoffset);
131+
132+
} else {
133+
ret = systemp(image, "cp --remove-destination '%s' '%s'",
134+
file, tmptarget);
135+
}
136+
137+
free(tmptarget);
112138
if (ret)
113139
goto out;
114140
}
@@ -193,6 +219,7 @@ static int rauc_parse(struct image *image, cfg_t *cfg)
193219
part = xzalloc(sizeof *part);
194220
part->name = cfg_title(filesec);
195221
part->image = cfg_getstr(filesec, "image");
222+
part->imageoffset = cfg_getint_suffix(filesec, "offset");
196223
part->partition_type = RAUC_CONTENT;
197224
list_add_tail(&part->list, &image->partitions);
198225
}
@@ -219,6 +246,7 @@ static int rauc_setup(struct image *image, cfg_t *cfg)
219246

220247
static cfg_opt_t file_opts[] = {
221248
CFG_STR("image", NULL, CFGF_NONE),
249+
CFG_STR("offset", "0", CFGF_NONE),
222250
CFG_END()
223251
};
224252

test/misc.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ setup_rauc() {
3131
mkdir input &&
3232
cp -r "${testdir}"/rauc-openssl-ca input/ &&
3333
echo "test" > input/rauc.content &&
34-
echo "test2" > input/rauc2.content
34+
echo "xtest2" > input/rauc2.content
3535
}
3636

3737
exec_test_set_prereq rauc

test/rauc.config

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@ image test.raucb {
1818
}
1919
image test2.raucb {
2020
rauc {
21-
file data { image = "rauc2.content" }
21+
file data {
22+
image = "rauc2.content"
23+
offset = 1
24+
}
2225
manifest = "
2326
[update]
2427
compatible=genimage-test

0 commit comments

Comments
 (0)