summaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorThomas Petazzoni <thomas.petazzoni@free-electrons.com>2013-05-15 09:36:28 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2013-05-17 07:39:51 +0200
commitd60819c62691a40c23b97d1bdf2da428af40544d (patch)
treecaf10b2394511d3aeeeaa219511719b3fe3e272c /scripts
parent87f6faa4508c8e66a828ccf425663375ca681017 (diff)
downloadbarebox-d60819c62691a40c23b97d1bdf2da428af40544d.tar.gz
barebox-d60819c62691a40c23b97d1bdf2da428af40544d.tar.xz
scripts/kwbimage: add a few sanity checks
This commit uses the newly introduced image_count_options() function to: - See if there is any DATA option that require the creation of an extended header for v0 header. - Verify that no more than one payload has been provided when creating a v0 header. - Verify that no more than one binary payload has been provided when creating a v1 header. Technically speaking, it is possible to support several payloads, but in real life, only one gets used, so we will only support that to make the code simpler for now. It can always be extended later on if needed. - Verify that no more than one payload has been provided when creating a v1 header. Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com> Tested-by: Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'scripts')
-rw-r--r--scripts/kwbimage.c18
1 files changed, 16 insertions, 2 deletions
diff --git a/scripts/kwbimage.c b/scripts/kwbimage.c
index 0d5dcac31e..cca20abdcd 100644
--- a/scripts/kwbimage.c
+++ b/scripts/kwbimage.c
@@ -712,12 +712,16 @@ static void *image_create_v0(struct image_cfg_element *image_cfg,
headersz = sizeof(struct main_hdr_v0);
payloadsz = 0;
- e = image_find_option(image_cfg, cfgn, IMAGE_CFG_DATA);
- if (e) {
+ if (image_count_options(image_cfg, cfgn, IMAGE_CFG_DATA) > 0) {
has_ext = 1;
headersz += sizeof(struct ext_hdr_v0);
}
+ if (image_count_options(image_cfg, cfgn, IMAGE_CFG_PAYLOAD) > 1) {
+ fprintf(stderr, "More than one payload, not possible\n");
+ return NULL;
+ }
+
payloade = image_find_option(image_cfg, cfgn, IMAGE_CFG_PAYLOAD);
if (payloade) {
struct stat s;
@@ -818,6 +822,16 @@ static void *image_create_v1(struct image_cfg_element *image_cfg,
headersz = sizeof(struct main_hdr_v1);
payloadsz = 0;
+ if (image_count_options(image_cfg, cfgn, IMAGE_CFG_BINARY) > 1) {
+ fprintf(stderr, "More than one binary blob, not supported\n");
+ return NULL;
+ }
+
+ if (image_count_options(image_cfg, cfgn, IMAGE_CFG_PAYLOAD) > 1) {
+ fprintf(stderr, "More than one payload, not possible\n");
+ return NULL;
+ }
+
e = image_find_option(image_cfg, cfgn, IMAGE_CFG_BINARY);
if (e) {
struct stat s;