Skip to content

Commit

Permalink
Merge pull request #241 from ukleinek/rauc-offset
Browse files Browse the repository at this point in the history
image-rauc: allow to specify an offset to skip input bytes
  • Loading branch information
michaelolbrich authored Mar 22, 2024
2 parents fbad79c + 8276468 commit 915ced7
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 6 deletions.
1 change: 1 addition & 0 deletions genimage.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ struct partition {
cfg_bool_t no_automount;
cfg_bool_t fill;
const char *image;
off_t imageoffset;
struct list_head list;
int autoresize;
int in_partition_table;
Expand Down
36 changes: 32 additions & 4 deletions image-rauc.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <string.h>
#include <stdlib.h>
#include <errno.h>
#include <unistd.h>

#include "genimage.h"

Expand Down Expand Up @@ -68,6 +69,7 @@ static int rauc_generate(struct image *image)
struct image *child = image_get(part->image);
const char *file = imageoutfile(child);
const char *target = part->name;
char *tmptarget;
char *path, *tmp;

if (part->partition_type == RAUC_CERT)
Expand Down Expand Up @@ -105,10 +107,34 @@ static int rauc_generate(struct image *image)
goto out;
}

image_info(image, "adding file '%s' as '%s' ...\n",
child->file, target);
ret = systemp(image, "cp --remove-destination '%s' '%s/%s'",
file, tmpdir, target);
xasprintf(&tmptarget, "%s/%s", tmpdir, target);

image_info(image, "adding file '%s' as '%s' (offset=%lld)...\n",
child->file, target, (long long)part->imageoffset);

if (part->imageoffset) {
unlink(tmptarget);

/*
* Starting with coreutils 9.1 you can use a 'B' suffix for
* skip=N instead of iflag=skip_bytes to have N count bytes, not
* (input) blocks.
*
* Note that dd doesn't behave as optimal as cp in the
* else branch below because it doesn't preserve holes.
* To improve here insert_image() should be extended to
* support part->imageoffset != 0 and then it can
* replace both commands.
*/
ret = systemp(image, "dd if='%s' of='%s' iflag=skip_bytes skip=%lld",
file, tmptarget, (long long)part->imageoffset);

} else {
ret = systemp(image, "cp --remove-destination '%s' '%s'",
file, tmptarget);
}

free(tmptarget);
if (ret)
goto out;
}
Expand Down Expand Up @@ -193,6 +219,7 @@ static int rauc_parse(struct image *image, cfg_t *cfg)
part = xzalloc(sizeof *part);
part->name = cfg_title(filesec);
part->image = cfg_getstr(filesec, "image");
part->imageoffset = cfg_getint_suffix(filesec, "offset");
part->partition_type = RAUC_CONTENT;
list_add_tail(&part->list, &image->partitions);
}
Expand All @@ -219,6 +246,7 @@ static int rauc_setup(struct image *image, cfg_t *cfg)

static cfg_opt_t file_opts[] = {
CFG_STR("image", NULL, CFGF_NONE),
CFG_STR("offset", "0", CFGF_NONE),
CFG_END()
};

Expand Down
2 changes: 1 addition & 1 deletion test/misc.test
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ setup_rauc() {
mkdir input &&
cp -r "${testdir}"/rauc-openssl-ca input/ &&
echo "test" > input/rauc.content &&
echo "test2" > input/rauc2.content
echo "xtest2" > input/rauc2.content
}

exec_test_set_prereq rauc
Expand Down
5 changes: 4 additions & 1 deletion test/rauc.config
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ image test.raucb {
}
image test2.raucb {
rauc {
file data { image = "rauc2.content" }
file data {
image = "rauc2.content"
offset = 1
}
manifest = "
[update]
compatible=genimage-test
Expand Down

0 comments on commit 915ced7

Please sign in to comment.