| Date: | 2010-04-28 12:46:33 (13 years 7 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 | ||
|---|---|---|
| 40 | 40 | char *id; |
| 41 | 41 | uint32_t seed; |
| 42 | 42 | uint8_t unk[2]; |
| 43 | uint32_t datalen; | |
| 43 | 44 | }; |
| 44 | 45 | |
| 45 | 46 | /* |
| ... | ... | |
| 58 | 59 | .id = "MZK-W04NU", |
| 59 | 60 | .seed = 2, |
| 60 | 61 | .unk = {0x04, 0x08}, |
| 62 | .datalen = 0x770000, | |
| 61 | 63 | }, { |
| 62 | 64 | .id = "MZK-W300NH", |
| 63 | 65 | .seed = 4, |
| 64 | 66 | .unk = {0x00, 0x00}, |
| 67 | .datalen = 0x770000, | |
| 65 | 68 | }, { |
| 66 | 69 | /* terminating entry */ |
| 67 | 70 | } |
| ... | ... | |
| 189 | 192 | goto err; |
| 190 | 193 | } |
| 191 | 194 | |
| 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 | } | |
| 194 | 200 | |
| 201 | buflen = board->datalen + 0x10000; | |
| 195 | 202 | buf = malloc(buflen); |
| 196 | 203 | if (!buf) { |
| 197 | 204 | ERR("no memory for buffer\n"); |
| ... | ... | |
| 201 | 208 | memset(buf, 0xff, buflen); |
| 202 | 209 | hdr = (struct planex_hdr *)buf; |
| 203 | 210 | |
| 204 | hdr->datalen = HOST_TO_BE32(buflen - sizeof(*hdr)); | |
| 211 | hdr->datalen = HOST_TO_BE32(board->datalen); | |
| 205 | 212 | hdr->unk1[0] = board->unk[0]; |
| 206 | 213 | hdr->unk1[1] = board->unk[1]; |
| 207 | 214 | |
| ... | ... | |
| 223 | 230 | seed = HOST_TO_BE32(board->seed); |
| 224 | 231 | sha1_starts(&ctx); |
| 225 | 232 | 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); | |
| 227 | 234 | sha1_finish(&ctx, hdr->sha1sum); |
| 228 | 235 | |
| 229 | 236 | outfile = fopen(ofname, "w"); |
