diff --git a/tools/firmware-utils/Makefile b/tools/firmware-utils/Makefile old mode 100755 new mode 100644 index 63df63191d..4b4af99908 --- a/tools/firmware-utils/Makefile +++ b/tools/firmware-utils/Makefile @@ -70,8 +70,8 @@ define Host/Compile $(call cc,fix-u-media-header cyg_crc32,-Wall) $(call cc,hcsmakeimage bcmalgo) $(call cc,mkporayfw, -Wall) - $(call cc,mkrasimage, --std=gnu99) $(call cc,mkhilinkfw, -lcrypto) + $(call cc,mkdcs932, -Wall) $(call cc,mkheader_gemtek,-lz) $(call cc,mkrtn56uimg, -lz) $(call cc,dgn3500sum, -Wall) @@ -84,7 +84,6 @@ define Host/Compile $(call cc,mkdhpimg buffalo-lib, -Wall) $(call cc,mkdlinkfw mkdlinkfw-lib, -lz -Wall --std=gnu99) $(call cc,dns313-header, -Wall) - $(call cc,mksercommfw, -Wall --std=gnu99) endef define Host/Install diff --git a/tools/firmware-utils/src/add_header.c b/tools/firmware-utils/src/add_header.c old mode 100755 new mode 100644 diff --git a/tools/firmware-utils/src/addpattern.c b/tools/firmware-utils/src/addpattern.c old mode 100755 new mode 100644 diff --git a/tools/firmware-utils/src/asustrx.c b/tools/firmware-utils/src/asustrx.c old mode 100755 new mode 100644 diff --git a/tools/firmware-utils/src/bcm_tag.h b/tools/firmware-utils/src/bcm_tag.h old mode 100755 new mode 100644 diff --git a/tools/firmware-utils/src/bcmalgo.c b/tools/firmware-utils/src/bcmalgo.c old mode 100755 new mode 100644 diff --git a/tools/firmware-utils/src/bcmalgo.h b/tools/firmware-utils/src/bcmalgo.h old mode 100755 new mode 100644 diff --git a/tools/firmware-utils/src/buffalo-enc.c b/tools/firmware-utils/src/buffalo-enc.c old mode 100755 new mode 100644 diff --git a/tools/firmware-utils/src/buffalo-lib.c b/tools/firmware-utils/src/buffalo-lib.c old mode 100755 new mode 100644 diff --git a/tools/firmware-utils/src/buffalo-lib.h b/tools/firmware-utils/src/buffalo-lib.h old mode 100755 new mode 100644 diff --git a/tools/firmware-utils/src/buffalo-tag.c b/tools/firmware-utils/src/buffalo-tag.c old mode 100755 new mode 100644 diff --git a/tools/firmware-utils/src/buffalo-tftp.c b/tools/firmware-utils/src/buffalo-tftp.c old mode 100755 new mode 100644 diff --git a/tools/firmware-utils/src/csysimg.h b/tools/firmware-utils/src/csysimg.h old mode 100755 new mode 100644 diff --git a/tools/firmware-utils/src/cyg_crc.h b/tools/firmware-utils/src/cyg_crc.h old mode 100755 new mode 100644 diff --git a/tools/firmware-utils/src/cyg_crc16.c b/tools/firmware-utils/src/cyg_crc16.c old mode 100755 new mode 100644 diff --git a/tools/firmware-utils/src/cyg_crc32.c b/tools/firmware-utils/src/cyg_crc32.c old mode 100755 new mode 100644 diff --git a/tools/firmware-utils/src/dgfirmware.c b/tools/firmware-utils/src/dgfirmware.c old mode 100755 new mode 100644 diff --git a/tools/firmware-utils/src/dgn3500sum.c b/tools/firmware-utils/src/dgn3500sum.c old mode 100755 new mode 100644 diff --git a/tools/firmware-utils/src/dns313-header.c b/tools/firmware-utils/src/dns313-header.c old mode 100755 new mode 100644 diff --git a/tools/firmware-utils/src/edimax_fw_header.c b/tools/firmware-utils/src/edimax_fw_header.c old mode 100755 new mode 100644 diff --git a/tools/firmware-utils/src/encode_crc.c b/tools/firmware-utils/src/encode_crc.c old mode 100755 new mode 100644 diff --git a/tools/firmware-utils/src/fix-u-media-header.c b/tools/firmware-utils/src/fix-u-media-header.c old mode 100755 new mode 100644 diff --git a/tools/firmware-utils/src/fw.h b/tools/firmware-utils/src/fw.h old mode 100755 new mode 100644 index 44f8d851d2..e37859c52d --- a/tools/firmware-utils/src/fw.h +++ b/tools/firmware-utils/src/fw.h @@ -24,7 +24,6 @@ #define MAGIC_HEADER "OPEN" #define MAGIC_PART "PART" #define MAGIC_END "END." -#define MAGIC_ENDS "ENDS" #define MAGIC_LENGTH 4 @@ -58,13 +57,6 @@ typedef struct signature { u_int32_t pad; } __attribute__ ((packed)) signature_t; -typedef struct signature_rsa { - char magic[MAGIC_LENGTH]; -// u_int32_t crc; - unsigned char rsa_signature[256]; - u_int32_t pad; -} __attribute__ ((packed)) signature_rsa_t; - #define VERSION "1.2" #define INFO(...) fprintf(stdout, __VA_ARGS__) diff --git a/tools/firmware-utils/src/hcsmakeimage.c b/tools/firmware-utils/src/hcsmakeimage.c old mode 100755 new mode 100644 diff --git a/tools/firmware-utils/src/imagetag.c b/tools/firmware-utils/src/imagetag.c old mode 100755 new mode 100644 diff --git a/tools/firmware-utils/src/imagetag.ggo b/tools/firmware-utils/src/imagetag.ggo old mode 100755 new mode 100644 diff --git a/tools/firmware-utils/src/imagetag_cmdline.c b/tools/firmware-utils/src/imagetag_cmdline.c old mode 100755 new mode 100644 diff --git a/tools/firmware-utils/src/imagetag_cmdline.h b/tools/firmware-utils/src/imagetag_cmdline.h old mode 100755 new mode 100644 diff --git a/tools/firmware-utils/src/jcgimage.c b/tools/firmware-utils/src/jcgimage.c old mode 100755 new mode 100644 diff --git a/tools/firmware-utils/src/lzma2eva.c b/tools/firmware-utils/src/lzma2eva.c old mode 100755 new mode 100644 diff --git a/tools/firmware-utils/src/makeamitbin.c b/tools/firmware-utils/src/makeamitbin.c old mode 100755 new mode 100644 diff --git a/tools/firmware-utils/src/md5.c b/tools/firmware-utils/src/md5.c old mode 100755 new mode 100644 diff --git a/tools/firmware-utils/src/md5.h b/tools/firmware-utils/src/md5.h old mode 100755 new mode 100644 diff --git a/tools/firmware-utils/src/mkbrncmdline.c b/tools/firmware-utils/src/mkbrncmdline.c old mode 100755 new mode 100644 diff --git a/tools/firmware-utils/src/mkbrnimg.c b/tools/firmware-utils/src/mkbrnimg.c old mode 100755 new mode 100644 diff --git a/tools/firmware-utils/src/mkbuffaloimg.c b/tools/firmware-utils/src/mkbuffaloimg.c old mode 100755 new mode 100644 diff --git a/tools/firmware-utils/src/mkcameofw.c b/tools/firmware-utils/src/mkcameofw.c old mode 100755 new mode 100644 diff --git a/tools/firmware-utils/src/mkcasfw.c b/tools/firmware-utils/src/mkcasfw.c old mode 100755 new mode 100644 diff --git a/tools/firmware-utils/src/mkchkimg.c b/tools/firmware-utils/src/mkchkimg.c old mode 100755 new mode 100644 diff --git a/tools/firmware-utils/src/mkcsysimg.c b/tools/firmware-utils/src/mkcsysimg.c old mode 100755 new mode 100644 diff --git a/tools/firmware-utils/src/mkdapimg.c b/tools/firmware-utils/src/mkdapimg.c old mode 100755 new mode 100644 index ed662d8ecc..640f42d7c6 --- a/tools/firmware-utils/src/mkdapimg.c +++ b/tools/firmware-utils/src/mkdapimg.c @@ -12,7 +12,7 @@ // Usage: mkdapimg [-p] [-m ] -s -i -o // -// e.g.: mkdapimg -s RT3052-AP-DAP1350-3 -i sysupgarde.bin -o factory.bin +// e.g.: mkdapimg -s RT3052-AP-DAP1350-3 -i sysupgrade.bin -o factory.bin // // If the model string is not given, we will assume that // the leading characters upto the first "-" is the model. diff --git a/tools/firmware-utils/src/mkdapimg2.c b/tools/firmware-utils/src/mkdapimg2.c old mode 100755 new mode 100644 index aef003c280..6b53c959b6 --- a/tools/firmware-utils/src/mkdapimg2.c +++ b/tools/firmware-utils/src/mkdapimg2.c @@ -48,7 +48,7 @@ // 0x000000120000-0x000000040000 = 0xE0000 -> 917504 // // e.g.: mkdapimg2 -s HONEYBEE-FIRMWARE-DAP-1330 -v 1.00.21 -r Default -// -k 917504 -i sysupgarde.bin -o factory.bin +// -k 917504 -i sysupgrade.bin -o factory.bin // // // The img_hdr_struct was taken from the D-Link SDK: diff --git a/tools/firmware-utils/src/mkdcs932.c b/tools/firmware-utils/src/mkdcs932.c new file mode 100644 index 0000000000..28c67aa3b3 --- /dev/null +++ b/tools/firmware-utils/src/mkdcs932.c @@ -0,0 +1,39 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License, + * version 2 as published by the Free Software Foundation. + * + * (C) John Crispin + */ + +#include +#include +#include +#include +#include +#include +#include + +int main(int argc, char **argv) +{ + uint32_t t = 0, sum = 0x55aa55aa; + int fd; + + if ((argc != 2) || ((fd = open(argv[1], O_RDWR)) == -1)) { + fprintf(stderr, "Usage: %s input_file\n", *argv); + return -EINVAL; + } + + lseek(fd, -4, SEEK_END); + write(fd, &t, 4); + lseek(fd, 0, SEEK_SET); + + while (read(fd, &t, 4) > 0) + sum -= t; + + lseek(fd, -4, SEEK_END); + write(fd, &sum, 4); + close(fd); + + return 0; +} diff --git a/tools/firmware-utils/src/mkdhpimg.c b/tools/firmware-utils/src/mkdhpimg.c old mode 100755 new mode 100644 diff --git a/tools/firmware-utils/src/mkdlinkfw-lib.c b/tools/firmware-utils/src/mkdlinkfw-lib.c old mode 100755 new mode 100644 diff --git a/tools/firmware-utils/src/mkdlinkfw-lib.h b/tools/firmware-utils/src/mkdlinkfw-lib.h old mode 100755 new mode 100644 diff --git a/tools/firmware-utils/src/mkdlinkfw.c b/tools/firmware-utils/src/mkdlinkfw.c old mode 100755 new mode 100644 diff --git a/tools/firmware-utils/src/mkdniimg.c b/tools/firmware-utils/src/mkdniimg.c old mode 100755 new mode 100644 diff --git a/tools/firmware-utils/src/mkedimaximg.c b/tools/firmware-utils/src/mkedimaximg.c old mode 100755 new mode 100644 index 541eaaaa3f..d8a017e6a8 --- a/tools/firmware-utils/src/mkedimaximg.c +++ b/tools/firmware-utils/src/mkedimaximg.c @@ -17,19 +17,12 @@ #include #include /* for __BYTE_ORDER */ -#define FALSE 0 -#define TRUE 1 - #if (__BYTE_ORDER == __LITTLE_ENDIAN) # define HOST_TO_LE16(x) (x) # define HOST_TO_LE32(x) (x) -# define HOST_TO_BE16(x) bswap_16(x) -# define HOST_TO_BE32(x) bswap_32(x) #else # define HOST_TO_LE16(x) bswap_16(x) # define HOST_TO_LE32(x) bswap_32(x) -# define HOST_TO_BE16(x) (x) -# define HOST_TO_BE32(x) (x) #endif struct header @@ -54,7 +47,6 @@ struct buf }; static char *progname; -static int force_be = FALSE; static void usage(int status) { @@ -69,8 +61,7 @@ static void usage(int status) " -i read input from file \n" " -o write output to file \n" " -f set flash address to \n" - " -S set start address to \n" - " -b big-endianness mode\n"); + " -S set start address to \n"); exit(status); } @@ -92,12 +83,8 @@ static unsigned short fwcsum (struct buf *buf) { int i; unsigned short ret = 0; - for (i = 0; i < buf->size / 2; i++) { - if (force_be == FALSE) - ret -= ((unsigned short *) buf->start)[i]; - else - ret -= HOST_TO_BE16(((unsigned short *) buf->start)[i]); - } + for (i = 0; i < buf->size / 2; i++) + ret -= ((unsigned short *) buf->start)[i]; return ret; } @@ -157,7 +144,7 @@ int main(int argc, char **argv) header.flash = header.size = header.start = 0; progname = basename(argv[0]); - while((c = getopt(argc, argv, "i:o:m:s:f:S:h:b")) != -1) { + while((c = getopt(argc, argv, "i:o:m:s:f:S:h")) != -1) { switch (c) { case 'i': ifinfo.name = optarg; @@ -194,9 +181,6 @@ int main(int argc, char **argv) usage(EXIT_FAILURE); } break; - case 'b': - force_be = TRUE; - break; default: usage(EXIT_FAILURE); break; @@ -257,23 +241,12 @@ int main(int argc, char **argv) if (fwread(&ifinfo, &ibuf)) usage(EXIT_FAILURE); - if (force_be == FALSE) { - header.flash = HOST_TO_LE32(header.flash); - header.size = HOST_TO_LE32(obuf.size - sizeof(struct header)); - header.start = HOST_TO_LE32(header.start); - } else { - header.flash = HOST_TO_BE32(header.flash); - header.size = HOST_TO_BE32(obuf.size - sizeof(struct header)); - header.start = HOST_TO_BE32(header.start); - } - + header.flash = HOST_TO_LE32(header.flash); + header.size = HOST_TO_LE32(obuf.size - sizeof(struct header)); + header.start = HOST_TO_LE32(header.start); memcpy (obuf.start, &header, sizeof(struct header)); - if (force_be == FALSE) - csum = HOST_TO_LE16(fwcsum(&ibuf)); - else - csum = HOST_TO_BE16(fwcsum(&ibuf)); - + csum = HOST_TO_LE16(fwcsum(&ibuf)); memcpy(obuf.start + obuf.size - sizeof(unsigned short), &csum, sizeof(unsigned short)); diff --git a/tools/firmware-utils/src/mkfwimage.c b/tools/firmware-utils/src/mkfwimage.c old mode 100755 new mode 100644 index 2b84d3db53..d8d5239cc5 --- a/tools/firmware-utils/src/mkfwimage.c +++ b/tools/firmware-utils/src/mkfwimage.c @@ -29,106 +29,65 @@ #include #include #include -#include #include "fw.h" typedef struct fw_layout_data { + char name[PATH_MAX]; u_int32_t kern_start; u_int32_t kern_entry; u_int32_t firmware_max_length; } fw_layout_t; -struct fw_info { - char name[PATH_MAX]; - struct fw_layout_data fw_layout; - bool sign; -}; - -struct fw_info fw_info[] = { +fw_layout_t fw_layout_data[] = { { - .name = "XS2", - .fw_layout = { - .kern_start = 0xbfc30000, - .kern_entry = 0x80041000, - .firmware_max_length= 0x00390000, - }, - .sign = false, + .name = "XS2", + .kern_start = 0xbfc30000, + .kern_entry = 0x80041000, + .firmware_max_length= 0x00390000, }, { - .name = "XS5", - .fw_layout = { - .kern_start = 0xbe030000, - .kern_entry = 0x80041000, - .firmware_max_length= 0x00390000, - }, - .sign = false, + .name = "XS5", + .kern_start = 0xbe030000, + .kern_entry = 0x80041000, + .firmware_max_length= 0x00390000, }, { - .name = "RS", - .fw_layout = { - .kern_start = 0xbf030000, - .kern_entry = 0x80060000, - .firmware_max_length= 0x00B00000, - }, - .sign = false, + .name = "RS", + .kern_start = 0xbf030000, + .kern_entry = 0x80060000, + .firmware_max_length= 0x00B00000, }, { - .name = "RSPRO", - .fw_layout = { - .kern_start = 0xbf030000, - .kern_entry = 0x80060000, - .firmware_max_length= 0x00F00000, - }, - .sign = false, + .name = "RSPRO", + .kern_start = 0xbf030000, + .kern_entry = 0x80060000, + .firmware_max_length= 0x00F00000, }, { - .name = "LS-SR71", - .fw_layout = { - .kern_start = 0xbf030000, - .kern_entry = 0x80060000, - .firmware_max_length= 0x00640000, - }, - .sign = false, + .name = "LS-SR71", + .kern_start = 0xbf030000, + .kern_entry = 0x80060000, + .firmware_max_length= 0x00640000, }, { - .name = "XS2-8", - .fw_layout = { - .kern_start = 0xa8030000, - .kern_entry = 0x80041000, - .firmware_max_length= 0x006C0000, - }, - .sign = false, - + .name = "XS2-8", + .kern_start = 0xa8030000, + .kern_entry = 0x80041000, + .firmware_max_length= 0x006C0000, }, { - .name = "XM", - .fw_layout = { - .kern_start = 0x9f050000, - .kern_entry = 0x80002000, - .firmware_max_length= 0x00760000, - }, - .sign = false, + .name = "XM", + .kern_start = 0x9f050000, + .kern_entry = 0x80002000, + .firmware_max_length= 0x00760000, }, { - .name = "UBDEV01", - .fw_layout = { - .kern_start = 0x9f050000, - .kern_entry = 0x80002000, - .firmware_max_length= 0x006A0000, - }, - .sign = false, + .name = "UBDEV01", + .kern_start = 0x9f050000, + .kern_entry = 0x80002000, + .firmware_max_length= 0x006A0000, }, - { - .name = "WA", - .fw_layout = { - .kern_start = 0x9f050000, - .kern_entry = 0x80002000, - .firmware_max_length= 0x00F60000, - }, - .sign = true, - }, - { - .name = "", + { .name = "", }, }; @@ -157,20 +116,8 @@ typedef struct image_info { char outputfile[PATH_MAX]; u_int32_t part_count; part_data_t parts[MAX_SECTIONS]; - struct fw_info* fwinfo; } image_info_t; -static struct fw_info* get_fwinfo(char* board_name) { - struct fw_info *fwinfo = fw_info; - while(strlen(fwinfo->name)) { - if(strcmp(fwinfo->name, board_name) == 0) { - return fwinfo; - } - fwinfo++; - } - return NULL; -} - static void write_header(void* mem, const char *magic, const char* version) { header_t* header = mem; @@ -195,17 +142,6 @@ static void write_signature(void* mem, u_int32_t sig_offset) sign->pad = 0L; } -static void write_signature_rsa(void* mem, u_int32_t sig_offset) -{ - /* write signature */ - signature_rsa_t* sign = (signature_rsa_t*)(mem + sig_offset); - memset(sign, 0, sizeof(signature_rsa_t)); - - memcpy(sign->magic, MAGIC_ENDS, MAGIC_LENGTH); -// sign->crc = htonl(crc32(0L,(unsigned char *)mem, sig_offset)); - sign->pad = 0L; -} - static int write_part(void* mem, part_data_t* d) { char* addr; @@ -301,9 +237,17 @@ static int create_image_layout(const char* kernelfile, const char* rootfsfile, c part_data_t* kernel = &im->parts[0]; part_data_t* rootfs = &im->parts[1]; - fw_layout_t* p = &im->fwinfo->fw_layout; + fw_layout_t* p; - printf("board = %s\n", im->fwinfo->name); + p = &fw_layout_data[0]; + while (*p->name && (strcmp(p->name, board_name) != 0)) + p++; + if (!*p->name) { + printf("BUG! Unable to find default fw layout!\n"); + exit(-1); + } + + printf("board = %s\n", p->name); strcpy(kernel->partition_name, "kernel"); kernel->partition_index = 1; kernel->partition_baseaddr = p->kern_start; @@ -386,12 +330,7 @@ static int build_image(image_info_t* im) int i; // build in-memory buffer - mem_size = sizeof(header_t); - if(im->fwinfo->sign) { - mem_size += sizeof(signature_rsa_t); - } else { - mem_size += sizeof(signature_t); - } + mem_size = sizeof(header_t) + sizeof(signature_t); for (i = 0; i < im->part_count; ++i) { part_data_t* d = &im->parts[i]; @@ -420,11 +359,7 @@ static int build_image(image_info_t* im) ptr += sizeof(part_t) + d->stats.st_size + sizeof(part_crc_t); } // write signature - if(im->fwinfo->sign) { - write_signature_rsa(mem, mem_size - sizeof(signature_rsa_t)); - } else { - write_signature(mem, mem_size - sizeof(signature_t)); - } + write_signature(mem, mem_size - sizeof(signature_t)); // write in-memory buffer into file if ((f = fopen(im->outputfile, "w")) == NULL) @@ -453,7 +388,6 @@ int main(int argc, char* argv[]) char board_name[PATH_MAX]; int o, rc; image_info_t im; - struct fw_info *fwinfo; memset(&im, 0, sizeof(im)); memset(kernelfile, 0, sizeof(kernelfile)); @@ -513,14 +447,6 @@ int main(int argc, char* argv[]) return -2; } - if ((fwinfo = get_fwinfo(board_name)) == NULL) { - ERROR("Invalid baord name '%s'\n", board_name); - usage(argv[0]); - return -2; - } - - im.fwinfo = fwinfo; - if ((rc = create_image_layout(kernelfile, rootfsfile, board_name, &im)) != 0) { ERROR("Failed creating firmware layout description - error code: %d\n", rc); diff --git a/tools/firmware-utils/src/mkfwimage2.c b/tools/firmware-utils/src/mkfwimage2.c old mode 100755 new mode 100644 diff --git a/tools/firmware-utils/src/mkheader_gemtek.c b/tools/firmware-utils/src/mkheader_gemtek.c old mode 100755 new mode 100644 diff --git a/tools/firmware-utils/src/mkhilinkfw.c b/tools/firmware-utils/src/mkhilinkfw.c old mode 100755 new mode 100644 diff --git a/tools/firmware-utils/src/mkmerakifw-old.c b/tools/firmware-utils/src/mkmerakifw-old.c old mode 100755 new mode 100644 diff --git a/tools/firmware-utils/src/mkmerakifw.c b/tools/firmware-utils/src/mkmerakifw.c old mode 100755 new mode 100644 diff --git a/tools/firmware-utils/src/mkmylofw.c b/tools/firmware-utils/src/mkmylofw.c old mode 100755 new mode 100644 diff --git a/tools/firmware-utils/src/mkplanexfw.c b/tools/firmware-utils/src/mkplanexfw.c old mode 100755 new mode 100644 diff --git a/tools/firmware-utils/src/mkporayfw.c b/tools/firmware-utils/src/mkporayfw.c old mode 100755 new mode 100644 diff --git a/tools/firmware-utils/src/mkrasimage.c b/tools/firmware-utils/src/mkrasimage.c deleted file mode 100755 index 8eee29cc08..0000000000 --- a/tools/firmware-utils/src/mkrasimage.c +++ /dev/null @@ -1,459 +0,0 @@ -/* - * --- ZyXEL header format --- - * Original Version by Benjamin Berg - * C implementation based on generation-script by Christian Lamparter - * - * The firmware image prefixed with a header (which is written into the MTD device). - * The header is one erase block (~64KiB) in size, but the checksum only convers the - * first 2KiB. Padding is 0xff. All integers are in big-endian. - * - * The checksum is always a 16-Bit System V checksum (sum -s) stored in a 32-Bit integer. - * - * 4 bytes: checksum of the rootfs image - * 4 bytes: length of the contained rootfs image file (big endian) - * 32 bytes: Firmware Version string (NUL terminated, 0xff padded) - * 4 bytes: checksum over the header partition (big endian - see below) - * 64 bytes: Model (e.g. "NBG6617", NUL termiated, 0xff padded) - * 4 bytes: checksum of the kernel partition - * 4 bytes: length of the contained kernel image file (big endian) - * rest: 0xff padding (To erase block size) - * - * The kernel partition checksum and length is not used for every device. - * If it's notused, pad those 8 bytes with 0xFF. - * - * The checksums are calculated by adding up all bytes and if a 16bit - * overflow occurs, one is added and the sum is masked to 16 bit: - * csum = csum + databyte; if (csum > 0xffff) { csum += 1; csum &= 0xffff }; - * Should the file have an odd number of bytes then the byte len-0x800 is - * used additionally. - * - * The checksum for the header is calculated over the first 2048 bytes with - * the rootfs image checksum as the placeholder during calculation. - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 as published - * by the Free Software Foundation. - * - */ -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -#include - -#define VERSION_STRING_LEN 31 -#define ROOTFS_HEADER_LEN 40 - -#define KERNEL_HEADER_LEN 8 - -#define BOARD_NAME_LEN 64 -#define BOARD_HEADER_LEN 68 - -#define HEADER_PARTITION_CALC_LENGTH 2048 -#define HEADER_PARTITION_LENGTH 0x10000 - -struct file_info { - char *name; /* name of the file */ - char *data; /* file content */ - size_t size; /* length of the file */ -}; - -static char *progname; - -static char *board_name = 0; -static char *version_name = 0; -static unsigned int rootfs_size = 0; - -static struct file_info kernel = { NULL, NULL, 0 }; -static struct file_info rootfs = { NULL, NULL, 0 }; -static struct file_info rootfs_out = { NULL, NULL, 0 }; -static struct file_info out = { NULL, NULL, 0 }; - -#define ERR(fmt, ...) do { \ - fprintf(stderr, "[%s] *** error: " fmt "\n", \ - progname, ## __VA_ARGS__ ); \ -} while (0) - -void map_file(struct file_info *finfo) -{ - struct stat file_stat = {0}; - int fd; - - fd = open(finfo->name, O_RDONLY, (mode_t)0600); - if (fd == -1) { - ERR("Error while opening file %s.", finfo->name); - exit(EXIT_FAILURE); - } - - if (fstat(fd, &file_stat) == -1) { - ERR("Error getting file size for %s.", finfo->name); - exit(EXIT_FAILURE); - } - - finfo->size = file_stat.st_size; - finfo->data = mmap(0, finfo->size, PROT_READ, MAP_SHARED, fd, 0); - - if (finfo->data == MAP_FAILED) { - ERR("Error mapping file %s.", finfo->name); - exit(EXIT_FAILURE); - } - - close(fd); -} - -void unmap_file(struct file_info *finfo) -{ - if(munmap(finfo->data, finfo->size) == -1) { - ERR("Error unmapping file %s.", finfo->name); - exit(EXIT_FAILURE); - } -} - -void write_file(struct file_info *finfo) -{ - FILE *fout = fopen(finfo->name, "w"); - - fwrite(finfo->data, finfo->size, 1, fout); - - if (ferror(fout)) { - ERR("Wanted to write, but something went wrong."); - exit(EXIT_FAILURE); - } - - fclose(fout); -} - -void usage(int status) -{ - FILE *stream = (status != EXIT_SUCCESS) ? stderr : stdout; - - fprintf(stream, "Usage: %s [OPTIONS...]\n", progname); - fprintf(stream, - "\n" - "Options:\n" - " -k path for kernel image\n" - " -r path for rootfs image\n" - " -s size of output rootfs\n" - " -v version string\n" - " -b name of board to generate image for\n" - " -o name of output image\n" - " -h show this screen\n" - ); - - exit(status); -} - -static int sysv_chksm(const unsigned char *data, int size) -{ - int r; - int checksum; - unsigned int s = 0; /* The sum of all the input bytes, modulo (UINT_MAX + 1). */ - - - for (int i = 0; i < size; i++) { - s += data[i]; - } - - r = (s & 0xffff) + ((s & 0xffffffff) >> 16); - checksum = (r & 0xffff) + (r >> 16); - - return checksum; -} - -static int zyxel_chksm(const unsigned char *data, int size) -{ - return htonl(sysv_chksm(data, size)); -} - -char *generate_rootfs_header(struct file_info filesystem, char *version) -{ - size_t version_string_length; - unsigned int chksm, size; - char *rootfs_header; - size_t ptr = 0; - - rootfs_header = malloc(ROOTFS_HEADER_LEN); - if (!rootfs_header) { - ERR("Couldn't allocate memory for rootfs header!"); - exit(EXIT_FAILURE); - } - - /* Prepare padding for firmware-version string here */ - memset(rootfs_header, 0xff, ROOTFS_HEADER_LEN); - - chksm = zyxel_chksm((const unsigned char *)filesystem.data, filesystem.size); - size = htonl(filesystem.size); - - /* 4 bytes: checksum of the rootfs image */ - memcpy(rootfs_header + ptr, &chksm, 4); - ptr += 4; - - /* 4 bytes: length of the contained rootfs image file (big endian) */ - memcpy(rootfs_header + ptr, &size, 4); - ptr += 4; - - /* 32 bytes: Firmware Version string (NUL terminated, 0xff padded) */ - version_string_length = strlen(version) <= VERSION_STRING_LEN ? strlen(version) : VERSION_STRING_LEN; - memcpy(rootfs_header + ptr, version, version_string_length); - ptr += version_string_length; - /* Add null-terminator */ - rootfs_header[ptr] = 0x0; - - return rootfs_header; -} - -char *generate_kernel_header(struct file_info kernel) -{ - unsigned int chksm, size; - char *kernel_header; - size_t ptr = 0; - - kernel_header = malloc(KERNEL_HEADER_LEN); - if (!kernel_header) { - ERR("Couldn't allocate memory for kernel header!"); - exit(EXIT_FAILURE); - } - - chksm = zyxel_chksm((const unsigned char *)kernel.data, kernel.size); - size = htonl(kernel.size); - - /* 4 bytes: checksum of the kernel image */ - memcpy(kernel_header + ptr, &chksm, 4); - ptr += 4; - - /* 4 bytes: length of the contained kernel image file (big endian) */ - memcpy(kernel_header + ptr, &size, 4); - - return kernel_header; -} - -unsigned int generate_board_header_checksum(char *kernel_hdr, char *rootfs_hdr, char *boardname) -{ - char *board_hdr_tmp; - unsigned int sum; - size_t ptr = 0; - - /* - * The checksum of the board header is calculated over the first 2048 bytes of - * the header partition with the rootfs checksum used as a placeholder for then - * board checksum we calculate in this step. The checksum gained from this step - * is then used for the final board header partition. - */ - - board_hdr_tmp = malloc(HEADER_PARTITION_CALC_LENGTH); - if (!board_hdr_tmp) { - ERR("Couldn't allocate memory for temporary board header!"); - exit(EXIT_FAILURE); - } - memset(board_hdr_tmp, 0xff, HEADER_PARTITION_CALC_LENGTH); - - /* 40 bytes: RootFS header */ - memcpy(board_hdr_tmp, rootfs_hdr, ROOTFS_HEADER_LEN); - ptr += ROOTFS_HEADER_LEN; - - /* 4 bytes: RootFS checksum (BE) as placeholder for board-header checksum */ - memcpy(board_hdr_tmp + ptr, rootfs_hdr, 4); - ptr += 4; - - /* 32 bytes: Model (e.g. "NBG6617", NUL termiated, 0xff padded) */ - memcpy(board_hdr_tmp + ptr, boardname, strlen(boardname)); - ptr += strlen(boardname); - /* Add null-terminator */ - board_hdr_tmp[ptr] = 0x0; - ptr = ROOTFS_HEADER_LEN + 4 + BOARD_NAME_LEN; - - /* 8 bytes: Kernel header */ - if (kernel_hdr) - memcpy(board_hdr_tmp + ptr, kernel_hdr, 8); - - /* Calculate the checksum over the first 2048 bytes */ - sum = zyxel_chksm((const unsigned char *)board_hdr_tmp, HEADER_PARTITION_CALC_LENGTH); - free(board_hdr_tmp); - return sum; -} - -char *generate_board_header(char *kernel_hdr, char *rootfs_hdr, char *boardname) -{ - unsigned int board_checksum; - char *board_hdr; - - board_hdr = malloc(BOARD_HEADER_LEN); - if (!board_hdr) { - ERR("Couldn't allocate memory for board header!"); - exit(EXIT_FAILURE); - } - memset(board_hdr, 0xff, BOARD_HEADER_LEN); - - /* 4 bytes: checksum over the header partition (big endian) */ - board_checksum = generate_board_header_checksum(kernel_hdr, rootfs_hdr, boardname); - memcpy(board_hdr, &board_checksum, 4); - - /* 32 bytes: Model (e.g. "NBG6617", NUL termiated, 0xff padded) */ - memcpy(board_hdr + 4, boardname, strlen(boardname)); - board_hdr[4 + strlen(boardname)] = 0x0; - - return board_hdr; -} - -int build_image() -{ - char *rootfs_header = NULL; - char *kernel_header = NULL; - char *board_header = NULL; - - size_t ptr; - - /* Load files */ - if (kernel.name) - map_file(&kernel); - map_file(&rootfs); - - /* - * Allocate memory and copy input rootfs for temporary output rootfs. - * This is important as we have to generate the rootfs checksum over the - * entire rootfs partition. As we might have to pad the partition to allow - * for flashing via ZyXEL's Web-GUI, we prepare the rootfs partition for the - * output image here (and also use it for calculating the rootfs checksum). - * - * The roofs padding has to be done with 0x00. - */ - rootfs_out.data = calloc(rootfs_out.size, sizeof(char)); - memcpy(rootfs_out.data, rootfs.data, rootfs.size); - - /* Prepare headers */ - rootfs_header = generate_rootfs_header(rootfs_out, version_name); - if (kernel.name) - kernel_header = generate_kernel_header(kernel); - board_header = generate_board_header(kernel_header, rootfs_header, board_name); - - /* Prepare output file */ - out.size = HEADER_PARTITION_LENGTH + rootfs_out.size; - if (kernel.name) - out.size += kernel.size; - out.data = malloc(out.size); - memset(out.data, 0xFF, out.size); - - /* Build output image */ - memcpy(out.data, rootfs_header, ROOTFS_HEADER_LEN); - memcpy(out.data + ROOTFS_HEADER_LEN, board_header, BOARD_HEADER_LEN); - if (kernel.name) - memcpy(out.data + ROOTFS_HEADER_LEN + BOARD_HEADER_LEN, kernel_header, KERNEL_HEADER_LEN); - ptr = HEADER_PARTITION_LENGTH; - memcpy(out.data + ptr, rootfs_out.data, rootfs_out.size); - ptr += rootfs_out.size; - if (kernel.name) - memcpy(out.data + ptr, kernel.data, kernel.size); - - /* Write back output image */ - write_file(&out); - - /* Free allocated memory */ - if (kernel.name) - unmap_file(&kernel); - unmap_file(&rootfs); - free(out.data); - free(rootfs_out.data); - - free(rootfs_header); - if (kernel.name) - free(kernel_header); - free(board_header); - - return 0; -} - -int check_options() -{ - if (!rootfs.name) { - ERR("No rootfs filename supplied"); - return -2; - } - - if (!out.name) { - ERR("No output filename supplied"); - return -3; - } - - if (!board_name) { - ERR("No board-name supplied"); - return -4; - } - - if (!version_name) { - ERR("No version supplied"); - return -5; - } - - if (rootfs_size <= 0) { - ERR("Invalid rootfs size supplied"); - return -6; - } - - if (strlen(board_name) > 31) { - ERR("Board name is to long"); - return -7; - } - return 0; -} - -int main(int argc, char *argv[]) -{ - int ret; - progname = basename(argv[0]); - while (1) { - int c; - - c = getopt(argc, argv, "b:k:o:r:s:v:h"); - if (c == -1) - break; - - switch (c) { - case 'b': - board_name = optarg; - break; - case 'h': - usage(EXIT_SUCCESS); - break; - case 'k': - kernel.name = optarg; - break; - case 'o': - out.name = optarg; - break; - case 'r': - rootfs.name = optarg; - break; - case 's': - sscanf(optarg, "%u", &rootfs_size); - break; - case 'v': - version_name = optarg; - break; - default: - usage(EXIT_FAILURE); - break; - } - } - - ret = check_options(); - if (ret) - usage(EXIT_FAILURE); - - /* As ZyXEL Web-GUI only accept images with a rootfs equal or larger than the first firmware shipped - * for the device, we need to pad rootfs partition to this size. To perform further calculations, we - * decide the size of this part here. In case the rootfs we want to integrate in our image is larger, - * take it's size, otherwise the supplied size. - * - * Be careful! We rely on assertion of correct size to be performed beforehand. It is unknown if images - * with a to large rootfs are accepted or not. - */ - rootfs_out.size = rootfs_size < rootfs.size ? rootfs.size : rootfs_size; - return build_image(); -} diff --git a/tools/firmware-utils/src/mkrtn56uimg.c b/tools/firmware-utils/src/mkrtn56uimg.c old mode 100755 new mode 100644 diff --git a/tools/firmware-utils/src/mksenaofw.c b/tools/firmware-utils/src/mksenaofw.c old mode 100755 new mode 100644 diff --git a/tools/firmware-utils/src/mksercommfw.c b/tools/firmware-utils/src/mksercommfw.c deleted file mode 100755 index 23e4dd06b2..0000000000 --- a/tools/firmware-utils/src/mksercommfw.c +++ /dev/null @@ -1,422 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include - -#if !defined(__BYTE_ORDER) -#error "Unknown byte order" -#endif - -#if __BYTE_ORDER == __BIG_ENDIAN -#define cpu_to_be32(x) (x) -#define be32_to_cpu(x) (x) -#define cpu_to_be16(x) (x) -#define be16_to_cpu(x) (x) -#elif __BYTE_ORDER == __LITTLE_ENDIAN -#define cpu_to_be32(x) bswap_32(x) -#define be32_to_cpu(x) bswap_32(x) -#define cpu_to_be16(x) bswap_16(x) -#define be16_to_cpu(x) bswap_16(x) -#else -#error "Unsupported endianness" -#endif - -/* #define DEBUG 1 */ - -#ifdef DEBUG -#define DBG(...) {printf(__VA_ARGS__); } -#else -#define DBG(...) {} -#endif - -#define ERR(...) {printf(__VA_ARGS__); } -#define ALIGN(a,b) ((a) + ((b) - ((a) % (b)))) -#define ROOTFS_ALIGN 128 -#define HEADER_SIZE 71 - -/* - * Fw Header Layout for Netgear / Sercomm devices (bytes) - * - * Size : 512 bytes + zipped image size - * - * Locations: - * magic : 0-6 ASCII - * version: 7-11 fixed - * hwID : 11-44 ASCII - * hwVer : 45-54 ASCII - * swVer : 55-62 uint32_t in BE - * magic : 63-69 ASCII - * ChkSum : 511 Inverse value of the full image checksum while this location is 0x00 - */ - -static const char* magic = "sErCoMm"; /* 7 */ - -/* 7-11: version control/download control ? */ -static const unsigned char version[4] = { 0x00, 0x01, 0x00, 0x00 }; - - -/* 512 onwards -> ZIP containing rootfs with the same Header */ - -struct file_info { - char* file_name; /* name of the file */ - char* file_data; /* data of the file in memory */ - u_int32_t file_size; /* length of the file */ -}; - -static u_int8_t getCheckSum(char* data, int len) { - u_int8_t new = 0; - - if (!data) { - ERR("Invalid pointer provided!\n"); - return 0; - } - - for (int i = 0; i < len; i++) { - new += data[i]; - } - - return new; -} - -static int bufferFile(struct file_info* finfo) { - int fs = 0; - FILE* fp = NULL; - - if (!finfo || !finfo->file_name) { - ERR("Invalid pointer provided!\n"); - return -1; - } - - DBG("Opening file: %s\n", finfo->file_name); - - if (!(fp = fopen(finfo->file_name, "rb"))) { - ERR("Error opening file: %s\n", finfo->file_name); - return -1; - } - - /* Get filesize */ - rewind(fp); - fseek(fp, 0L, SEEK_END); - fs = ftell(fp); - rewind(fp); - - if (fs < 0) { - ERR("Error getting filesize: %s\n", finfo->file_name); - fclose(fp); - return -1; - } - - DBG("Filesize: %i\n", fs); - finfo->file_size = fs; - - if (!(finfo->file_data = malloc(fs))) { - ERR("Out of memory!\n"); - fclose(fp); - return -1; - } - - if (fread(finfo->file_data, 1, fs, fp) != fs) { - ERR("Error reading file %s\n", finfo->file_name); - fclose(fp); - return -1; - } - - DBG("File: read successful\n"); - fclose(fp); - - return 0; -} - -static int writeFile(struct file_info* finfo) { - FILE* fp; - - if (!finfo || !finfo->file_name) { - ERR("Invalid pointer provided!\n"); - return -1; - } - - DBG("Opening file: %s\n", finfo->file_name); - - if (!(fp = fopen(finfo->file_name, "w"))) { - ERR("Error opening file: %s\n", finfo->file_name); - return -1; - } - - DBG("Writing file: %s\n", finfo->file_name); - - if (fwrite(finfo->file_data, 1, finfo->file_size, fp) != finfo->file_size) { - ERR("Wanted to write, but something went wrong!\n"); - fclose(fp); - return -1; - } - - fclose(fp); - return 0; -} - -static void fi_clean(struct file_info* finfo) { - if (!finfo) - return; - - if (finfo->file_name) { - finfo->file_name = NULL; - } - - if (finfo->file_data) { - free(finfo->file_data); - finfo->file_data = NULL; - } - - finfo->file_size = 0; -} - -static void usage(char* argv[]) { - printf("Usage: %s \n" - "All are positional arguments ... \n" - " sysupgradefile: File with the kernel uimage at 0\n" - " kernel_offset: Offset where the kernel is located (decimal, hex or octal notation)\n" - " HWID: Hardware ID, ASCII\n" - " HWVER: Hardware Version, ASCII\n" - " SWID: Software Version (decimal, hex or octal notation)\n" - " \n" - , argv[0]); -} - -int main(int argc, char* argv[]) { - int ret = 1; - int rootfsname_sz; - int zipfsname_sz; - int zipcmd_sz; - u_int32_t kernel_offset = 0x90000; /* offset for the kernel inside the rootfs, default val */ - u_int32_t swVer = 0; - struct file_info sysupgrade = { 0 }; - struct file_info header = { 0 }; - struct file_info rootfs = { 0 }; - struct file_info zippedfs = { 0 }; - struct file_info image = { 0 }; - char* hwID = NULL; - char* hwVer = NULL; - char* rootfsname = NULL; - char* zipfsname = NULL; - char* zipcmd = NULL; - u_int8_t chkSum; - - if (argc == 2) { - struct file_info myfile = { argv[1], 0, 0 }; - - if (bufferFile(&myfile)) - return 1; - - chkSum = getCheckSum(myfile.file_data, myfile.file_size); - printf("Checksum for File: 0x%hhX\n", chkSum); - - return 0; - } - - if (argc != 6) { - usage(argv); - return 1; - } - - printf("Building fw image for sercomm devices ..\n"); - - /* process args */ - hwID = argv[3]; - hwVer = argv[4]; - - sysupgrade.file_name = argv[1]; - image.file_name = argv[1]; - kernel_offset = (u_int32_t) strtol(argv[2], NULL, 0); - swVer = (u_int32_t) strtol(argv[5], NULL, 0); - swVer = cpu_to_be32(swVer); - - /* Check if files actually exist */ - if (access(sysupgrade.file_name, (F_OK | R_OK))) { - /* Error */ - ERR("File not found: %s\n", sysupgrade.file_name); - goto cleanup; - } - - /* Calculate amount of required memory (incl. 0-term) */ - rootfsname_sz = strlen(sysupgrade.file_name) + 7 + 1; - zipfsname_sz = strlen(sysupgrade.file_name) + 7 + 4 + 1; - - /* Allocate required memory */ - if (!(rootfsname = (char*) malloc(rootfsname_sz)) || !(zipfsname = - (char*) malloc(zipfsname_sz))) { - /* Error */ - ERR("Out of memory!\n"); - goto cleanup; - } - - /* Create filenames */ - if (snprintf(rootfsname, rootfsname_sz, "%s.rootfs", sysupgrade.file_name) - >= rootfsname_sz - || snprintf(zipfsname, zipfsname_sz, "%s.rootfs.zip", - sysupgrade.file_name) >= zipfsname_sz) { - /* Error */ - ERR("Buffer too small!\n"); - goto cleanup; - } - - /* Buffer all files */ - if (bufferFile(&sysupgrade)) { - /* Error */ - goto cleanup; - } - - DBG("Building header: %s %s %2X %s\n", hwID, hwVer, swVer, magic); - - /* Construct the firmware header/magic */ - header.file_name = NULL; - header.file_size = HEADER_SIZE; - - if (!(header.file_data = (char*) calloc(1, HEADER_SIZE))) { - /* Error */ - ERR("Out of memory!\n"); - goto cleanup; - } - - strncpy(header.file_data + 0, magic, 7); - memcpy(header.file_data + 7, version, sizeof(version)); - strncpy(header.file_data + 11, hwID, 34); - strncpy(header.file_data + 45, hwVer, 10); - memcpy(header.file_data + 55, &swVer, sizeof(swVer)); - strncpy(header.file_data + 63, magic, 7); - - DBG("Creating rootfs ..\n"); - - /* Construct a rootfs */ - rootfs.file_name = rootfsname; - rootfs.file_size = ALIGN( - sysupgrade.file_size + kernel_offset + header.file_size, - ROOTFS_ALIGN); - - if (!(rootfs.file_data = calloc(1, rootfs.file_size))) { - /* Error */ - ERR("Out of memory!\n"); - goto cleanup; - } - - /* copy Owrt image to kernel location */ - memcpy(rootfs.file_data + kernel_offset, sysupgrade.file_data, - sysupgrade.file_size); - - /* Append header after the owrt image. The updater searches for it */ - memcpy(rootfs.file_data + kernel_offset + sysupgrade.file_size, - header.file_data, header.file_size); - - /* Write to file */ - if (writeFile(&rootfs)) { - /* Error */ - goto cleanup; - } - - /* Construct a zip */ - DBG("Preparing to zip ..\n"); - - /* now that we got the rootfs, repeat the whole thing again(sorta): - * 1. zip the rootfs */ - zipcmd_sz = 3 + 1 + strlen(zipfsname) + 1 + strlen(rootfs.file_name) + 1; - - if (!(zipcmd = malloc(zipcmd_sz))) { - /* Error */ - ERR("Out of memory!\n"); - goto cleanup; - } - - if (snprintf(zipcmd, zipcmd_sz, "%s %s %s", "zip", zipfsname, - rootfs.file_name) >= zipcmd_sz) { - /* Error */ - ERR("Buffer too small!\n"); - goto cleanup; - } - - if (system(zipcmd)) { - /* Error */ - ERR("Error creating a zip file!\n"); - goto cleanup; - } - - /* and load zipped fs */ - zippedfs.file_name = zipfsname; - - if (bufferFile(&zippedfs)) { - /* Error */ - goto cleanup; - } - - DBG("Creating Image.\n"); - - /* 2. create new file 512 + rootfs size */ - image.file_size = zippedfs.file_size + 512; - if (!(image.file_data = malloc(zippedfs.file_size + 512))) { - /* Error */ - ERR("Out of memory!\n"); - goto cleanup; - } - - /* 3. add header to file */ - memcpy(image.file_data, header.file_data, header.file_size); - - /* 4. clear remaining space */ - if (header.file_size < 512) - memset(image.file_data + header.file_size, 0, 512 - header.file_size); - - /* 5. copy zipfile at loc 512 */ - memcpy(image.file_data + 512, zippedfs.file_data, zippedfs.file_size); - - /* 6. do a checksum run, and compute checksum */ - chkSum = getCheckSum(image.file_data, image.file_size); - - DBG("Checksum for Image: %hhX\n", chkSum); - - /* 7. write the checksum inverted into byte 511 to bring it to 0 on verification */ - chkSum = (chkSum ^ 0xFF) + 1; - image.file_data[511] = (char) chkSum; - - chkSum = getCheckSum(image.file_data, image.file_size); - DBG("Checksum for after fix: %hhX\n", chkSum); - - if (chkSum != 0) { - ERR("Invalid checksum!\n") - goto cleanup; - } - - /* 8. pray that the updater will accept the file */ - if (writeFile(&image)) { - /* Error */ - goto cleanup; - } - - /* All seems OK */ - ret = 0; - - cleanup: - - if (rootfs.file_name && !access(rootfs.file_name, F_OK | W_OK)) - remove(rootfs.file_name); - - if (zippedfs.file_name && !access(zippedfs.file_name, F_OK | W_OK)) - remove(zippedfs.file_name); - - fi_clean(&sysupgrade); - fi_clean(&header); - fi_clean(&rootfs); - fi_clean(&zippedfs); - fi_clean(&image); - - if (rootfsname) - free(rootfsname); - - if (zipfsname) - free(zipfsname); - - if (zipcmd) - free(zipcmd); - - return ret; -} diff --git a/tools/firmware-utils/src/mktitanimg.c b/tools/firmware-utils/src/mktitanimg.c old mode 100755 new mode 100644 diff --git a/tools/firmware-utils/src/mktitanimg.h b/tools/firmware-utils/src/mktitanimg.h old mode 100755 new mode 100644 diff --git a/tools/firmware-utils/src/mktplinkfw-lib.c b/tools/firmware-utils/src/mktplinkfw-lib.c old mode 100755 new mode 100644 diff --git a/tools/firmware-utils/src/mktplinkfw-lib.h b/tools/firmware-utils/src/mktplinkfw-lib.h old mode 100755 new mode 100644 diff --git a/tools/firmware-utils/src/mktplinkfw.c b/tools/firmware-utils/src/mktplinkfw.c old mode 100755 new mode 100644 index ce2acc20c9..ab5fd6d58b --- a/tools/firmware-utils/src/mktplinkfw.c +++ b/tools/firmware-utils/src/mktplinkfw.c @@ -107,7 +107,6 @@ static uint32_t reserved_space; static struct file_info inspect_info; static int extract = 0; static bool endian_swap = false; -static bool rootfs_ofs_calc = false; static const char md5salt_normal[MD5SUM_LEN] = { 0xdc, 0xd7, 0x3a, 0xa5, 0xc3, 0x95, 0x98, 0xfb, @@ -203,7 +202,6 @@ static void usage(int status) " -r read rootfs image from the file \n" " -a align the rootfs start on an bytes boundary\n" " -R overwrite rootfs offset with (hexval prefixed with 0x)\n" -" -O calculate rootfs offset for combined images\n" " -o write output to the file \n" " -s strip padding from the end of the image\n" " -j add jffs2 end-of-filesystem markers\n" @@ -386,10 +384,6 @@ void fill_header(char *buf, int len) hdr->rootfs_len = htonl(rootfs_info.file_size); } - if (combined && rootfs_ofs_calc) { - hdr->rootfs_ofs = htonl(sizeof(struct fw_header) + kernel_len); - } - hdr->ver_hi = htons(fw_ver_hi); hdr->ver_mid = htons(fw_ver_mid); hdr->ver_lo = htons(fw_ver_lo); @@ -545,7 +539,7 @@ int main(int argc, char *argv[]) while ( 1 ) { int c; - c = getopt(argc, argv, "a:H:E:F:L:m:V:N:W:C:ci:k:r:R:o:OxX:ehsjv:"); + c = getopt(argc, argv, "a:H:E:F:L:m:V:N:W:C:ci:k:r:R:o:xX:ehsjv:"); if (c == -1) break; @@ -598,9 +592,6 @@ int main(int argc, char *argv[]) case 'o': ofname = optarg; break; - case 'O': - rootfs_ofs_calc = 1; - break; case 's': strip_padding = 1; break; diff --git a/tools/firmware-utils/src/mktplinkfw2.c b/tools/firmware-utils/src/mktplinkfw2.c old mode 100755 new mode 100644 diff --git a/tools/firmware-utils/src/mkwrggimg.c b/tools/firmware-utils/src/mkwrggimg.c old mode 100755 new mode 100644 diff --git a/tools/firmware-utils/src/mkwrgimg.c b/tools/firmware-utils/src/mkwrgimg.c old mode 100755 new mode 100644 diff --git a/tools/firmware-utils/src/mkzcfw.c b/tools/firmware-utils/src/mkzcfw.c old mode 100755 new mode 100644 diff --git a/tools/firmware-utils/src/mkzynfw.c b/tools/firmware-utils/src/mkzynfw.c old mode 100755 new mode 100644 diff --git a/tools/firmware-utils/src/motorola-bin.c b/tools/firmware-utils/src/motorola-bin.c old mode 100755 new mode 100644 diff --git a/tools/firmware-utils/src/myloader.h b/tools/firmware-utils/src/myloader.h old mode 100755 new mode 100644 diff --git a/tools/firmware-utils/src/nand_ecc.c b/tools/firmware-utils/src/nand_ecc.c old mode 100755 new mode 100644 diff --git a/tools/firmware-utils/src/osbridge-crc.c b/tools/firmware-utils/src/osbridge-crc.c old mode 100755 new mode 100644 diff --git a/tools/firmware-utils/src/oseama.c b/tools/firmware-utils/src/oseama.c old mode 100755 new mode 100644 diff --git a/tools/firmware-utils/src/otrx.c b/tools/firmware-utils/src/otrx.c old mode 100755 new mode 100644 diff --git a/tools/firmware-utils/src/pc1crypt.c b/tools/firmware-utils/src/pc1crypt.c old mode 100755 new mode 100644 diff --git a/tools/firmware-utils/src/ptgen.c b/tools/firmware-utils/src/ptgen.c old mode 100755 new mode 100644 diff --git a/tools/firmware-utils/src/seama.c b/tools/firmware-utils/src/seama.c old mode 100755 new mode 100644 diff --git a/tools/firmware-utils/src/seama.h b/tools/firmware-utils/src/seama.h old mode 100755 new mode 100644 diff --git a/tools/firmware-utils/src/sha1.c b/tools/firmware-utils/src/sha1.c old mode 100755 new mode 100644 diff --git a/tools/firmware-utils/src/sha1.h b/tools/firmware-utils/src/sha1.h old mode 100755 new mode 100644 diff --git a/tools/firmware-utils/src/spw303v.c b/tools/firmware-utils/src/spw303v.c old mode 100755 new mode 100644 diff --git a/tools/firmware-utils/src/srec2bin.c b/tools/firmware-utils/src/srec2bin.c old mode 100755 new mode 100644 diff --git a/tools/firmware-utils/src/tplink-safeloader.c b/tools/firmware-utils/src/tplink-safeloader.c old mode 100755 new mode 100644 index 74ea697634..4b227e1c97 --- a/tools/firmware-utils/src/tplink-safeloader.c +++ b/tools/firmware-utils/src/tplink-safeloader.c @@ -65,7 +65,7 @@ struct image_partition_entry { /** A flash partition table entry */ struct flash_partition_entry { - char *name; + const char *name; uint32_t base; uint32_t size; }; @@ -77,7 +77,7 @@ struct device_info { const char *support_list; char support_trail; const char *soft_ver; - struct flash_partition_entry partitions[MAX_PARTITIONS+1]; + const struct flash_partition_entry partitions[MAX_PARTITIONS+1]; const char *first_sysupgrade_partition; const char *last_sysupgrade_partition; }; @@ -210,17 +210,7 @@ static struct device_info boards[] = { "CPE510(TP-LINK|EU|N300-5):1.1\r\n" "CPE520(TP-LINK|UN|N300-5):1.1\r\n" "CPE520(TP-LINK|US|N300-5):1.1\r\n" - "CPE520(TP-LINK|EU|N300-5):1.1\r\n" - "CPE510(TP-LINK|EU|N300-5|00000000):2.0\r\n" - "CPE510(TP-LINK|EU|N300-5|45550000):2.0\r\n" - "CPE510(TP-LINK|EU|N300-5|55530000):2.0\r\n" - "CPE510(TP-LINK|UN|N300-5|00000000):2.0\r\n" - "CPE510(TP-LINK|UN|N300-5|45550000):2.0\r\n" - "CPE510(TP-LINK|UN|N300-5|55530000):2.0\r\n" - "CPE510(TP-LINK|US|N300-5|55530000):2.0\r\n" - "CPE510(TP-LINK|UN|N300-5):2.0\r\n" - "CPE510(TP-LINK|EU|N300-5):2.0\r\n" - "CPE510(TP-LINK|US|N300-5):2.0\r\n", + "CPE520(TP-LINK|EU|N300-5):1.1\r\n", .support_trail = '\xff', .soft_ver = NULL, @@ -357,46 +347,6 @@ static struct device_info boards[] = { .last_sysupgrade_partition = "file-system" }, - /** Firmware layout for the A7-V5 */ - { - .id = "ARCHER-A7-V5", - .support_list = - "SupportList:\n" - "{product_name:Archer A7,product_ver:5.0.0,special_id:45550000}\n" - "{product_name:Archer A7,product_ver:5.0.0,special_id:55530000}\n" - "{product_name:Archer A7,product_ver:5.0.0,special_id:43410000}\n" - "{product_name:Archer A7,product_ver:5.0.0,special_id:4A500000}\n" - "{product_name:Archer A7,product_ver:5.0.0,special_id:54570000}\n", - .support_trail = '\x00', - .soft_ver = "soft_ver:1.0.0\n", - - /* We're using a dynamic kernel/rootfs split here */ - .partitions = { - {"factory-boot", 0x00000, 0x20000}, - {"fs-uboot", 0x20000, 0x20000}, - {"firmware", 0x40000, 0xec0000}, /* Stock: name os-image base 0x40000 size 0x120000 */ - /* Stock: name file-system base 0x160000 size 0xda0000 */ - {"default-mac", 0xf40000, 0x00200}, - {"pin", 0xf40200, 0x00200}, - {"device-id", 0xf40400, 0x00100}, - {"product-info", 0xf40500, 0x0fb00}, - {"soft-version", 0xf50000, 0x00100}, - {"extra-para", 0xf51000, 0x01000}, - {"support-list", 0xf52000, 0x0a000}, - {"profile", 0xf5c000, 0x04000}, - {"default-config", 0xf60000, 0x10000}, - {"user-config", 0xf70000, 0x40000}, - {"certificate", 0xfb0000, 0x10000}, - {"partition-table", 0xfc0000, 0x10000}, - {"log", 0xfd0000, 0x20000}, - {"radio", 0xff0000, 0x10000}, - {NULL, 0, 0} - }, - - .first_sysupgrade_partition = "os-image", - .last_sysupgrade_partition = "file-system", - }, - /** Firmware layout for the C25v1 */ { .id = "ARCHER-C25-V1", @@ -408,12 +358,16 @@ static struct device_info boards[] = { .support_trail = '\x00', .soft_ver = "soft_ver:1.0.0\n", - /* We're using a dynamic kernel/rootfs split here */ + /** + We use a bigger os-image partition than the stock images (and thus + smaller file-system), as our kernel doesn't fit in the stock firmware's + 1MB os-image. + */ .partitions = { {"factory-boot", 0x00000, 0x20000}, {"fs-uboot", 0x20000, 0x10000}, - {"firmware", 0x30000, 0x7a0000}, /* Stock: name os-image base 0x30000 size 0x100000 */ - /* Stock: name file-system base 0x130000 size 0x6a0000 */ + {"os-image", 0x30000, 0x180000}, /* Stock: base 0x30000 size 0x100000 */ + {"file-system", 0x1b0000, 0x620000}, /* Stock: base 0x130000 size 0x6a0000 */ {"user-config", 0x7d0000, 0x04000}, {"default-mac", 0x7e0000, 0x00100}, {"device-id", 0x7e0100, 0x00100}, @@ -459,7 +413,8 @@ static struct device_info boards[] = { {"profile", 0x11700, 0x03900}, {"default-config", 0x15000, 0x04000}, {"user-config", 0x19000, 0x04000}, - {"firmware", 0x20000, 0x7c8000}, + {"os-image", 0x20000, 0x180000}, + {"file-system", 0x1a0000, 0x648000}, {"certyficate", 0x7e8000, 0x08000}, {"radio", 0x7f0000, 0x10000}, {NULL, 0, 0} @@ -482,14 +437,14 @@ static struct device_info boards[] = { .support_trail = '\x00', .soft_ver = "soft_ver:1.0.0\n", - /* We're using a dynamic kernel/rootfs split here */ .partitions = { {"fs-uboot", 0x00000, 0x10000}, {"default-mac", 0x10000, 0x00200}, {"pin", 0x10200, 0x00200}, {"device-id", 0x10400, 0x00100}, {"product-info", 0x10500, 0x0fb00}, - {"firmware", 0x20000, 0xe30000}, + {"os-image", 0x20000, 0x180000}, + {"file-system", 0x1a0000, 0xcb0000}, {"partition-table", 0xe50000, 0x10000}, {"soft-version", 0xe60000, 0x10000}, {"support-list", 0xe70000, 0x10000}, @@ -508,82 +463,6 @@ static struct device_info boards[] = { .last_sysupgrade_partition = "file-system", }, - /** Firmware layout for the C59v2 */ - { - .id = "ARCHER-C59-V2", - .vendor = "", - .support_list = - "SupportList:\r\n" - "{product_name:Archer C59,product_ver:2.0.0,special_id:00000000}\r\n" - "{product_name:Archer C59,product_ver:2.0.0,special_id:45550000}\r\n" - "{product_name:Archer C59,product_ver:2.0.0,special_id:55530000}\r\n", - .support_trail = '\x00', - .soft_ver = "soft_ver:2.0.0 Build 20161206 rel.7303\n", - - /** We're using a dynamic kernel/rootfs split here */ - .partitions = { - {"factory-boot", 0x00000, 0x20000}, - {"fs-uboot", 0x20000, 0x10000}, - {"default-mac", 0x30000, 0x00200}, - {"pin", 0x30200, 0x00200}, - {"device-id", 0x30400, 0x00100}, - {"product-info", 0x30500, 0x0fb00}, - {"firmware", 0x40000, 0xe10000}, - {"partition-table", 0xe50000, 0x10000}, - {"soft-version", 0xe60000, 0x10000}, - {"support-list", 0xe70000, 0x10000}, - {"profile", 0xe80000, 0x10000}, - {"default-config", 0xe90000, 0x10000}, - {"user-config", 0xea0000, 0x40000}, - {"usb-config", 0xee0000, 0x10000}, - {"certificate", 0xef0000, 0x10000}, - {"extra-para", 0xf00000, 0x10000}, - {"qos-db", 0xf10000, 0x30000}, - {"log", 0xfe0000, 0x10000}, - {"radio", 0xff0000, 0x10000}, - {NULL, 0, 0} - }, - - .first_sysupgrade_partition = "os-image", - .last_sysupgrade_partition = "file-system", - }, - - /** Firmware layout for the C6v2 */ - { - .id = "ARCHER-C6-V2", - .vendor = "", - .support_list = - "SupportList:\r\n" - "{product_name:Archer C6,product_ver:2.0.0,special_id:45550000}\r\n" - "{product_name:Archer C6,product_ver:2.0.0,special_id:52550000}\r\n" - "{product_name:Archer C6,product_ver:2.0.0,special_id:4A500000}\r\n", - .support_trail = '\x00', - .soft_ver = "soft_ver:1.0.0\n", - - .partitions = { - {"fs-uboot", 0x00000, 0x20000}, - {"default-mac", 0x20000, 0x00200}, - {"pin", 0x20200, 0x00100}, - {"product-info", 0x20300, 0x00200}, - {"device-id", 0x20500, 0x0fb00}, - {"firmware", 0x30000, 0x7a9400}, - {"soft-version", 0x7d9400, 0x00100}, - {"extra-para", 0x7d9500, 0x00100}, - {"support-list", 0x7d9600, 0x00200}, - {"profile", 0x7d9800, 0x03000}, - {"default-config", 0x7dc800, 0x03000}, - {"partition-table", 0x7df800, 0x00800}, - {"user-config", 0x7e0000, 0x0c000}, - {"certificate", 0x7ec000, 0x04000}, - {"radio", 0x7f0000, 0x10000}, - {NULL, 0, 0} - }, - - .first_sysupgrade_partition = "os-image", - .last_sysupgrade_partition = "file-system", - }, - - /** Firmware layout for the C60v1 */ { .id = "ARCHER-C60-V1", @@ -608,7 +487,8 @@ static struct device_info boards[] = { {"profile", 0x11700, 0x03900}, {"default-config", 0x15000, 0x04000}, {"user-config", 0x19000, 0x04000}, - {"firmware", 0x20000, 0x7c8000}, + {"os-image", 0x20000, 0x180000}, + {"file-system", 0x1a0000, 0x648000}, {"certyficate", 0x7e8000, 0x08000}, {"radio", 0x7f0000, 0x10000}, {NULL, 0, 0} @@ -637,7 +517,8 @@ static struct device_info boards[] = { {"product-info", 0x1fe00, 0x00100}, {"device-id", 0x1ff00, 0x00100}, {"fs-uboot", 0x20000, 0x10000}, - {"firmware", 0x30000, 0x7a0000}, + {"os-image", 0x30000, 0x180000}, + {"file-system", 0x1b0000, 0x620000}, {"soft-version", 0x7d9500, 0x00100}, {"support-list", 0x7d9600, 0x00100}, {"extra-para", 0x7d9700, 0x00100}, @@ -707,12 +588,16 @@ static struct device_info boards[] = { .support_trail = '\x00', .soft_ver = "soft_ver:1.0.0\n", - /* We're using a dynamic kernel/rootfs split here */ + /** + We use a bigger os-image partition than the stock images (and thus + smaller file-system), as our kernel doesn't fit in the stock firmware's + 1MB os-image. + */ .partitions = { {"factory-boot", 0x00000, 0x20000}, {"fs-uboot", 0x20000, 0x20000}, - {"firmware", 0x40000, 0xEC0000}, /* Stock: name os-image base 0x40000 size 0x120000 */ - /* Stock: name file-system base 0x160000 size 0xda0000 */ + {"os-image", 0x40000, 0x180000}, /* Stock: base 0x40000 size 0x120000 */ + {"file-system", 0x1c0000, 0xd40000}, /* Stock: base 0x160000 size 0xda0000 */ {"default-mac", 0xf00000, 0x00200}, {"pin", 0xf00200, 0x00200}, {"device-id", 0xf00400, 0x00100}, @@ -750,7 +635,11 @@ static struct device_info boards[] = { .support_trail = '\x00', .soft_ver = "soft_ver:1.0.0\n", - /* We're using a dynamic kernel/rootfs split here */ + /** + We use a bigger os-image partition than the stock images (and thus + smaller file-system), as our kernel doesn't fit in the stock firmware's + 1MB os-image. + */ .partitions = { {"factory-boot", 0x00000, 0x20000}, {"fs-uboot", 0x20000, 0x20000}, @@ -767,8 +656,8 @@ static struct device_info boards[] = { {"user-config", 0x80000, 0x40000}, - {"firmware", 0xc0000, 0xf00000}, /* Stock: name os-image base 0xc0000 size 0x120000 */ - /* Stock: name file-system base 0x1e0000 size 0xde0000 */ + {"os-image", 0xc0000, 0x180000}, /* Stock: base 0xc0000 size 0x120000 */ + {"file-system", 0x240000, 0xd80000}, /* Stock: base 0x1e0000 size 0xde0000 */ {"log", 0xfc0000, 0x20000}, {"certificate", 0xfe0000, 0x10000}, @@ -942,7 +831,8 @@ static struct device_info boards[] = { .partitions = { {"factory-boot", 0x00000, 0x20000}, {"fs-uboot", 0x20000, 0x20000}, - {"firmware", 0x40000, 0xec0000}, + {"os-image", 0x40000, 0x180000}, + {"file-system", 0x1c0000, 0xd40000}, {"default-mac", 0xf00000, 0x00200}, {"pin", 0xf00200, 0x00200}, {"device-id", 0xf00400, 0x00100}, @@ -974,10 +864,15 @@ static struct device_info boards[] = { .support_trail = '\x00', .soft_ver = NULL, - /* We're using a dynamic kernel/rootfs split here */ + /** + We use a bigger os-image partition than the stock images (and thus + smaller file-system), as our kernel doesn't fit in the stock firmware's + 1MB os-image. + */ .partitions = { {"fs-uboot", 0x00000, 0x20000}, - {"firmware", 0x20000, 0xf30000}, + {"os-image", 0x20000, 0x180000}, + {"file-system", 0x1a0000, 0xdb0000}, {"default-mac", 0xf50000, 0x00200}, {"pin", 0xf50200, 0x00200}, {"product-info", 0xf50400, 0x0fc00}, @@ -1013,7 +908,8 @@ static struct device_info boards[] = { */ .partitions = { {"fs-uboot", 0x00000, 0x20000}, - {"firmware", 0x20000, 0x730000}, + {"os-image", 0x20000, 0x180000}, + {"file-system", 0x1a0000, 0x5b0000}, {"default-mac", 0x750000, 0x00200}, {"pin", 0x750200, 0x00200}, {"product-info", 0x750400, 0x0fc00}, @@ -1045,7 +941,8 @@ static struct device_info boards[] = { .partitions = { {"fs-uboot", 0x00000, 0x20000}, - {"firmware", 0x20000, 0xe20000}, + {"os-image", 0x20000, 0x180000}, + {"file-system", 0x1a0000, 0xca0000}, {"default-mac", 0xe40000, 0x00200}, {"pin", 0xe40200, 0x00200}, {"product-info", 0xe40400, 0x0fc00}, @@ -1084,10 +981,14 @@ static struct device_info boards[] = { .support_trail = '\x00', .soft_ver = NULL, - /** We're using a dynamic kernel/rootfs split here */ + /** + The original os-image partition is too small, + so we enlarge it to 1.75M + */ .partitions = { {"fs-uboot", 0x00000, 0x20000}, - {"firmware", 0x20000, 0x5e0000}, + {"os-image", 0x20000, 0x1c0000}, + {"file-system", 0x1e0000, 0x420000}, {"partition-table", 0x600000, 0x02000}, {"default-mac", 0x610000, 0x00020}, {"pin", 0x610100, 0x00020}, @@ -1122,10 +1023,15 @@ static struct device_info boards[] = { .support_trail = '\x00', .soft_ver = NULL, - /* We're using a dynamic kernel/rootfs split here */ + /** + The flash partition table for RE355; + it is almost the same as the one used by the stock images, + 576KB were moved from file-system to os-image. + */ .partitions = { {"fs-uboot", 0x00000, 0x20000}, - {"firmware", 0x20000, 0x5e0000}, + {"os-image", 0x20000, 0x180000}, + {"file-system", 0x1a0000, 0x460000}, {"partition-table", 0x600000, 0x02000}, {"default-mac", 0x610000, 0x00020}, {"pin", 0x610100, 0x00020}, @@ -1160,10 +1066,15 @@ static struct device_info boards[] = { .support_trail = '\x00', .soft_ver = NULL, - /** We're using a dynamic kernel/rootfs split here */ + /** + The flash partition table for RE450; + it is almost the same as the one used by the stock images, + 576KB were moved from file-system to os-image. + */ .partitions = { {"fs-uboot", 0x00000, 0x20000}, - {"firmware", 0x20000, 0x5e0000}, + {"os-image", 0x20000, 0x180000}, + {"file-system", 0x1a0000, 0x460000}, {"partition-table", 0x600000, 0x02000}, {"default-mac", 0x610000, 0x00020}, {"pin", 0x610100, 0x00020}, @@ -1181,46 +1092,6 @@ static struct device_info boards[] = { .last_sysupgrade_partition = "file-system" }, - /** Firmware layout for the RE450 v2 */ - { - .id = "RE450-V2", - .vendor = "", - .support_list = - "SupportList:\r\n" - "{product_name:RE450,product_ver:2.0.0,special_id:00000000}\r\n" - "{product_name:RE450,product_ver:2.0.0,special_id:55530000}\r\n" - "{product_name:RE450,product_ver:2.0.0,special_id:45550000}\r\n" - "{product_name:RE450,product_ver:2.0.0,special_id:4A500000}\r\n" - "{product_name:RE450,product_ver:2.0.0,special_id:43410000}\r\n" - "{product_name:RE450,product_ver:2.0.0,special_id:41550000}\r\n" - "{product_name:RE450,product_ver:2.0.0,special_id:41530000}\r\n" - "{product_name:RE450,product_ver:2.0.0,special_id:4B520000}\r\n" - "{product_name:RE450,product_ver:2.0.0,special_id:42520000}\r\n", - .support_trail = '\x00', - .soft_ver = NULL, - - /* We're using a dynamic kernel/rootfs split here */ - .partitions = { - {"fs-uboot", 0x00000, 0x20000}, - {"firmware", 0x20000, 0x5e0000}, - {"partition-table", 0x600000, 0x02000}, - {"default-mac", 0x610000, 0x00020}, - {"pin", 0x610100, 0x00020}, - {"product-info", 0x611100, 0x01000}, - {"soft-version", 0x620000, 0x01000}, - {"support-list", 0x621000, 0x01000}, - {"profile", 0x622000, 0x08000}, - {"user-config", 0x630000, 0x10000}, - {"default-config", 0x640000, 0x10000}, - {"radio", 0x7f0000, 0x10000}, - - {NULL, 0, 0} - }, - - .first_sysupgrade_partition = "os-image", - .last_sysupgrade_partition = "file-system" - }, - {} }; @@ -1356,7 +1227,7 @@ static struct image_partition_entry make_soft_version_from_string(const char *so } /** Generates the support-list partition */ -static struct image_partition_entry make_support_list(struct device_info *info) { +static struct image_partition_entry make_support_list(const struct device_info *info) { size_t len = strlen(info->support_list); struct image_partition_entry entry = alloc_image_partition("support-list", len + 9); @@ -1369,7 +1240,7 @@ static struct image_partition_entry make_support_list(struct device_info *info) } /** Creates a new image partition with an arbitrary name from a file */ -static struct image_partition_entry read_file(const char *part_name, const char *filename, bool add_jffs2_eof, struct flash_partition_entry *file_system_partition) { +static struct image_partition_entry read_file(const char *part_name, const char *filename, bool add_jffs2_eof) { struct stat statbuf; if (stat(filename, &statbuf) < 0) @@ -1378,10 +1249,7 @@ static struct image_partition_entry read_file(const char *part_name, const char size_t len = statbuf.st_size; if (add_jffs2_eof) - if (file_system_partition) - len = ALIGN(len + file_system_partition->base, 0x10000) + sizeof(jffs2_eof_mark) - file_system_partition->base; - else - len = ALIGN(len, 0x10000) + sizeof(jffs2_eof_mark); + len = ALIGN(len, 0x10000) + sizeof(jffs2_eof_mark); struct image_partition_entry entry = alloc_image_partition(part_name, len); @@ -1497,7 +1365,7 @@ static void put_md5(uint8_t *md5, uint8_t *buffer, unsigned int len) { 1014-1813 Image partition table (2048 bytes, padded with 0xff) 1814-xxxx Firmware partitions */ -static void * generate_factory_image(struct device_info *info, const struct image_partition_entry *parts, size_t *len) { +static void * generate_factory_image(const struct device_info *info, const struct image_partition_entry *parts, size_t *len) { *len = 0x1814; size_t i; @@ -1530,7 +1398,7 @@ static void * generate_factory_image(struct device_info *info, const struct imag should be generalized when TP-LINK starts building its safeloader into hardware with different flash layouts. */ -static void * generate_sysupgrade_image(struct device_info *info, const struct image_partition_entry *image_parts, size_t *len) { +static void * generate_sysupgrade_image(const struct device_info *info, const struct image_partition_entry *image_parts, size_t *len) { size_t i, j; size_t flash_first_partition_index = 0; size_t flash_last_partition_index = 0; @@ -1593,53 +1461,10 @@ static void build_image(const char *output, uint32_t rev, bool add_jffs2_eof, bool sysupgrade, - struct device_info *info) { - - size_t i; + const struct device_info *info) { struct image_partition_entry parts[7] = {}; - struct flash_partition_entry *firmware_partition = NULL; - struct flash_partition_entry *os_image_partition = NULL; - struct flash_partition_entry *file_system_partition = NULL; - size_t firmware_partition_index = 0; - - for (i = 0; info->partitions[i].name; i++) { - if (!strcmp(info->partitions[i].name, "firmware")) - { - firmware_partition = &info->partitions[i]; - firmware_partition_index = i; - } - } - - if (firmware_partition) - { - os_image_partition = &info->partitions[firmware_partition_index]; - file_system_partition = &info->partitions[firmware_partition_index + 1]; - - struct stat kernel; - if (stat(kernel_image, &kernel) < 0) - error(1, errno, "unable to stat file `%s'", kernel_image); - - if (kernel.st_size > firmware_partition->size) - error(1, 0, "kernel overflowed firmware partition\n"); - - for (i = MAX_PARTITIONS-1; i >= firmware_partition_index + 1; i--) - info->partitions[i+1] = info->partitions[i]; - - file_system_partition->name = "file-system"; - file_system_partition->base = firmware_partition->base + kernel.st_size; - - /* Align partition start to erase blocks for factory images only */ - if (!sysupgrade) - file_system_partition->base = ALIGN(firmware_partition->base + kernel.st_size, 0x10000); - - file_system_partition->size = firmware_partition->size - file_system_partition->base; - - os_image_partition->name = "os-image"; - os_image_partition->size = kernel.st_size; - } - parts[0] = make_partition_table(info->partitions); if (info->soft_ver) parts[1] = make_soft_version_from_string(info->soft_ver); @@ -1647,22 +1472,18 @@ static void build_image(const char *output, parts[1] = make_soft_version(rev); parts[2] = make_support_list(info); - parts[3] = read_file("os-image", kernel_image, false, NULL); - parts[4] = read_file("file-system", rootfs_image, add_jffs2_eof, file_system_partition); + parts[3] = read_file("os-image", kernel_image, false); + parts[4] = read_file("file-system", rootfs_image, add_jffs2_eof); /* Some devices need the extra-para partition to accept the firmware */ if (strcasecmp(info->id, "ARCHER-C25-V1") == 0 || - strcasecmp(info->id, "ARCHER-C59-V2") == 0 || strcasecmp(info->id, "ARCHER-C60-V2") == 0 || strcasecmp(info->id, "TLWR1043NV5") == 0) { const char mdat[11] = {0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00}; parts[5] = put_data("extra-para", mdat, 11); - } else if (strcasecmp(info->id, "ARCHER-A7-V5") == 0 || strcasecmp(info->id, "ARCHER-C7-V4") == 0 || strcasecmp(info->id, "ARCHER-C7-V5") == 0) { + } else if (strcasecmp(info->id, "ARCHER-C7-V4") == 0 || strcasecmp(info->id, "ARCHER-C7-V5") == 0) { const char mdat[11] = {0x01, 0x00, 0x00, 0x02, 0x00, 0x00, 0xca, 0x00, 0x01, 0x00, 0x00}; parts[5] = put_data("extra-para", mdat, 11); - } else if (strcasecmp(info->id, "ARCHER-C6-V2") == 0) { - const char mdat[11] = {0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00}; - parts[5] = put_data("extra-para", mdat, 11); } size_t len; @@ -1683,6 +1504,7 @@ static void build_image(const char *output, free(image); + size_t i; for (i = 0; parts[i].name; i++) free_image_partition(parts[i]); } @@ -1712,7 +1534,7 @@ static void usage(const char *argv0) { }; -static struct device_info *find_board(const char *id) +static const struct device_info *find_board(const char *id) { struct device_info *board = NULL; @@ -1744,10 +1566,6 @@ static int add_flash_partition( } part_list->name = calloc(1, strlen(name) + 1); - if (!part_list->name) { - error(1, 0, "Unable to allocate memory"); - } - memcpy((char *)part_list->name, name, strlen(name)); part_list->base = base; part_list->size = size; @@ -2046,7 +1864,7 @@ int main(int argc, char *argv[]) { const char *extract_image = NULL, *output_directory = NULL, *convert_image = NULL; bool add_jffs2_eof = false, sysupgrade = false; unsigned rev = 0; - struct device_info *info; + const struct device_info *info; set_source_date_epoch(); while (true) { diff --git a/tools/firmware-utils/src/trx.c b/tools/firmware-utils/src/trx.c old mode 100755 new mode 100644 diff --git a/tools/firmware-utils/src/trx2edips.c b/tools/firmware-utils/src/trx2edips.c old mode 100755 new mode 100644 diff --git a/tools/firmware-utils/src/trx2usr.c b/tools/firmware-utils/src/trx2usr.c old mode 100755 new mode 100644 diff --git a/tools/firmware-utils/src/wrt400n.c b/tools/firmware-utils/src/wrt400n.c old mode 100755 new mode 100644 diff --git a/tools/firmware-utils/src/xorimage.c b/tools/firmware-utils/src/xorimage.c old mode 100755 new mode 100644 index 2ca643faeb..ca6e43742a --- a/tools/firmware-utils/src/xorimage.c +++ b/tools/firmware-utils/src/xorimage.c @@ -20,13 +20,11 @@ #include #include #include -#include #include #include #include static char default_pattern[] = "12345678"; -static int is_hex_pattern; int xor_data(uint8_t *data, size_t len, const uint8_t *pattern, int p_len, int p_off) @@ -45,7 +43,7 @@ void usage(void) __attribute__ (( __noreturn__ )); void usage(void) { - fprintf(stderr, "Usage: xorimage [-i infile] [-o outfile] [-p ] [-x]\n"); + fprintf(stderr, "Usage: xorimage [-i infile] [-o outfile] [-p ]\n"); exit(EXIT_FAILURE); } @@ -58,14 +56,12 @@ int main(int argc, char **argv) char *ifn = NULL; char *ofn = NULL; const char *pattern = default_pattern; - char hex_pattern[128]; - unsigned int hex_buf; int c; int v0, v1, v2; size_t n; int p_len, p_off = 0; - while ((c = getopt(argc, argv, "i:o:p:xh")) != -1) { + while ((c = getopt(argc, argv, "i:o:p:h")) != -1) { switch (c) { case 'i': ifn = optarg; @@ -76,9 +72,6 @@ int main(int argc, char **argv) case 'p': pattern = optarg; break; - case 'x': - is_hex_pattern = true; - break; case 'h': default: usage(); @@ -107,27 +100,6 @@ int main(int argc, char **argv) usage(); } - if (is_hex_pattern) { - int i; - - if ((p_len / 2) > sizeof(hex_pattern)) { - fprintf(stderr, "provided hex pattern is too long\n"); - usage(); - } - - if (p_len % 2 != 0) { - fprintf(stderr, "the number of characters (hex) is incorrect\n"); - usage(); - } - - for (i = 0; i < (p_len / 2); i++) { - if (sscanf(pattern + (i * 2), "%2x", &hex_buf) < 0) { - fprintf(stderr, "invalid hex digit around %d\n", i * 2); - usage(); - } - hex_pattern[i] = (char)hex_buf; - } - } while ((n = fread(buf, 1, sizeof(buf), in)) > 0) { if (n < sizeof(buf)) { @@ -138,12 +110,7 @@ int main(int argc, char **argv) } } - if (is_hex_pattern) { - p_off = xor_data(buf, n, hex_pattern, (p_len / 2), - p_off); - } else { - p_off = xor_data(buf, n, pattern, p_len, p_off); - } + p_off = xor_data(buf, n, pattern, p_len, p_off); if (!fwrite(buf, n, 1, out)) { FWRITE_ERROR: diff --git a/tools/firmware-utils/src/zyimage.c b/tools/firmware-utils/src/zyimage.c old mode 100755 new mode 100644 diff --git a/tools/firmware-utils/src/zynos.h b/tools/firmware-utils/src/zynos.h old mode 100755 new mode 100644 diff --git a/tools/firmware-utils/src/zyxbcm.c b/tools/firmware-utils/src/zyxbcm.c old mode 100755 new mode 100644