diff options
author | Gabor Juhos <juhosg@openwrt.org> | 2011-12-15 22:03:42 +0000 |
---|---|---|
committer | Gabor Juhos <juhosg@openwrt.org> | 2011-12-15 22:03:42 +0000 |
commit | 2e0cc81c4e45b72e87b204b572a1331846f94e27 (patch) | |
tree | 1cd837f7460b044982312a5a31bd071f2dab6739 /tools | |
parent | c0f856759b0b613ca12bfa28af0422e051a03200 (diff) | |
download | upstream-2e0cc81c4e45b72e87b204b572a1331846f94e27.tar.gz upstream-2e0cc81c4e45b72e87b204b572a1331846f94e27.tar.bz2 upstream-2e0cc81c4e45b72e87b204b572a1331846f94e27.zip |
firmware-utils/mktplinkfw: add ability to put jffs2 eof marker into the image
git-svn-id: svn://svn.openwrt.org/openwrt/trunk@29544 3c298f89-4303-0410-b956-a3cf2f4a3e73
Diffstat (limited to 'tools')
-rw-r--r-- | tools/firmware-utils/src/mktplinkfw.c | 46 |
1 files changed, 45 insertions, 1 deletions
diff --git a/tools/firmware-utils/src/mktplinkfw.c b/tools/firmware-utils/src/mktplinkfw.c index 174df957fb..bc3a2f377c 100644 --- a/tools/firmware-utils/src/mktplinkfw.c +++ b/tools/firmware-utils/src/mktplinkfw.c @@ -119,6 +119,8 @@ static uint32_t rootfs_align; static struct file_info boot_info; static int combined; static int strip_padding; +static int add_jffs2_eof; +static unsigned char jffs2_eof_mark[4] = {0xde, 0xad, 0xc0, 0xde}; static struct file_info inspect_info; static int extract = 0; @@ -333,6 +335,7 @@ static void usage(int status) " -R <offset> overwrite rootfs offset with <offset> (hexval prefixed with 0x)\n" " -o <file> write output to the file <file>\n" " -s strip padding from the end of the image\n" +" -j add jffs2 end-of-filesystem markers\n" " -N <vendor> set image vendor to <vendor>\n" " -V <version> set image version to <version>\n" " -i <file> inspect given firmware file <file>\n" @@ -545,6 +548,40 @@ static void fill_header(char *buf, int len) get_md5(buf, len, hdr->md5sum1); } +static int pad_jffs2(char *buf, int currlen) +{ + int len; + uint32_t pad_mask; + + len = currlen; + pad_mask = (64 * 1024); + while ((len < layout->fw_max_len) && (pad_mask != 0)) { + uint32_t mask; + int i; + + for (i = 10; i < 32; i++) { + mask = 1 << i; + if (pad_mask & mask) + break; + } + + len = ALIGN(len, mask); + + for (i = 10; i < 32; i++) { + mask = 1 << i; + if ((len & (mask - 1)) == 0) + pad_mask &= ~mask; + } + + for (i = 0; i < sizeof(jffs2_eof_mark); i++) + buf[len + i] = jffs2_eof_mark[i]; + + len += sizeof(jffs2_eof_mark); + } + + return len; +} + static int write_fw(char *data, int len) { FILE *f; @@ -606,6 +643,7 @@ static int build_fw(void) p = buf + writelen; else p = buf + rootfs_ofs; + ret = read_to_buf(&rootfs_info, p); if (ret) goto out_free_buf; @@ -614,6 +652,9 @@ static int build_fw(void) writelen += rootfs_info.file_size; else writelen = rootfs_ofs + rootfs_info.file_size; + + if (add_jffs2_eof) + writelen = pad_jffs2(buf, writelen); } if (!strip_padding) @@ -855,7 +896,7 @@ int main(int argc, char *argv[]) while ( 1 ) { int c; - c = getopt(argc, argv, "a:B:H:E:F:L:V:N:W:ci:k:r:R:o:xhs"); + c = getopt(argc, argv, "a:B:H:E:F:L:V:N:W:ci:k:r:R:o:xhsj"); if (c == -1) break; @@ -908,6 +949,9 @@ int main(int argc, char *argv[]) case 'i': inspect_info.file_name = optarg; break; + case 'j': + add_jffs2_eof = 1; + break; case 'x': extract = 1; break; |