diff options
author | Petr Štetiar <ynezz@true.cz> | 2021-07-05 11:54:26 +0200 |
---|---|---|
committer | Rafał Miłecki <rafal@milecki.pl> | 2021-10-05 16:20:10 +0200 |
commit | 8cc9a74a3f6bf363645efda6db417f8dadd3d844 (patch) | |
tree | 68f1648a077df8e49328f087eccaf94c2e47d1e8 /tools/firmware-utils/src/mkheader_gemtek.c | |
parent | f82c93b93c0a021921ac7a30ba6e7a090c7ddd1c (diff) | |
download | upstream-8cc9a74a3f6bf363645efda6db417f8dadd3d844.tar.gz upstream-8cc9a74a3f6bf363645efda6db417f8dadd3d844.tar.bz2 upstream-8cc9a74a3f6bf363645efda6db417f8dadd3d844.zip |
firmware-utils: update to version 2021-10-05
Includes following changes:
db65821f006c cmake: fix missing install target
3a0cfc856991 Add initial GitLab CI support
8f47adea6f87 Add missing includes for byte swap operations
fbafae9f8037 Convert to CMake based project
Additionaly moves source code into separate Git project repository and
converts the package build to utilize CMake.
Signed-off-by: Petr Štetiar <ynezz@true.cz>
[rmilecki: rebase, update to the latest repo git & rm -r src]
Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
Diffstat (limited to 'tools/firmware-utils/src/mkheader_gemtek.c')
-rw-r--r-- | tools/firmware-utils/src/mkheader_gemtek.c | 198 |
1 files changed, 0 insertions, 198 deletions
diff --git a/tools/firmware-utils/src/mkheader_gemtek.c b/tools/firmware-utils/src/mkheader_gemtek.c deleted file mode 100644 index ab72a644ef..0000000000 --- a/tools/firmware-utils/src/mkheader_gemtek.c +++ /dev/null @@ -1,198 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-or-later -/* - * Copyright (C) 2014 Claudio Leite <leitec@staticky.com> - */ - -/* - * Builds a proper flash image for routers using some Gemtek - * OEM boards. These include the Airlink101 AR725W, the - * Asante SmartHub 600 (AWRT-600N), and Linksys WRT100/110. - * - * The resulting image is compatible with the factory firmware - * web upgrade and TFTP interface. - * - * To build: - * gcc -O2 -o mkheader_gemtek mkheader_gemtek.c -lz - * - * Claudio Leite <leitec@staticky.com> - */ - -#include <stdio.h> -#include <stdlib.h> -#include <stdint.h> -#include <string.h> - -#include <zlib.h> /* for crc32() */ - -/* - * The header is in little-endian format. In case - * we are on a BE host, we need to swap binary - * values. - */ -#ifdef __APPLE__ -# include <libkern/OSByteOrder.h> -# define le32 OSSwapHostToLittleInt32 -#else -# if defined(__linux__) -# include <endian.h> -# if __BYTE_ORDER == __BIG_ENDIAN -# define CPU_BIG_ENDIAN -# endif -# else -# include <sys/endian.h> /* BSD's should have this */ -# if _BYTE_ORDER == _BIG_ENDIAN -# define CPU_BIG_ENDIAN -# endif -# endif -# ifdef CPU_BIG_ENDIAN -# define le32(x) (((x & 0xff000000) >> 24) | \ - ((x & 0x00ff0000) >> 8) | \ - ((x & 0x0000ff00) << 8) | \ - ((x & 0x000000ff) << 24)) -# else -# define le32(x) (x) -# endif -#endif - -struct gemtek_header { - uint8_t magic[4]; - uint8_t version[4]; - uint32_t product_id; - uint32_t imagesz; - uint32_t checksum; - uint32_t fast_checksum; - uint8_t build[4]; - uint8_t lang[4]; -}; - -#define HDRLEN sizeof(struct gemtek_header) - -struct machines { - char *desc; - char *id; - uint32_t maxsize; - struct gemtek_header header; -}; - -struct machines mach_def[] = { - {"Airlink101 AR725W", "ar725w", 0x340000, - {"GMTK", "1003", le32(0x03000001), 0, 0, - 0, "01\0\0", "EN\0\0"}}, - {"Asante AWRT-600N", "awrt600n", 0x340000, - {"A600", "1005", le32(0x03000001), 0, 0, - 0, "01\0\0", "EN\0\0"}}, - {"Linksys WRT100", "wrt100", 0x320000, - {"GMTK", "1007", le32(0x03040001), 0, 0, - 0, "2\0\0\0", "EN\0\0"}}, - {"Linksys WRT110", "wrt110", 0x320000, - {"GMTK", "1007", le32(0x03040001), 0, 0, - 0, "2\0\0\0", "EN\0\0"}}, - {0} -}; - -int -main(int argc, char *argv[]) -{ - unsigned long res, flen; - struct gemtek_header my_hdr; - FILE *f, *f_out; - int image_type = -1, index; - uint8_t *buf; - uint32_t crc; - - if (argc < 3) { - fprintf(stderr, "mkheader_gemtek <uImage> <webflash image> [machine ID]\n"); - fprintf(stderr, " where [machine ID] is one of:\n"); - for (index = 0; mach_def[index].desc != 0; index++) { - fprintf(stderr, " %-10s %s", mach_def[index].id, mach_def[index].desc); - if (index == 0) - fprintf(stderr, " (default)\n"); - else - fprintf(stderr, "\n"); - } - - exit(-1); - } - - if (argc == 4) { - for(index = 0; mach_def[index].id != 0; index++) { - if(strcmp(mach_def[index].id, argv[3]) == 0) { - image_type = index; - break; - } - } - - if(image_type == -1) { - fprintf(stderr, "\nERROR: invalid machine type\n"); - exit(-1); - } - } else - image_type = 0; - - printf("Opening %s...\n", argv[1]); - - f = fopen(argv[1], "r"); - if(!f) { - fprintf(stderr, "\nERROR: couldn't open input image\n"); - exit(-1); - } - - fseek(f, 0, SEEK_END); - flen = (unsigned long) ftell(f); - - printf(" %lu (0x%lX) bytes long\n", flen, flen); - - if (flen > mach_def[image_type].maxsize) { - fprintf(stderr, "\nERROR: image exceeds maximum compatible size\n"); - goto f_error; - } - - buf = malloc(flen + HDRLEN); - if (!buf) { - fprintf(stderr, "\nERROR: couldn't allocate buffer\n"); - goto f_error; - } - rewind(f); - res = fread(buf + HDRLEN, 1, flen, f); - if (res != flen) { - perror("Couldn't read entire file: fread()"); - goto f_error; - } - fclose(f); - - printf("\nCreating %s...\n", argv[2]); - - memcpy(&my_hdr, &mach_def[image_type].header, HDRLEN); - - printf(" Using %s magic\n", mach_def[image_type].desc); - - my_hdr.imagesz = le32(flen + HDRLEN); - memcpy(my_hdr.lang, "EN", 2); - - memcpy(buf, &my_hdr, HDRLEN); - - crc = crc32(0, buf, flen + HDRLEN); - printf(" CRC32: %08X\n", crc); - - my_hdr.checksum = le32(crc); - memcpy(buf, &my_hdr, HDRLEN); - - printf(" Writing...\n"); - - f_out = fopen(argv[2], "w"); - if(!f_out) { - fprintf(stderr, "\nERROR: couldn't open output image\n"); - exit(-1); - } - - fwrite(buf, 1, flen + HDRLEN, f_out); - - fclose(f_out); - - free(buf); - return 0; - -f_error: - fclose(f); - exit(-1); -} |