Skip to content
Snippets Groups Projects
Commit d55c74de authored by Kenneth Johansson's avatar Kenneth Johansson
Browse files

generalize header matching.

This matches any header not just the board name.
parent 31de0014
No related branches found
No related tags found
No related merge requests found
...@@ -28,7 +28,7 @@ calls iopupgrade. ...@@ -28,7 +28,7 @@ calls iopupgrade.
./iopupgrade [OPTION].. ./iopupgrade [OPTION]..
Options: Options:
-f, --file=NAME image file to use. If not specified stdin is used. -f, --file=NAME image file to use. If not specified stdin is used.
-b, --board=name name of the board -M, --match=key=val,.... image headers needs to have this value
-q, --force do not do board name check -q, --force do not do board name check
-u, --ubivol=NAME UBI volume device file to write rootfs to. -u, --ubivol=NAME UBI volume device file to write rootfs to.
-U, --ubifs=NAME Extract ubifs image to file. -U, --ubifs=NAME Extract ubifs image to file.
...@@ -54,7 +54,7 @@ Options: ...@@ -54,7 +54,7 @@ Options:
|----|-------| |----|-------|
|Help|`iopupgrade -h`| |Help|`iopupgrade -h`|
|Print headers|`iopupgrade -f last.y3 -p`| |Print headers|`iopupgrade -f last.y3 -p`|
|match board name|`iopupgrade -f last.y3 -M "board=DG400,dsl=A" `|
### Broadcom target related examples ### ### Broadcom target related examples ###
|task|command| |task|command|
......
...@@ -27,41 +27,119 @@ ...@@ -27,41 +27,119 @@
#include "consumer.h" #include "consumer.h"
#include "cmd.h" #include "cmd.h"
static char *board;
static int force; static int force;
#define MAX_KEYS 20
static char * key_name[MAX_KEYS];
static char * key_value[MAX_KEYS];
static int keys;
static int init(struct img_header *hdr) static int init(struct img_header *hdr)
{ {
char *p; char *p;
int index;
/* skip snity check ? */ /* skip snity check ? */
if (force) return 0; if (force) return 0;
if (!board){ /* Loop over all headers and compare values */
fprintf(stderr, "Board name needs to be given with -b or to skip test give -q (unsafe)\n"); for(index=0; index<keys; index++) {
exit(EXIT_FAILURE); p = get_str_val(hdr, key_name[index]);
if (p == NULL){
fprintf(stderr, "Could not find header [%s] in y3 image\n",key_name[index]);
fprintf(stderr, "To skip test give -q (unsafe)\n");
exit(EXIT_FAILURE);
}
if (strcmp(p,key_value[index])){
fprintf(stderr, "Wrong value of header [%s] in y3 image, got [%s] wanted [%s]\n",
key_name[index],p,key_value[index]);
fprintf(stderr, "To skip test give -q (unsafe)\n");
exit(EXIT_FAILURE);
}
}
return 0;
}
static void usage(void)
{
printf(" -M, --match=key=val,.... image headers needs to have this value\n");
printf(" -q, --force\tdo not do header check\n");
}
static void parse_match(char *s)
{
int tot_len= strlen(s);
int index=0;
char *p=s,tmp;
/* find number of keys = 1 + number of , chars in string */
keys = 1;
for (int i=0; i<tot_len; i++){
if (',' == s[i] )
keys++;
} }
p = get_str_val(hdr, "board"); if (keys > MAX_KEYS ) {
fprintf(stderr, "To many header values to match, max %d allowed wanted %d\n", MAX_KEYS, keys);
exit (EXIT_FAILURE);
}
if (p) { while (1){
if (0 == strncmp(p, board,strlen(board))){ char *e;
return 0; char *c;
}else {
fprintf(stderr, "Board header not matching board name \n"); /* copy key to index */
fprintf(stderr, "header [%s] but wanted [%s]\n",p,board); e = strstr(p, "=");
c = strstr(p, ",");
if (e == NULL) {
if (c) {
fprintf(stderr, "Header match error: expected = found , instread\n");
goto error_print;
}else
break;
fprintf(stderr, "Header match error: expected = found end of string\n");
goto error_print;
} else if ( c != NULL && e > c) {
fprintf(stderr, "Header match error: Found , before = . missing a = ??\n");
goto error_print;
} }
} else tmp=*e;*e=0;
fprintf(stderr, "Board header not found in image data. Aborting!\n"); key_name[index] = strdup(p);
*e=tmp;
exit(EXIT_FAILURE); /* copy value */
return 1; p=e+1;
} e = strstr(p, "=");
c = strstr(p, ",");
static void usage(void) /* last value ?*/
{ if (c == NULL ) {
printf(" -b, --board=name\tname of the board\n"); key_value[index] = strdup(p);
printf(" -q, --force\tdo not do board name check\n"); index++;
break;
}
tmp=*c;*c=0;
key_value[index] = strdup(p);
*c=tmp;
p=c+1;
index++;
}
keys=index;
#if 0
for (int i=0; i<keys;i++){
printf("%s=%s\n",key_name[i],key_value[i]);
}
#endif
return;
error_print:
fprintf(stderr, "Trying to parse string [%s]\n",s);
exit (EXIT_FAILURE);
} }
static void opt( int argc, char **argv) static void opt( int argc, char **argv)
...@@ -71,19 +149,19 @@ static void opt( int argc, char **argv) ...@@ -71,19 +149,19 @@ static void opt( int argc, char **argv)
while (1) { while (1) {
int option_index = 0; int option_index = 0;
static struct option long_options[] = { static struct option long_options[] = {
{"board", required_argument, 0, 'b'}, {"match", required_argument, 0, 'M'},
{"force", no_argument, 0, 'q'}, {"force", no_argument, 0, 'q'},
{0, 0, 0, 0} {0, 0, 0, 0}
}; };
ch = getopt_long(argc, argv, "b:q", ch = getopt_long(argc, argv, "M:q",
long_options, &option_index); long_options, &option_index);
if (ch == -1) if (ch == -1)
break; break;
switch (ch) { switch (ch) {
case 'b': case 'M':
board = optarg; parse_match(optarg);
break; break;
case 'q': case 'q':
force = 1; force = 1;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment