Date:2010-04-28 12:46:33 (7 years 6 months ago)
Author:juhosg
Commit:3bed6fa4d458e01828c9b4d56709a8098d540381
Message:backfire: tools/firmware-utils: add size check to the mkplanexfw tool (backport of 21174)

Also pad the image to a 64K boundary.


git-svn-id: svn://svn.openwrt.org/openwrt/branches/backfire@21229 3c298f89-4303-0410-b956-a3cf2f4a3e73
Files: tools/firmware-utils/src/mkplanexfw.c (5 diffs)

Change Details

tools/firmware-utils/src/mkplanexfw.c
4040    char *id;
4141    uint32_t seed;
4242    uint8_t unk[2];
43    uint32_t datalen;
4344};
4445
4546/*
...... 
5859        .id = "MZK-W04NU",
5960        .seed = 2,
6061        .unk = {0x04, 0x08},
62        .datalen = 0x770000,
6163    }, {
6264        .id = "MZK-W300NH",
6365        .seed = 4,
6466        .unk = {0x00, 0x00},
67        .datalen = 0x770000,
6568    }, {
6669        /* terminating entry */
6770    }
...... 
189192        goto err;
190193    }
191194
192    buflen = (st.st_size + 3) & ~3;
193    buflen += sizeof(*hdr);
195    if (st.st_size > board->datalen) {
196        ERR("file '%s' is too big - max size: 0x%08X (exceeds %lu bytes)\n",
197            ifname, board->datalen, st.st_size - board->datalen);
198        goto err;
199    }
194200
201    buflen = board->datalen + 0x10000;
195202    buf = malloc(buflen);
196203    if (!buf) {
197204        ERR("no memory for buffer\n");
...... 
201208    memset(buf, 0xff, buflen);
202209    hdr = (struct planex_hdr *)buf;
203210
204    hdr->datalen = HOST_TO_BE32(buflen - sizeof(*hdr));
211    hdr->datalen = HOST_TO_BE32(board->datalen);
205212    hdr->unk1[0] = board->unk[0];
206213    hdr->unk1[1] = board->unk[1];
207214
...... 
223230    seed = HOST_TO_BE32(board->seed);
224231    sha1_starts(&ctx);
225232    sha1_update(&ctx, (uchar *) &seed, sizeof(seed));
226    sha1_update(&ctx, buf + sizeof(*hdr), buflen - sizeof(*hdr));
233    sha1_update(&ctx, buf + sizeof(*hdr), board->datalen);
227234    sha1_finish(&ctx, hdr->sha1sum);
228235
229236    outfile = fopen(ofname, "w");

Archive Download the corresponding diff file



interactive