summaryrefslogtreecommitdiffstats
path: root/tools/firmware-utils
diff options
context:
space:
mode:
Diffstat (limited to 'tools/firmware-utils')
-rw-r--r--tools/firmware-utils/Makefile2
-rw-r--r--[l---------]tools/firmware-utils/src/bcm_tag.h71
-rw-r--r--tools/firmware-utils/src/csysimg.h1
-rw-r--r--tools/firmware-utils/src/fix-u-media-header.c354
-rw-r--r--tools/firmware-utils/src/mkcameofw.c84
-rw-r--r--tools/firmware-utils/src/mkcsysimg.c1
-rw-r--r--tools/firmware-utils/src/mkdapimg.c39
-rw-r--r--tools/firmware-utils/src/mkfwimage2.c2
-rw-r--r--tools/firmware-utils/src/mktplinkfw.c61
-rw-r--r--tools/firmware-utils/src/seama.c529
-rw-r--r--tools/firmware-utils/src/seama.h108
11 files changed, 1220 insertions, 32 deletions
diff --git a/tools/firmware-utils/Makefile b/tools/firmware-utils/Makefile
index 9dca902ae..ce9e1f7ce 100644
--- a/tools/firmware-utils/Makefile
+++ b/tools/firmware-utils/Makefile
@@ -60,6 +60,8 @@ define Host/Compile
$(call cc,mkbrnimg)
$(call cc,mkdapimg)
$(call cc, mkcameofw, -Wall)
+ $(call cc,seama md5)
+ $(call cc,fix-u-media-header cyg_crc32,-Wall)
$(call cc,bixutil)
$(call cc,cvimg)
endef
diff --git a/tools/firmware-utils/src/bcm_tag.h b/tools/firmware-utils/src/bcm_tag.h
index 2e977a2d7..2730edc9a 120000..100644
--- a/tools/firmware-utils/src/bcm_tag.h
+++ b/tools/firmware-utils/src/bcm_tag.h
@@ -1 +1,70 @@
-../../../target/linux/brcm63xx/files/arch/mips/include/asm/mach-bcm63xx/bcm_tag.h \ No newline at end of file
+#ifndef __BCM63XX_TAG_H
+#define __BCM63XX_TAG_H
+
+#define TAGVER_LEN 4 /* Length of Tag Version */
+#define TAGLAYOUT_LEN 4 /* Length of FlashLayoutVer */
+#define SIG1_LEN 20 /* Company Signature 1 Length */
+#define SIG2_LEN 14 /* Company Signature 2 Lenght */
+#define BOARDID_LEN 16 /* Length of BoardId */
+#define ENDIANFLAG_LEN 2 /* Endian Flag Length */
+#define CHIPID_LEN 6 /* Chip Id Length */
+#define IMAGE_LEN 10 /* Length of Length Field */
+#define ADDRESS_LEN 12 /* Length of Address field */
+#define DUALFLAG_LEN 2 /* Dual Image flag Length */
+#define INACTIVEFLAG_LEN 2 /* Inactie Flag Length */
+#define RSASIG_LEN 20 /* Length of RSA Signature in tag */
+#define TAGINFO1_LEN 30 /* Length of vendor information field1 in tag */
+#define FLASHLAYOUTVER_LEN 4 /* Length of Flash Layout Version String tag */
+#define TAGINFO2_LEN 16 /* Length of vendor information field2 in tag */
+#define CRC_LEN 4 /* Length of CRC in bytes */
+#define ALTTAGINFO_LEN 54 /* Alternate length for vendor information; Pirelli */
+
+#define NUM_PIRELLI 2
+#define IMAGETAG_CRC_START 0xFFFFFFFF
+
+#define PIRELLI_BOARDS { \
+ "AGPF-S0", \
+ "DWV-S0", \
+}
+
+/*
+ * The broadcom firmware assumes the rootfs starts the image,
+ * therefore uses the rootfs start (flashImageAddress)
+ * to determine where to flash the image. Since we have the kernel first
+ * we have to give it the kernel address, but the crc uses the length
+ * associated with this address (rootLength), which is added to the kernel
+ * length (kernelLength) to determine the length of image to flash and thus
+ * needs to be rootfs + deadcode (jffs2 EOF marker)
+*/
+
+struct bcm_tag {
+ char tagVersion[TAGVER_LEN]; // 0-3: Version of the image tag
+ char sig_1[SIG1_LEN]; // 4-23: Company Line 1
+ char sig_2[SIG2_LEN]; // 24-37: Company Line 2
+ char chipid[CHIPID_LEN]; // 38-43: Chip this image is for
+ char boardid[BOARDID_LEN]; // 44-59: Board name
+ char big_endian[ENDIANFLAG_LEN]; // 60-61: Map endianness -- 1 BE 0 LE
+ char totalLength[IMAGE_LEN]; // 62-71: Total length of image
+ char cfeAddress[ADDRESS_LEN]; // 72-83: Address in memory of CFE
+ char cfeLength[IMAGE_LEN]; // 84-93: Size of CFE
+ char flashImageStart[ADDRESS_LEN]; // 94-105: Address in memory of image start (kernel for OpenWRT, rootfs for stock firmware)
+ char flashRootLength[IMAGE_LEN]; // 106-115: Size of rootfs for flashing
+ char kernelAddress[ADDRESS_LEN]; // 116-127: Address in memory of kernel
+ char kernelLength[IMAGE_LEN]; // 128-137: Size of kernel
+ char dualImage[DUALFLAG_LEN]; // 138-139: Unused at present
+ char inactiveFlag[INACTIVEFLAG_LEN]; // 140-141: Unused at present
+ char rsa_signature[RSASIG_LEN]; // 142-161: RSA Signature (unused at present; some vendors may use this)
+ char information1[TAGINFO1_LEN]; // 162-191: Compilation and related information (not generated/used by OpenWRT)
+ char flashLayoutVer[FLASHLAYOUTVER_LEN];// 192-195: Version flash layout
+ char fskernelCRC[CRC_LEN]; // 196-199: kernel+rootfs CRC32
+ char information2[TAGINFO2_LEN]; // 200-215: Unused at present except Alice Gate where is is information
+ char imageCRC[CRC_LEN]; // 216-219: CRC32 of image less imagetag (kernel for Alice Gate)
+ char rootfsCRC[CRC_LEN]; // 220-223: CRC32 of rootfs partition
+ char kernelCRC[CRC_LEN]; // 224-227: CRC32 of kernel partition
+ char imageSequence[4]; // 228-231: Image sequence number
+ char rootLength[4]; // 232-235: steal from reserved1 to keep the real root length so we can use in the flash map even after we have change the rootLength to 0 to satisfy devices that check CRC on every boot
+ char headerCRC[CRC_LEN]; // 236-239: CRC32 of header excluding tagVersion
+ char reserved2[16]; // 240-255: Unused at present
+};
+
+#endif /* __BCM63XX_TAG_H */
diff --git a/tools/firmware-utils/src/csysimg.h b/tools/firmware-utils/src/csysimg.h
index 19dfbd433..65ab062f3 100644
--- a/tools/firmware-utils/src/csysimg.h
+++ b/tools/firmware-utils/src/csysimg.h
@@ -49,6 +49,7 @@
#define SIG_BR6114WG SIG_BR6104IPC
#define SIG_BR6524K "2-K-"
#define SIG_BR6524KP "2-KP" /* FIXME: valid? */
+#define SIG_BR6524N "WNRA"
#define SIG_BR6524WG "2-WG" /* FIXME: valid? */
#define SIG_BR6524WP "2-WP" /* FIXME: valid? */
#define SIG_BR6541K "4--K"
diff --git a/tools/firmware-utils/src/fix-u-media-header.c b/tools/firmware-utils/src/fix-u-media-header.c
new file mode 100644
index 000000000..21f184e66
--- /dev/null
+++ b/tools/firmware-utils/src/fix-u-media-header.c
@@ -0,0 +1,354 @@
+/*
+ * Copyright (C) 2012 Gabor Juhos <juhosg@openwrt.org>
+ *
+ * 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 <stdio.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <string.h>
+#include <unistd.h> /* for unlink() */
+#include <libgen.h>
+#include <getopt.h> /* for getopt() */
+#include <stdarg.h>
+#include <errno.h>
+#include <sys/stat.h>
+
+#include "cyg_crc.h"
+
+#include <arpa/inet.h>
+#include <netinet/in.h>
+
+#define IH_MAGIC 0x27051956 /* Image Magic Number */
+#define IH_NMLEN 32 /* Image Name Length */
+
+#define UM_MAGIC 0x55525F46
+#define UM_HEADER_LEN 12
+
+/*
+ * all data in network byte order (aka natural aka bigendian)
+ */
+struct u_media_header {
+ uint32_t ih_magic; /* Image Header Magic Number */
+ uint32_t ih_hcrc; /* Image Header CRC Checksum */
+ uint32_t ih_time; /* Image Creation Timestamp */
+ uint32_t ih_size; /* Image Data Size */
+ uint32_t ih_load; /* Data Load Address */
+ uint32_t ih_ep; /* Entry Point Address */
+ uint32_t ih_dcrc; /* Image Data CRC Checksum */
+ uint8_t ih_os; /* Operating System */
+ uint8_t ih_arch; /* CPU architecture */
+ uint8_t ih_type; /* Image Type */
+ uint8_t ih_comp; /* Compression Type */
+ uint8_t ih_name[IH_NMLEN - UM_HEADER_LEN]; /* Image Name */
+
+ uint32_t ih_UMedia_magic; /* U-Media magic number */
+ uint32_t ih_UMedia_boardID; /* U-Media board ID */
+ uint8_t ih_UMedia_imageType; /* U-Media image type */
+ uint8_t ih_UMedia_LoadDefault; /* U-Media load to factory default setting */
+ uint8_t ih_UMedia_temp1; /* U-Media didn't use this tag */
+ uint8_t ih_UMedia_temp2; /* U-Media didn't use this tag */
+} __attribute__ ((packed));
+
+struct if_info {
+ char *file_name; /* name of the file */
+ uint32_t file_size; /* length of the file */
+};
+
+static char *progname;
+static char *ofname;
+static struct if_info if_info;
+static int factory_defaults;
+static uint32_t board_id;
+static uint8_t image_type;
+
+/*
+ * Message macros
+ */
+#define ERR(fmt, ...) do { \
+ fflush(0); \
+ fprintf(stderr, "[%s] *** error: " fmt "\n", \
+ progname, ## __VA_ARGS__ ); \
+} while (0)
+
+#define ERRS(fmt, ...) do { \
+ int save = errno; \
+ fflush(0); \
+ fprintf(stderr, "[%s] *** error: " fmt " (%s)\n", \
+ progname, ## __VA_ARGS__, strerror(save)); \
+} while (0)
+
+#define DBG(fmt, ...) do { \
+ fprintf(stderr, "[%s] " fmt "\n", progname, ## __VA_ARGS__ ); \
+} while (0)
+
+static void usage(int status)
+{
+ FILE *stream = (status != EXIT_SUCCESS) ? stderr : stdout;
+
+ fprintf(stream, "Usage: %s [OPTIONS...]\n", progname);
+ fprintf(stream,
+"\n"
+"Options:\n"
+" -B <board_id> set board ID to <board_id>\n"
+" -i <file> read input from the file <file>\n"
+" -F load factory defaults\n"
+" -o <file> write output to the file <file>\n"
+" -T <type> set image type to <type>\n"
+" -h show this screen\n"
+ );
+
+ exit(status);
+}
+
+static int str2u32(char *arg, uint32_t *val)
+{
+ char *err = NULL;
+ uint32_t t;
+
+ errno=0;
+ t = strtoul(arg, &err, 0);
+ if (errno || (err==arg) || ((err != NULL) && *err)) {
+ return -1;
+ }
+
+ *val = t;
+ return 0;
+}
+
+static int str2u8(char *arg, uint8_t *val)
+{
+ char *err = NULL;
+ uint32_t t;
+
+ errno=0;
+ t = strtoul(arg, &err, 0);
+ if (errno || (err==arg) || ((err != NULL) && *err)) {
+ return -1;
+ }
+
+ if (t > 255)
+ return -1;
+
+ *val = t;
+ return 0;
+}
+
+static int get_file_stat(struct if_info *fdata)
+{
+ struct stat st;
+ int res;
+
+ if (fdata->file_name == NULL)
+ return 0;
+
+ res = stat(fdata->file_name, &st);
+ if (res){
+ ERRS("stat failed on %s", fdata->file_name);
+ return res;
+ }
+
+ fdata->file_size = st.st_size;
+ return 0;
+}
+
+static int read_to_buf(struct if_info *fdata, char *buf)
+{
+ FILE *f;
+ int ret = EXIT_FAILURE;
+
+ f = fopen(fdata->file_name, "r");
+ if (f == NULL) {
+ ERRS("could not open \"%s\" for reading", fdata->file_name);
+ goto out;
+ }
+
+ errno = 0;
+ fread(buf, fdata->file_size, 1, f);
+ if (errno != 0) {
+ ERRS("unable to read from file \"%s\"", fdata->file_name);
+ goto out_close;
+ }
+
+ ret = EXIT_SUCCESS;
+
+out_close:
+ fclose(f);
+out:
+ return ret;
+}
+
+static int check_options(void)
+{
+ int ret;
+
+ if (ofname == NULL) {
+ ERR("no %s specified", "output file");
+ return -1;
+ }
+
+ if (if_info.file_name == NULL) {
+ ERR("no %s specified", "input file");
+ return -1;
+ }
+
+ ret = get_file_stat(&if_info);
+ if (ret)
+ return ret;
+
+ return 0;
+}
+
+static int write_fw(char *data, int len)
+{
+ FILE *f;
+ int ret = EXIT_FAILURE;
+
+ f = fopen(ofname, "w");
+ if (f == NULL) {
+ ERRS("could not open \"%s\" for writing", ofname);
+ goto out;
+ }
+
+ errno = 0;
+ fwrite(data, len, 1, f);
+ if (errno) {
+ ERRS("unable to write output file");
+ goto out_flush;
+ }
+
+ ret = EXIT_SUCCESS;
+
+out_flush:
+ fflush(f);
+ fclose(f);
+ if (ret != EXIT_SUCCESS) {
+ unlink(ofname);
+ }
+out:
+ return ret;
+}
+
+static int fix_header(void)
+{
+ int buflen;
+ char *buf;
+ uint32_t crc, crc_orig;
+ struct u_media_header *hdr;
+ int ret = EXIT_FAILURE;
+
+ buflen = if_info.file_size;
+ if (buflen < sizeof(*hdr)) {
+ ERR("invalid input file\n");
+ return ret;
+ }
+
+ buf = malloc(buflen);
+ if (!buf) {
+ ERR("no memory for buffer\n");
+ goto out;
+ }
+
+ ret = read_to_buf(&if_info, buf);
+ if (ret)
+ goto out_free_buf;
+
+ hdr = (struct u_media_header *) buf;
+ if (ntohl(hdr->ih_magic) != IH_MAGIC) {
+ ERR("invalid input file, bad magic\n");
+ goto out_free_buf;
+ }
+
+ /* verify header CRC */
+ crc_orig = ntohl(hdr->ih_hcrc);
+ hdr->ih_hcrc = 0;
+ crc = cyg_ether_crc32((unsigned char *)hdr, sizeof(*hdr));
+ if (crc != crc_orig) {
+ ERR("invalid input file, bad header CRC\n");
+ goto out_free_buf;
+ }
+
+ hdr->ih_name[IH_NMLEN - UM_HEADER_LEN - 1] = '\0';
+
+ /* set U-Media specific fields */
+ hdr->ih_UMedia_magic = htonl(UM_MAGIC);
+ hdr->ih_UMedia_boardID = htonl(board_id);
+ hdr->ih_UMedia_imageType = image_type;
+ hdr->ih_UMedia_LoadDefault = (factory_defaults) ? 1 : 0;
+
+ /* update header CRC */
+ crc = cyg_ether_crc32((unsigned char *)hdr, sizeof(*hdr));
+ hdr->ih_hcrc = htonl(crc);
+
+ ret = write_fw(buf, buflen);
+ if (ret)
+ goto out_free_buf;
+
+ DBG("U-Media header fixed in \"%s\"", ofname);
+
+ ret = EXIT_SUCCESS;
+
+out_free_buf:
+ free(buf);
+out:
+ return ret;
+}
+
+int main(int argc, char *argv[])
+{
+ int ret = EXIT_FAILURE;
+
+ progname = basename(argv[0]);
+
+ while (1) {
+ int c;
+
+ c = getopt(argc, argv, "B:Fi:o:T:h");
+ if (c == -1)
+ break;
+
+ switch (c) {
+ case 'B':
+ if (str2u32(optarg, &board_id)) {
+ ERR("%s is invalid '%s'",
+ "board ID", optarg);
+ goto out;
+ }
+ break;
+ case 'T':
+ if (str2u8(optarg, &image_type)) {
+ ERR("%s is invalid '%s'",
+ "image type", optarg);
+ goto out;
+ }
+ break;
+ case 'F':
+ factory_defaults = 1;
+ break;
+ case 'i':
+ if_info.file_name = optarg;
+ break;
+ case 'o':
+ ofname = optarg;
+ break;
+ case 'h':
+ usage(EXIT_SUCCESS);
+ break;
+ default:
+ usage(EXIT_FAILURE);
+ break;
+ }
+ }
+
+ ret = check_options();
+ if (ret)
+ goto out;
+
+ ret = fix_header();
+
+out:
+ return ret;
+}
diff --git a/tools/firmware-utils/src/mkcameofw.c b/tools/firmware-utils/src/mkcameofw.c
index a152eb535..e0da4baf3 100644
--- a/tools/firmware-utils/src/mkcameofw.c
+++ b/tools/firmware-utils/src/mkcameofw.c
@@ -61,6 +61,7 @@ static struct file_info kernel_info;
static struct file_info rootfs_info;
static uint32_t kernel_size;
static uint32_t image_size;
+static int combined;
/*
* Message macros
@@ -91,6 +92,7 @@ static void usage(int status)
"\n"
"Options:\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"
" -o <file> write output to the file <file>\n"
" -r <file> read rootfs image from the file <file>\n"
@@ -196,37 +198,55 @@ static int check_options(void)
CHKSTRLEN(version, "version");
CHKSTR(ofname, "output file");
CHKSTR(kernel_info.file_name, "kernel image");
- CHKSTR(rootfs_info.file_name, "rootfs image");
ret = get_file_stat(&kernel_info);
if (ret)
return ret;
- ret = get_file_stat(&rootfs_info);
- if (ret)
- return ret;
+ if (combined) {
+ if (!kernel_size) {
+ ERR("kernel size must be specified for combined images");
+ return -1; \
+ }
- if (kernel_size) {
- /* override kernel size */
- kernel_info.write_size = kernel_size;
- }
+ if (!image_size)
+ image_size = kernel_info.file_size;
- if (image_size) {
- if (image_size < kernel_info.write_size)
- kernel_info.write_size = image_size;
+ if (kernel_info.file_size > image_size) {
+ ERR("kernel image is too big");
+ return -1;
+ }
- /* override rootfs size */
- rootfs_info.write_size = image_size - kernel_info.write_size;
- }
+ kernel_info.write_size = image_size;
+ } else {
+ CHKSTR(rootfs_info.file_name, "rootfs image");
- if (kernel_info.file_size > kernel_info.write_size) {
- ERR("kernel image is too big");
- return -1;
- }
+ ret = get_file_stat(&rootfs_info);
+ if (ret)
+ return ret;
- if (rootfs_info.file_size > rootfs_info.write_size) {
- ERR("rootfs image is too big");
- return -1;
+ if (kernel_size) {
+ /* override kernel size */
+ kernel_info.write_size = kernel_size;
+ }
+
+ if (image_size) {
+ if (image_size < kernel_info.write_size)
+ kernel_info.write_size = image_size;
+
+ /* override rootfs size */
+ rootfs_info.write_size = image_size - kernel_info.write_size;
+ }
+
+ if (kernel_info.file_size > kernel_info.write_size) {
+ ERR("kernel image is too big");
+ return -1;
+ }
+
+ if (rootfs_info.file_size > rootfs_info.write_size) {
+ ERR("rootfs image is too big");
+ return -1;
+ }
}
return 0;
@@ -301,12 +321,14 @@ static int build_fw(void)
if (ret)
goto out_free_buf;
- p += kernel_info.write_size;
+ if (!combined) {
+ p += kernel_info.write_size;
- /* read rootfs data */
- ret = read_to_buf(&rootfs_info, p);
- if (ret)
- goto out_free_buf;
+ /* read rootfs data */
+ ret = read_to_buf(&rootfs_info, p);
+ if (ret)
+ goto out_free_buf;
+ }
csum = get_csum((unsigned char *)(buf + sizeof(struct img_header)),
buflen - sizeof(struct img_header));
@@ -316,7 +338,10 @@ static int build_fw(void)
hdr->checksum = htonl(csum);
hdr->image_size = htonl(buflen - sizeof(struct img_header));
- hdr->kernel_size = htonl(kernel_info.write_size);
+ if (!combined)
+ hdr->kernel_size = htonl(kernel_info.write_size);
+ else
+ hdr->kernel_size = htonl(kernel_size);
hdr->header_len = sizeof(struct img_header);
strncpy(hdr->model, model, sizeof(hdr->model));
strncpy(hdr->signature, signature, sizeof(hdr->signature));
@@ -344,7 +369,7 @@ int main(int argc, char *argv[])
while (1) {
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)
break;
@@ -381,6 +406,9 @@ int main(int argc, char *argv[])
case 'r':
rootfs_info.file_name = optarg;
break;
+ case 'c':
+ combined = 1;
+ break;
case 'o':
ofname = optarg;
break;
diff --git a/tools/firmware-utils/src/mkcsysimg.c b/tools/firmware-utils/src/mkcsysimg.c
index 4f2352a60..c00096f87 100644
--- a/tools/firmware-utils/src/mkcsysimg.c
+++ b/tools/firmware-utils/src/mkcsysimg.c
@@ -160,6 +160,7 @@ static struct board_info boards[] = {
BOARD_ADM("BR-6114WG", "Edimax BR-6114WG", 2, SIG_BR6114WG),
BOARD_ADM("BR-6524K", "Edimax BR-6524K", 2, SIG_BR6524K),
BOARD_ADM("BR-6524KP", "Edimax BR-6524KP", 2, SIG_BR6524KP),
+ BOARD_ADM("BR-6524N", "Edimax BR-6524N", 2, SIG_BR6524N),
BOARD_ADM("BR-6524WG", "Edimax BR-6524WG", 4, SIG_BR6524WG),
BOARD_ADM("BR-6524WP", "Edimax BR-6524WP", 4, SIG_BR6524WP),
BOARD_ADM("BR-6541K", "Edimax BR-6541K", 2, SIG_BR6541K),
diff --git a/tools/firmware-utils/src/mkdapimg.c b/tools/firmware-utils/src/mkdapimg.c
index 8b0359f74..ed662d8ec 100644
--- a/tools/firmware-utils/src/mkdapimg.c
+++ b/tools/firmware-utils/src/mkdapimg.c
@@ -27,6 +27,8 @@
#define MAX_MODEL_NAME_LEN 20
#define MAX_SIG_LEN 30
+#define MAX_REGION_LEN 4
+#define MAX_VERSION_LEN 12
struct img_hdr_struct {
uint32_t checksum;
@@ -51,7 +53,7 @@ perrexit(int code, char *msg)
void
usage()
{
- fprintf(stderr, "usage: %s [-p] [-m model] -s signature -i input -o output\n", progname);
+ fprintf(stderr, "usage: %s [-p] [-m model] [-r region] [-v version] -s signature -i input -o output\n", progname);
exit(1);
}
@@ -60,8 +62,11 @@ main(int ac, char *av[])
{
char model[MAX_MODEL_NAME_LEN+1];
char signature[MAX_SIG_LEN+1];
+ char region[MAX_REGION_LEN+1];
+ char version[MAX_VERSION_LEN+1];
int patchmode = 0;
int fixmode = 0;
+ int have_regionversion = 0;
FILE *ifile, *ofile;
int c;
@@ -71,11 +76,13 @@ main(int ac, char *av[])
progname = basename(av[0]);
memset(model, 0, sizeof(model));
memset(signature, 0, sizeof(signature));
+ memset(region, 0, sizeof(region));
+ memset(version, 0, sizeof(version));
while ( 1 ) {
int c;
- c = getopt(ac, av, "pxm:s:i:o:");
+ c = getopt(ac, av, "pxm:r:v:s:i:o:");
if (c == -1)
break;
@@ -94,6 +101,24 @@ main(int ac, char *av[])
}
strcpy(model, optarg);
break;
+ case 'r':
+ if (strlen(optarg) > MAX_REGION_LEN) {
+ fprintf(stderr, "%s: region exceeds %d chars\n",
+ progname, MAX_REGION_LEN);
+ exit(1);
+ }
+ have_regionversion = 1;
+ strcpy(region, optarg);
+ break;
+ case 'v':
+ if (strlen(optarg) > MAX_VERSION_LEN) {
+ fprintf(stderr, "%s: version exceeds %d chars\n",
+ progname, MAX_VERSION_LEN);
+ exit(1);
+ }
+ have_regionversion = 1;
+ strcpy(version, optarg);
+ break;
case 's':
if (strlen(optarg) > MAX_SIG_LEN) {
fprintf(stderr, "%s: signature exceeds %d chars\n",
@@ -150,6 +175,10 @@ main(int ac, char *av[])
imghdr.checksum = htonl(cksum);
imghdr.partition = 0 ; // don't care?
imghdr.hdr_len = sizeof(imghdr);
+ if (have_regionversion) {
+ imghdr.hdr_len += MAX_REGION_LEN;
+ imghdr.hdr_len += MAX_VERSION_LEN;
+ }
imghdr.flash_byte_cnt = htonl(bcnt);
} else {
if (ntohl(imghdr.checksum) != cksum) {
@@ -176,6 +205,12 @@ main(int ac, char *av[])
if (fwrite(&imghdr, sizeof(imghdr), 1, ofile) < 0)
perrexit(2, "fwrite header on output");
+ if (have_regionversion) {
+ if (fwrite(&region, MAX_REGION_LEN, 1, ofile) < 0)
+ perrexit(2, "fwrite header on output");
+ if (fwrite(&version, MAX_VERSION_LEN, 1, ofile) < 0)
+ perrexit(2, "fwrite header on output");
+ }
while ((c = fgetc(ifile)) != EOF) {
if (fputc(c, ofile) == EOF)
diff --git a/tools/firmware-utils/src/mkfwimage2.c b/tools/firmware-utils/src/mkfwimage2.c
index ee09abba1..993c3d44e 100644
--- a/tools/firmware-utils/src/mkfwimage2.c
+++ b/tools/firmware-utils/src/mkfwimage2.c
@@ -212,7 +212,7 @@ static int image_layout_add_partition(const char *part_desc)
}
d = &im.parts[im.part_count];
- t = sscanf(part_desc, "%15[a-zA-Z]:%15[0-9a-fA-Fx]:%15[0-9a-fA-Fx]:%15[0-9a-fA-Fx]:%15[0-9a-fA-Fx]:%256s",
+ t = sscanf(part_desc, "%15[0-9a-zA-Z]:%15[0-9a-fA-Fx]:%15[0-9a-fA-Fx]:%15[0-9a-fA-Fx]:%15[0-9a-fA-Fx]:%256s",
d->partition_name,
offset,
length,
diff --git a/tools/firmware-utils/src/mktplinkfw.c b/tools/firmware-utils/src/mktplinkfw.c
index fab208170..74a55fd27 100644
--- a/tools/firmware-utils/src/mktplinkfw.c
+++ b/tools/firmware-utils/src/mktplinkfw.c
@@ -32,16 +32,25 @@
#define HEADER_VERSION_V1 0x01000000
#define HWID_TL_MR3020_V1 0x30200001
#define HWID_TL_MR3220_V1 0x32200001
+#define HWID_TL_MR3220_V2 0x32200002
#define HWID_TL_MR3420_V1 0x34200001
+#define HWID_TL_MR3420_V2 0x34200002
#define HWID_TL_WA701N_V1 0x07010001
+#define HWID_TL_WA7510N_V1 0x75100001
+#define HWID_TL_WA801ND_V1 0x08010001
+#define HWID_TL_WA830RE_V1 0x08300010
+#define HWID_TL_WA830RE_V2 0x08300002
#define HWID_TL_WA901ND_V1 0x09010001
#define HWID_TL_WA901ND_V2 0x09010002
+#define HWID_TL_WDR4900_V1 0x49000001
#define HWID_TL_WR703N_V1 0x07030101
+#define HWID_TL_WR720N_V3 0x07200103
#define HWID_TL_WR741ND_V1 0x07410001
#define HWID_TL_WR741ND_V4 0x07410004
#define HWID_TL_WR740N_V1 0x07400001
#define HWID_TL_WR740N_V3 0x07400003
#define HWID_TL_WR743ND_V1 0x07430001
+#define HWID_TL_WR743ND_V2 0x07430002
#define HWID_TL_WR841N_V1_5 0x08410002
#define HWID_TL_WR841ND_V3 0x08410003
#define HWID_TL_WR841ND_V5 0x08410005
@@ -172,6 +181,12 @@ static struct flash_layout layouts[] = {
.kernel_ep = 0x80060000,
.rootfs_ofs = 0x100000,
}, {
+ .id = "16Mppc",
+ .fw_max_len = 0xf80000,
+ .kernel_la = 0x00000000,
+ .kernel_ep = 0xc0000000,
+ .rootfs_ofs = 0x2a0000,
+ }, {
/* terminating entry */
}
};
@@ -188,16 +203,46 @@ static struct board_info boards[] = {
.hw_rev = 1,
.layout_id = "4M",
}, {
+ .id = "TL-MR3220v2",
+ .hw_id = HWID_TL_MR3220_V2,
+ .hw_rev = 1,
+ .layout_id = "4Mlzma",
+ }, {
.id = "TL-MR3420v1",
.hw_id = HWID_TL_MR3420_V1,
.hw_rev = 1,
.layout_id = "4M",
}, {
+ .id = "TL-MR3420v2",
+ .hw_id = HWID_TL_MR3420_V2,
+ .hw_rev = 1,
+ .layout_id = "4Mlzma",
+ }, {
.id = "TL-WA701Nv1",
.hw_id = HWID_TL_WA701N_V1,
.hw_rev = 1,
.layout_id = "4M",
}, {
+ .id = "TL-WA7510N",
+ .hw_id = HWID_TL_WA7510N_V1,
+ .hw_rev = 1,
+ .layout_id = "4M",
+ }, {
+ .id = "TL-WA801NDv1",
+ .hw_id = HWID_TL_WA801ND_V1,
+ .hw_rev = 1,
+ .layout_id = "4M",
+ }, {
+ .id = "TL-WA830REv1",
+ .hw_id = HWID_TL_WA830RE_V1,
+ .hw_rev = 1,
+ .layout_id = "4M",
+ }, {
+ .id = "TL-WA830REv2",
+ .hw_id = HWID_TL_WA830RE_V2,
+ .hw_rev = 1,
+ .layout_id = "4M",
+ }, {
.id = "TL-WA901NDv1",
.hw_id = HWID_TL_WA901ND_V1,
.hw_rev = 1,
@@ -208,6 +253,11 @@ static struct board_info boards[] = {
.hw_rev = 1,
.layout_id = "4M",
}, {
+ .id = "TL-WDR4900v1",
+ .hw_id = HWID_TL_WDR4900_V1,
+ .hw_rev = 1,
+ .layout_id = "16Mppc",
+ }, {
.id = "TL-WR741NDv1",
.hw_id = HWID_TL_WR741ND_V1,
.hw_rev = 1,
@@ -233,6 +283,11 @@ static struct board_info boards[] = {
.hw_rev = 1,
.layout_id = "4M",
}, {
+ .id = "TL-WR743NDv2",
+ .hw_id = HWID_TL_WR743ND_V2,
+ .hw_rev = 1,
+ .layout_id = "4Mlzma",
+ }, {
.id = "TL-WR841Nv1.5",
.hw_id = HWID_TL_WR841N_V1_5,
.hw_rev = 2,
@@ -283,6 +338,11 @@ static struct board_info boards[] = {
.hw_rev = 1,
.layout_id = "4Mlzma",
}, {
+ .id = "TL-WR720Nv3",
+ .hw_id = HWID_TL_WR720N_V3,
+ .hw_rev = 1,
+ .layout_id = "4Mlzma",
+ }, {
/* terminating entry */
}
};
@@ -365,6 +425,7 @@ static void usage(int status)
" -E <ep> overwrite kernel entry point with <ep> (hexval prefixed with 0x)\n"
" -L <la> overwrite kernel load address with <la> (hexval prefixed with 0x)\n"
" -H <hwid> use hardware id specified with <hwid>\n"
+" -W <hwrev> use hardware revision specified with <hwrev>\n"
" -F <id> use flash layout specified with <id>\n"
" -k <file> read kernel image from the file <file>\n"
" -r <file> read rootfs image from the file <file>\n"
diff --git a/tools/firmware-utils/src/seama.c b/tools/firmware-utils/src/seama.c
new file mode 100644
index 000000000..944ed3a44
--- /dev/null
+++ b/tools/firmware-utils/src/seama.c
@@ -0,0 +1,529 @@
+/* vi: set sw=4 ts=4: */
+/*
+ * Copyright (C) 2008, Alpha Networks, Inc.
+ * Created by David Hsieh <david_hsieh@alphanetworks.com>
+ * All right reserved.
+ *
+ * (SEA)ttle i(MA)ge is the image which used in project seattle.
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * 3. The name of the author may not be used to endorse or promote
+ * products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+ * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#include <stdio.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <stdarg.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include <string.h>
+#include <arpa/inet.h>
+
+#include "md5.h"
+#include "seama.h"
+
+#define PROGNAME "seama"
+#define VERSION "0.20"
+#define MAX_SEAMA_META_SIZE 1024
+#define MAX_META 128
+#define MAX_IMAGE 128
+
+extern int optind;
+extern char * optarg;
+
+static int o_verbose = 0; /* verbose mode. */
+static char * o_dump = NULL; /* Seama file to dump. */
+static char * o_seal = NULL; /* Seal the input images when file name exist. */
+static char * o_extract = NULL; /* Extract the seama file. */
+static char * o_images[MAX_IMAGE];/* The image files to pack or seal */
+static int o_isize = 0; /* number of images */
+static char * o_meta[MAX_META]; /* meta data array */
+static int o_msize = 0; /* size of meta array */
+
+static void verbose(const char * format, ...)
+{
+ va_list marker;
+ if (o_verbose)
+ {
+ va_start(marker, format);
+ vfprintf(stdout, format, marker);
+ va_end(marker);
+ }
+}
+
+static void cleanup_exit(int exit_code)
+{
+ verbose("%s: exit with code %d\n", PROGNAME, exit_code);
+ exit(exit_code);
+}
+
+static void show_usage(int exit_code)
+{
+ printf( PROGNAME " version " VERSION "\n"
+ "usage: " PROGNAME " [OPTIONS]\n"
+ " -h show this help message.\n"
+ " -v verbose mode.\n"
+ " -m {META data} META data.\n"
+ " -d {file} dump the info of the seama file.\n"
+ " -i {input file} image file name.\n"
+ " -s {file} Seal the images to the seama file.\n"
+ " -x {seama file} Extract the seama file.\n"
+ "\n"
+ " SEAMA can pack the input file (with -i) into a seama file.\n"
+ " ex: seama -i target.file\n"
+ " SEAMA can also seal multiple seama files into a single seama file.\n"
+ " ex: seama -s final.file -i taget1.seama -i target2.seama\n"
+ " To extract the raw image from SEAMA, you need to specify the meta.\n"
+ " The first image match the specified meta will be extract to\n"
+ " the output file which was specified with '-x'.\n"
+ " ex: seama -x output -i seama.image -m file=sealpac\n"
+ );
+ cleanup_exit(exit_code);
+}
+
+static int parse_args(int argc, char * argv[])
+{
+ int opt;
+
+ while ((opt = getopt(argc, argv, "hvd:s:i:m:x:")) > 0)
+ {
+ switch (opt)
+ {
+ default: show_usage(-1); break;
+ case 'h': show_usage(0); break;
+ case 'v': o_verbose++; break;
+ case 'd': o_dump = optarg; break;
+ case 's': o_seal = optarg; break;
+ case 'x': o_extract = optarg; break;
+ case 'i':
+ if (o_isize < MAX_IMAGE) o_images[o_isize++] = optarg;
+ else printf("Exceed the maximum acceptable image files.!\n");
+ break;
+ case 'm':
+ if (o_msize < MAX_META) o_meta[o_msize++] = optarg;
+ else printf("Exceed the maximum acceptable META data.!\n");
+ break;
+ }
+ }
+ return 0;
+}
+
+/*******************************************************************/
+
+static size_t calculate_digest(FILE * fh, size_t size, uint8_t * digest)
+{
+ MD5_CTX ctx;
+ size_t bytes_left, bytes_read, i;
+ uint8_t buf[MAX_SEAMA_META_SIZE];
+
+ bytes_left = size ? size : sizeof(buf);
+ bytes_read = 0;
+
+ MD5_Init(&ctx);
+ while (!feof(fh) && !ferror(fh) && bytes_left > 0)
+ {
+ i = bytes_left < sizeof(buf) ? bytes_left : sizeof(buf);
+ i = fread(buf, sizeof(char), i, fh);
+ if (i > 0)
+ {
+ MD5_Update(&ctx, buf, i);
+ bytes_read += i;
+ }
+ if (size) bytes_left -= i;
+ }
+ MD5_Final(digest, &ctx);
+ return bytes_read;
+}
+
+#define READ_BUFF_SIZE 8*1024
+static size_t copy_file(FILE * to, FILE * from)
+{
+ size_t i, fsize = 0;
+ uint8_t buf[READ_BUFF_SIZE];
+
+ while (!feof(from) && !ferror(from))
+ {
+ i = fread(buf, sizeof(uint8_t), READ_BUFF_SIZE, from);
+ if (i > 0)
+ {
+ fsize += i;
+ fwrite(buf, sizeof(uint8_t), i, to);
+ }
+ }
+ return fsize;
+}
+
+static int verify_seama(const char * fname, int msg)
+{
+ FILE * fh = NULL;
+ struct stat st;
+ seamahdr_t shdr;
+ uint8_t checksum[16];
+ uint8_t digest[16];
+ uint8_t buf[MAX_SEAMA_META_SIZE];
+ size_t msize, isize, i;
+ int ret = -1;
+
+#define ERRBREAK(fmt, args...) { if (msg) printf(fmt, ##args); break; }
+
+ do
+ {
+ if (stat(fname, &st) < 0) ERRBREAK("Unable to get the info of '%s'\n",fname);
+ if ((fh = fopen(fname, "r+"))==NULL) ERRBREAK("Unable to open '%s' for reading!\n",fname);
+
+ /* Dump SEAMA header */
+ if (msg) printf("FILE - %s (%d bytes)\n", fname, (int)st.st_size);
+
+ /* SEAMA */
+ while (!feof(fh) && !ferror(fh))
+ {
+ /* read header */
+ if (fread(&shdr, sizeof(shdr), 1, fh) != 1) break;
+
+ /* Check the magic number */
+ if (shdr.magic != htonl(SEAMA_MAGIC)) ERRBREAK("Invalid SEAMA magic. Probably no more SEAMA!\n");
+
+ /* Get the size */
+ isize = ntohl(shdr.size);
+ msize = ntohs(shdr.metasize);
+
+ /* The checksum exist only if size is greater than zero. */
+ if (isize > 0)
+ {
+ if (fread(checksum, sizeof(checksum), 1, fh) != 1)
+ ERRBREAK("Error reading checksum !\n");
+ }
+
+ /* Check the META size. */
+ if (msize > sizeof(buf)) ERRBREAK("META data in SEAMA header is too large!\n");
+
+ /* Read META data. */
+ if (fread(buf, sizeof(char), msize, fh) != msize)
+ ERRBREAK("Unable to read SEAMA META data!\n");
+
+ /* dump header */
+ if (msg)
+ {
+ printf("SEAMA ==========================================\n");
+ printf(" magic : %08x\n", ntohl(shdr.magic));
+ printf(" meta size : %d bytes\n", msize);
+ for (i=0; i<msize; i+=(strlen((const char *)&buf[i])+1))
+ printf(" meta data : %s\n", &buf[i]);
+ printf(" image size : %d bytes\n", isize);
+ }
+
+ /* verify checksum */
+ if (isize > 0)
+ {
+ if (msg)
+ {
+ printf(" checksum : ");
+ for (i=0; i<16; i++) printf("%02X", checksum[i]);
+ printf("\n");
+ }
+
+ /* Calculate the checksum */
+ calculate_digest(fh, isize, digest);
+ if (msg)
+ {
+ printf(" digest : ");
+ for (i=0; i<16; i++) printf("%02X", digest[i]);
+ printf("\n");
+ }
+
+ if (memcmp(checksum, digest, 16)!=0) ERRBREAK("!!ERROR!! checksum error !!\n");
+ ret = 0;
+ }
+ }
+ if (msg) printf("================================================\n");
+ } while (0);
+ if (fh) fclose(fh);
+ return ret;
+}
+
+static size_t write_seama_header(FILE * fh, char * meta[], size_t msize, size_t size)
+{
+ seamahdr_t shdr;
+ size_t i;
+ uint16_t metasize = 0;
+
+ /* Calculate the META size */
+ for (i=0; i<msize; i++) metasize += (strlen(meta[i]) + 1);
+ //+++ let meta data end on 4 alignment by siyou. 2010/3/1 03:58pm
+ metasize = ((metasize+3)/4)*4;
+ verbose("SEAMA META : %d bytes\n", metasize);
+
+ /* Fill up the header, all the data endian should be network byte order. */
+ shdr.magic = htonl(SEAMA_MAGIC);
+ shdr.reserved = 0;
+ shdr.metasize = htons(metasize);
+ shdr.size = htonl(size);
+
+ /* Write the header */
+ return fwrite(&shdr, sizeof(seamahdr_t), 1, fh);
+}
+
+static size_t write_checksum(FILE * fh, uint8_t * checksum)
+{
+ return fwrite(checksum, sizeof(uint8_t), 16, fh);
+}
+
+static size_t write_meta_data(FILE * fh, char * meta[], size_t size)
+{
+ size_t i,j;
+ size_t ret = 0;
+
+ for (i=0; i<size; i++)
+ {
+ verbose("SEAMA META data : %s\n", meta[i]);
+ j = fwrite(meta[i], sizeof(char), strlen(meta[i])+1, fh);
+ if (j != strlen(meta[i])+1) return 0;
+ ret += j;
+ }
+ //+++ let meta data end on 4 alignment by siyou. 2010/3/1 03:58pm
+ j = ((ret+3)/4)*4;
+ for ( ; ret < j; ret++)
+ fwrite("", sizeof(char), 1, fh);
+
+ return ret;
+}
+
+/*******************************************************************/
+
+static void dump_seama(const char * fname)
+{
+ verify_seama(fname, 1);
+}
+
+static void seal_files(const char * file)
+{
+ FILE * fh;
+ FILE * ifh;
+ size_t i;
+
+ /* Each image should be seama. */
+ for (i = 0; i < o_isize; i++)
+ {
+ if (verify_seama(o_images[i], 0) < 0)
+ {
+ printf("'%s' is not a seama file !\n",o_images[i]);
+ return;
+ }
+ }
+
+ /* Open file for write */
+ fh = fopen(file, "w+");
+ if (fh)
+ {
+ /* Write the header. */
+ write_seama_header(fh, o_meta, o_msize, 0);
+ write_meta_data(fh, o_meta, o_msize);
+
+ /* Write image files */
+ for (i=0; i<o_isize; i++)
+ {
+ ifh = fopen(o_images[i], "r+");
+ if (ifh)
+ {
+ copy_file(fh, ifh);
+ fclose(ifh);
+ }
+ }
+
+ fclose(fh);
+ }
+}
+
+static void pack_files(void)
+{
+ FILE * fh;
+ FILE * ifh;
+ size_t i, fsize;
+ char filename[512];
+ uint8_t digest[16];
+
+ for (i=0; i<o_isize; i++)
+ {
+ /* Open the input file. */
+ ifh = fopen(o_images[i], "r+");
+ if (ifh)
+ {
+ fsize = calculate_digest(ifh, 0, digest);
+ verbose("file size (%s) : %d\n", o_images[i], fsize);
+ rewind(ifh);
+
+ /* Open the output file. */
+ sprintf(filename, "%s.seama", o_images[i]);
+ fh = fopen(filename, "w+");
+ if (fh)
+ {
+ write_seama_header(fh, o_meta, o_msize, fsize);
+ write_checksum(fh, digest);
+ write_meta_data(fh, o_meta, o_msize);
+ copy_file(fh, ifh);
+ fclose(fh);
+ }
+ fclose(ifh);
+ }
+ else
+ {
+ printf("Unable to open image file '%s'\n",o_images[i]);
+ }
+ }
+}
+
+/**************************************************************************/
+
+static int match_meta(const char * meta, size_t size)
+{
+ size_t i, j;
+ int match;
+
+ for (i = 0; i < o_msize; i++)
+ {
+ for (match = 0, j = 0; j < size; j += (strlen(&meta[j])+1))
+ if (strcmp(&meta[j], o_meta[i])==0) { match++; break; }
+ if (!match) return 0;
+ }
+ return 1;
+}
+
+
+static void extract_file(const char * output)
+{
+ FILE * ifh = NULL;
+ FILE * ofh = NULL;
+ size_t msize, isize, i, m;
+ seamahdr_t shdr;
+ uint8_t buf[MAX_SEAMA_META_SIZE];
+ int done = 0;
+
+ /* We need meta for searching the target image. */
+ if (o_msize == 0)
+ {
+ printf("SEAMA: need meta for searching image.\n");
+ return;
+ }
+
+ /* Walk through each input file */
+ for (i = 0; i < o_isize; i++)
+ {
+ /* verify the input file */
+ if (verify_seama(o_images[i], 0) < 0)
+ {
+ printf("SEAMA: '%s' is not a seama file !\n", o_images[i]);
+ continue;
+ }
+ /* open the input file */
+ ifh = fopen(o_images[i], "r");
+ if (!ifh) continue;
+ /* read file */
+ while (!feof(ifh) && !ferror(ifh))
+ {
+ /* read header */
+ fread(&shdr, sizeof(shdr), 1, ifh);
+ if (shdr.magic != htonl(SEAMA_MAGIC)) break;
+ /* Get the size */
+ isize = ntohl(shdr.size);
+ msize = ntohs(shdr.metasize);
+ if (isize == 0)
+ {
+ while (msize > 0)
+ {
+ m = fread(buf, sizeof(char), (msize < MAX_SEAMA_META_SIZE) ? msize : MAX_SEAMA_META_SIZE, ifh);
+ if (m <= 0) break;
+ msize -= m;
+ }
+ continue;
+ }
+ /* read checksum */
+ fread(buf, sizeof(char), 16, ifh);
+ if (msize > 0)
+ {
+ /* read META */
+ fread(buf, sizeof(char), msize, ifh);
+ if (match_meta((const char *)buf, msize))
+ {
+ printf("SEAMA: found image @ '%s', image size: %d\n", o_images[i], isize);
+ /* open output file */
+ ofh = fopen(output, "w");
+ if (!ofh) printf("SEAMA: unable to open '%s' for writting.\n",output);
+ else
+ {
+ while (isize > 0)
+ {
+ m = fread(buf, sizeof(char), (isize < MAX_SEAMA_META_SIZE) ? isize : MAX_SEAMA_META_SIZE, ifh);
+ if (m <= 0) break;
+ fwrite(buf, sizeof(char), m, ofh);
+ isize -= m;
+ }
+ fclose(ofh);
+ }
+ done++;
+ break;
+ }
+ }
+ while (isize > 0)
+ {
+ m = fread(buf, sizeof(char), (isize < MAX_SEAMA_META_SIZE) ? isize : MAX_SEAMA_META_SIZE, ifh);
+ if (m <= 0) break;
+ isize -= m;
+ }
+ }
+ /* close the file. */
+ fclose(ifh);
+ if (done) break;
+ }
+ return;
+}
+
+/*******************************************************************/
+#ifdef RGBIN_BOX
+int seama_main(int argc, char * argv[], char * env[])
+#else
+int main(int argc, char * argv[], char * env[])
+#endif
+{
+ verbose("SEAMA version " VERSION "\n");
+
+ /* parse the arguments */
+ if (parse_args(argc, argv) < 0) show_usage(9);
+
+ /* Do the works */
+ if (o_dump) dump_seama(o_dump);
+ else if (o_seal) seal_files(o_seal);
+ else if (o_extract) extract_file(o_extract);
+ else pack_files();
+
+ cleanup_exit(0);
+ return 0;
+}
diff --git a/tools/firmware-utils/src/seama.h b/tools/firmware-utils/src/seama.h
new file mode 100644
index 000000000..02683b6e9
--- /dev/null
+++ b/tools/firmware-utils/src/seama.h
@@ -0,0 +1,108 @@
+/* vi: set sw=4 ts=4: */
+/*
+ * (SEA)ttle i(MA)ge is the image which used in project seattle.
+ *
+ * Created by David Hsieh <david_hsieh@alphanetworks.com>
+ * Copyright (C) 2008-2009 Alpha Networks, Inc.
+ *
+ * This file is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either'
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * The GNU C Library is distributed in the hope that it will be useful,'
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with the GNU C Library; if not, write to the Free
+ * Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ * 02111-1307 USA.
+ */
+
+#ifndef __SEAMA_HEADER_FILE__
+#define __SEAMA_HEADER_FILE__
+
+#include <stdint.h>
+
+#define SEAMA_MAGIC 0x5EA3A417
+
+/*
+ * SEAMA looks like the following map.
+ * All the data of the header should be in network byte order.
+ *
+ * +-------------+-------------+------------
+ * | SEAMA magic | ^
+ * +-------------+-------------+ |
+ * | reserved | meta size | |
+ * +-------------+-------------+ header
+ * | image size (0 bytes) | |
+ * +-------------+-------------+ |
+ * ~ Meta data ~ v
+ * +-------------+-------------+------------
+ * | SEAMA magic | ^ ^
+ * +-------------+-------------+ | |
+ * | reserved | meta size | | |
+ * +-------------+-------------+ | |
+ * | image size | | |
+ * +-------------+-------------+ header |
+ * | | | |
+ * | 16 bytes of MD5 digest | | |
+ * | | | |
+ * | | | |
+ * +-------------+-------------+ | |
+ * ~ Meta data ~ v |
+ * +-------------+-------------+------- |
+ * | | |
+ * | Image of the 1st entity | |
+ * ~ ~ 1st entity
+ * | | |
+ * | | v
+ * +-------------+-------------+-------------
+ * | SEAMA magic | ^ ^
+ * +-------------+-------------+ | |
+ * | reserved | meta size | | |
+ * +-------------+-------------+ | |
+ * | image size | | |
+ * +-------------+-------------+ header |
+ * | | | |
+ * | 16 bytes of MD5 digest | | |
+ * | | | |
+ * | | | |
+ * +-------------+-------------+ | |
+ * ~ Meta data ~ v |
+ * +-------------+-------------+------- |
+ * | | |
+ * | Image of the 2nd entity | |
+ * ~ ~ 2nd entity
+ * | | |
+ * | | v
+ * +-------------+-------------+-------------
+ */
+
+
+/*
+ * SEAMA header
+ *
+ * |<-------- 32 bits -------->|
+ * +-------------+-------------+
+ * | SEAMA magic |
+ * +-------------+-------------+
+ * | reserved | meta size |
+ * +-------------+-------------+
+ * | image size |
+ * +-------------+-------------+
+ */
+/* seama header */
+typedef struct seama_hdr seamahdr_t;
+struct seama_hdr
+{
+ uint32_t magic; /* should always be SEAMA_MAGIC. */
+ uint16_t reserved; /* reserved for */
+ uint16_t metasize; /* size of the META data */
+ uint32_t size; /* size of the image */
+} __attribute__ ((packed));
+
+
+#endif