scripts: fix_size: check magic
Instead of passing the offset to the fix_size tool check the image to fixup for a valid header so that only recognized files are fixed up. This makes the usage of this tool safer. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
This commit is contained in:
parent
2af8bdd369
commit
e3ed260db7
|
@ -23,7 +23,7 @@ $(obj)/zbarebox.bin: $(obj)/zbarebox FORCE
|
||||||
$(call if_changed,objcopy)
|
$(call if_changed,objcopy)
|
||||||
$(call cmd,check_file_size,$(CONFIG_BAREBOX_MAX_IMAGE_SIZE))
|
$(call cmd,check_file_size,$(CONFIG_BAREBOX_MAX_IMAGE_SIZE))
|
||||||
$(Q)$(kecho) ' Barebox: fix size'
|
$(Q)$(kecho) ' Barebox: fix size'
|
||||||
$(Q)$(objtree)/scripts/fix_size -f $(objtree)/$@ -o 0x2c $(FIX_SIZE)
|
$(Q)$(objtree)/scripts/fix_size -i -f $(objtree)/$@ $(FIX_SIZE)
|
||||||
$(Q)$(kecho) ' Barebox: $@ is ready'
|
$(Q)$(kecho) ' Barebox: $@ is ready'
|
||||||
|
|
||||||
$(obj)/zbarebox.S: $(obj)/zbarebox FORCE
|
$(obj)/zbarebox.S: $(obj)/zbarebox FORCE
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
|
@ -15,23 +16,24 @@ int main(int argc, char**argv)
|
||||||
struct stat s;
|
struct stat s;
|
||||||
int c;
|
int c;
|
||||||
int fd;
|
int fd;
|
||||||
uint64_t offset = 0;
|
|
||||||
uint32_t size = 0;
|
uint32_t size = 0;
|
||||||
char *file = NULL;
|
char *file = NULL;
|
||||||
int ret = 1;
|
int ret = 1;
|
||||||
int is_bigendian = 0;
|
int is_bigendian = 0;
|
||||||
|
char magic[8];
|
||||||
|
int ignore_unknown = 0;
|
||||||
|
|
||||||
while ((c = getopt (argc, argv, "hf:o:b")) != -1) {
|
while ((c = getopt (argc, argv, "if:b")) != -1) {
|
||||||
switch (c) {
|
switch (c) {
|
||||||
case 'f':
|
case 'f':
|
||||||
file = optarg;
|
file = optarg;
|
||||||
break;
|
break;
|
||||||
case 'o':
|
|
||||||
offset = strtoul(optarg, NULL, 16);
|
|
||||||
break;
|
|
||||||
case 'b':
|
case 'b':
|
||||||
is_bigendian = 1;
|
is_bigendian = 1;
|
||||||
break;
|
break;
|
||||||
|
case 'i':
|
||||||
|
ignore_unknown = 1;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -45,13 +47,36 @@ int main(int argc, char**argv)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
fd = open(file, O_WRONLY);
|
fd = open(file, O_RDWR);
|
||||||
if (fd < 0) {
|
if (fd < 0) {
|
||||||
perror("open");
|
perror("open");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = lseek(fd, offset, SEEK_SET);
|
ret = lseek(fd, 0x20, SEEK_SET);
|
||||||
|
if (ret < 0) {
|
||||||
|
perror("lseek");
|
||||||
|
ret = 1;
|
||||||
|
goto err;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = read(fd, magic, sizeof(magic));
|
||||||
|
if (ret < 0) {
|
||||||
|
perror("read");
|
||||||
|
ret = 1;
|
||||||
|
goto err;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (strcmp(magic, "barebox")) {
|
||||||
|
fprintf(stderr, "invalid magic\n");
|
||||||
|
if (ignore_unknown)
|
||||||
|
ret = 0;
|
||||||
|
else
|
||||||
|
ret = 1;
|
||||||
|
goto err;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = lseek(fd, 0x2c, SEEK_SET);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
perror("lseek");
|
perror("lseek");
|
||||||
ret = 1;
|
ret = 1;
|
||||||
|
|
Loading…
Reference in New Issue