ramips: Add a tool to create JCG factory images

replace spaces with tabs

Signed-off-by: Reinhard Max <reinhard@m4x.de>

SVN-Revision: 48901
lede-17.01
John Crispin 2016-03-04 08:32:54 +00:00
parent 4f8f5a2332
commit 4d97c8bab0
1 changed files with 220 additions and 209 deletions

View File

@ -99,8 +99,8 @@
#define JH_MAGIC 0x59535a4a /* "YSZJ" */
struct jcg_header {
uint32_t jh_magic;
uint8_t jh_version[32]; /* Firmware version string. Fill with
zeros to avoid encryption */
uint8_t jh_version[32]; /* Firmware version string.
Fill with zeros to avoid encryption */
uint32_t jh_type; /* must be 1 */
uint8_t jh_info[64]; /* Firmware info string. Fill with
zeros to avoid encryption */
@ -134,7 +134,9 @@ struct uimage_header {
uint8_t ih_type; /* Image Type */
uint8_t ih_comp; /* Compression Type */
uint8_t ih_name[IH_NMLEN];/* Image Name */
uint32_t ih_fsoff; /* Offset of the file system partition */
uint32_t ih_fsoff; /* Offset of the file system
partition from the start of
the header */
};
/*
@ -263,15 +265,16 @@ craftcrc(uint32_t dcrc, uint8_t *buf, size_t len)
crc = crc32(0L, Z_NULL, 0);
crc = crc32(crc, buf, len);
if (crc != dcrc) {
errx(1, "CRC patching is broken: wanted %08x, but got %08x.", dcrc, crc);
errx(1, "CRC patching is broken: wanted %08x, but got %08x.",
dcrc, crc);
}
}
void
usage() {
fprintf(stderr, "Usage:\n"
" jcgimage -o outputfile -u uImage [-v version]\n"
" jcgimage -o outputfile -k kernel -f rootfs [-v version]\n");
"jcgimage -o outfile -u uImage [-v version]\n"
"jcgimage -o outfile -k kernel -f rootfs [-v version]\n");
exit(1);
}
@ -307,20 +310,23 @@ main(int argc, char **argv)
imagefile = optarg;
break;
case 'k':
if (mode == MODE_UIMAGE)
if (mode == MODE_UIMAGE) {
errx(1,"-k cannot be combined with -u");
}
mode = MODE_KR;
file1 = optarg;
break;
case 'f':
if (mode == MODE_UIMAGE)
if (mode == MODE_UIMAGE) {
errx(1,"-f cannot be combined with -u");
}
mode = MODE_KR;
file2 = optarg;
break;
case 'u':
if (mode == MODE_KR)
if (mode == MODE_KR) {
errx(1,"-u cannot be combined with -k and -r");
}
mode = MODE_UIMAGE;
file1 = optarg;
break;
@ -338,11 +344,13 @@ main(int argc, char **argv)
if (imagefile == NULL) {
errx(1, "no output file specified");
}
if (mode == MODE_UNKNOWN)
if (mode == MODE_UNKNOWN) {
errx(1, "specify either -u or -k and -r");
}
if (mode == MODE_KR) {
if (file1 == NULL || file2 == NULL)
if (file1 == NULL || file2 == NULL) {
errx(1,"need -k and -r");
}
fd2 = opensize(file2, &size2);
}
fd1 = opensize(file1, &size1);
@ -357,12 +365,14 @@ main(int argc, char **argv)
sizeo = sizeof(*jh) + sizeu;
}
if (sizeo > MAXSIZE)
if (sizeo > MAXSIZE) {
errx(1,"payload too large: %zd > %zd\n", sizeo, MAXSIZE);
}
fdo = open(imagefile, O_RDWR | O_CREAT | O_TRUNC, 00644);
if (fdo < 0)
if (fdo < 0) {
err(1, "cannot open \"%s\"", imagefile);
}
if (ftruncate(fdo, sizeo) == -1) {
err(1, "cannot grow \"%s\" to %zd bytes", imagefile, sizeo);
@ -373,12 +383,14 @@ main(int argc, char **argv)
err(1, "cannot mmap \"%s\"", imagefile);
}
if (read(fd1, map + off1, size1) != size1)
if (read(fd1, map + off1, size1) != size1) {
err(1, "cannot copy %s", file1);
}
if (mode == MODE_KR) {
if (read(fd2, map+off2, size2) != size2)
if (read(fd2, map+off2, size2) != size2) {
err(1, "cannot copy %s", file2);
}
mkuheader(uh, size1, size2);
} else if (mode == MODE_UIMAGE) {
craftcrc(ntohl(uh->ih_dcrc), (void*)uh + sizeof(*uh),
@ -389,4 +401,3 @@ main(int argc, char **argv)
close(fdo);
return 0;
}