firmware-utils/mkcameofw: allow to use combined kernel image
Signed-off-by: Gabor Juhos <juhosg@openwrt.org> SVN-Revision: 36583
This commit is contained in:
parent
f938a798f8
commit
3a407a0986
1 changed files with 56 additions and 28 deletions
|
@ -61,6 +61,7 @@ static struct file_info kernel_info;
|
||||||
static struct file_info rootfs_info;
|
static struct file_info rootfs_info;
|
||||||
static uint32_t kernel_size;
|
static uint32_t kernel_size;
|
||||||
static uint32_t image_size;
|
static uint32_t image_size;
|
||||||
|
static int combined;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Message macros
|
* Message macros
|
||||||
|
@ -91,6 +92,7 @@ static void usage(int status)
|
||||||
"\n"
|
"\n"
|
||||||
"Options:\n"
|
"Options:\n"
|
||||||
" -k <file> read kernel image from the file <file>\n"
|
" -k <file> read kernel image from the file <file>\n"
|
||||||
|
" -c use the kernel image as a combined image\n"
|
||||||
" -M <model> set model to <model>\n"
|
" -M <model> set model to <model>\n"
|
||||||
" -o <file> write output to the file <file>\n"
|
" -o <file> write output to the file <file>\n"
|
||||||
" -r <file> read rootfs image from the file <file>\n"
|
" -r <file> read rootfs image from the file <file>\n"
|
||||||
|
@ -196,12 +198,29 @@ static int check_options(void)
|
||||||
CHKSTRLEN(version, "version");
|
CHKSTRLEN(version, "version");
|
||||||
CHKSTR(ofname, "output file");
|
CHKSTR(ofname, "output file");
|
||||||
CHKSTR(kernel_info.file_name, "kernel image");
|
CHKSTR(kernel_info.file_name, "kernel image");
|
||||||
CHKSTR(rootfs_info.file_name, "rootfs image");
|
|
||||||
|
|
||||||
ret = get_file_stat(&kernel_info);
|
ret = get_file_stat(&kernel_info);
|
||||||
if (ret)
|
if (ret)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
|
if (combined) {
|
||||||
|
if (!kernel_size) {
|
||||||
|
ERR("kernel size must be specified for combined images");
|
||||||
|
return -1; \
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!image_size)
|
||||||
|
image_size = kernel_info.file_size;
|
||||||
|
|
||||||
|
if (kernel_info.file_size > image_size) {
|
||||||
|
ERR("kernel image is too big");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
kernel_info.write_size = image_size;
|
||||||
|
} else {
|
||||||
|
CHKSTR(rootfs_info.file_name, "rootfs image");
|
||||||
|
|
||||||
ret = get_file_stat(&rootfs_info);
|
ret = get_file_stat(&rootfs_info);
|
||||||
if (ret)
|
if (ret)
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -228,6 +247,7 @@ static int check_options(void)
|
||||||
ERR("rootfs image is too big");
|
ERR("rootfs image is too big");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -301,12 +321,14 @@ static int build_fw(void)
|
||||||
if (ret)
|
if (ret)
|
||||||
goto out_free_buf;
|
goto out_free_buf;
|
||||||
|
|
||||||
|
if (!combined) {
|
||||||
p += kernel_info.write_size;
|
p += kernel_info.write_size;
|
||||||
|
|
||||||
/* read rootfs data */
|
/* read rootfs data */
|
||||||
ret = read_to_buf(&rootfs_info, p);
|
ret = read_to_buf(&rootfs_info, p);
|
||||||
if (ret)
|
if (ret)
|
||||||
goto out_free_buf;
|
goto out_free_buf;
|
||||||
|
}
|
||||||
|
|
||||||
csum = get_csum((unsigned char *)(buf + sizeof(struct img_header)),
|
csum = get_csum((unsigned char *)(buf + sizeof(struct img_header)),
|
||||||
buflen - sizeof(struct img_header));
|
buflen - sizeof(struct img_header));
|
||||||
|
@ -316,7 +338,10 @@ static int build_fw(void)
|
||||||
|
|
||||||
hdr->checksum = htonl(csum);
|
hdr->checksum = htonl(csum);
|
||||||
hdr->image_size = htonl(buflen - sizeof(struct img_header));
|
hdr->image_size = htonl(buflen - sizeof(struct img_header));
|
||||||
|
if (!combined)
|
||||||
hdr->kernel_size = htonl(kernel_info.write_size);
|
hdr->kernel_size = htonl(kernel_info.write_size);
|
||||||
|
else
|
||||||
|
hdr->kernel_size = htonl(kernel_size);
|
||||||
hdr->header_len = sizeof(struct img_header);
|
hdr->header_len = sizeof(struct img_header);
|
||||||
strncpy(hdr->model, model, sizeof(hdr->model));
|
strncpy(hdr->model, model, sizeof(hdr->model));
|
||||||
strncpy(hdr->signature, signature, sizeof(hdr->signature));
|
strncpy(hdr->signature, signature, sizeof(hdr->signature));
|
||||||
|
@ -344,7 +369,7 @@ int main(int argc, char *argv[])
|
||||||
while (1) {
|
while (1) {
|
||||||
int c;
|
int c;
|
||||||
|
|
||||||
c = getopt(argc, argv, "M:S:V:R:k:K:I:r:o:h");
|
c = getopt(argc, argv, "M:S:V:R:k:K:I:r:o:hc");
|
||||||
if (c == -1)
|
if (c == -1)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -381,6 +406,9 @@ int main(int argc, char *argv[])
|
||||||
case 'r':
|
case 'r':
|
||||||
rootfs_info.file_name = optarg;
|
rootfs_info.file_name = optarg;
|
||||||
break;
|
break;
|
||||||
|
case 'c':
|
||||||
|
combined = 1;
|
||||||
|
break;
|
||||||
case 'o':
|
case 'o':
|
||||||
ofname = optarg;
|
ofname = optarg;
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Reference in a new issue