Upgrade to Linux 2.6.19
[openwrt/staging/yousong.git] / target / linux / generic-2.6 / patches / 050-mtdpart_redboot_byteswap_partition_truncate.patch
1 diff -urN linux-2.6.19.old/drivers/mtd/redboot.c linux-2.6.19.dev/drivers/mtd/redboot.c
2 --- linux-2.6.19.old/drivers/mtd/redboot.c 2006-11-29 22:57:37.000000000 +0100
3 +++ linux-2.6.19.dev/drivers/mtd/redboot.c 2006-12-14 03:13:35.000000000 +0100
4 @@ -92,22 +92,47 @@
5 * swab32(erasesize) then we know we are looking at
6 * a byte swapped FIS directory - swap all the entries!
7 * (NOTE: this is 'size' not 'data_length'; size is
8 - * the full size of the entry.)
9 + * the full size of the entry.)
10 + *
11 + * Handle cases where the FIS directory is less than
12 + * a full erase block (like combine FIS directory
13 + * and RedBoot config).
14 + *
15 + * IMHO the best solution would be to compute the
16 + * flash address of the RedBoot FIS directory and
17 + * compare that with the entry in the FIS directory
18 + * entry swabbed. However, I haven't yet figured out
19 + * how to compute that.
20 */
21 - if (swab32(buf[i].size) == master->erasesize) {
22 +
23 + unsigned long erasesize_mask = master->erasesize -1;
24 + unsigned long eraseaddr_mask = 0xFFFFFFFF ^ erasesize_mask;
25 +
26 + if (((swab32(buf[i].size)+erasesize_mask)
27 + & eraseaddr_mask) == master->erasesize) {
28 int j;
29 - for (j = 0; j < numslots && buf[j].name[0] != 0xff; ++j) {
30 +
31 + /* N.B. The full table being processed so adjust size now */
32 + numslots = swab32(buf[i].size) / sizeof (struct fis_image_desc);
33 + for (j = 0; j < numslots; ++j) {
34 /* The unsigned long fields were written with the
35 * wrong byte sex, name and pad have no byte sex.
36 + *
37 + * Only process non-deleted entries. Don't exit early.
38 */
39 - swab32s(&buf[j].flash_base);
40 - swab32s(&buf[j].mem_base);
41 - swab32s(&buf[j].size);
42 - swab32s(&buf[j].entry_point);
43 - swab32s(&buf[j].data_length);
44 - swab32s(&buf[j].desc_cksum);
45 - swab32s(&buf[j].file_cksum);
46 + if (buf[j].name[0] != 0xff) {
47 + swab32s(&buf[j].flash_base);
48 + swab32s(&buf[j].mem_base);
49 + swab32s(&buf[j].size);
50 + swab32s(&buf[j].entry_point);
51 + swab32s(&buf[j].data_length);
52 + swab32s(&buf[j].desc_cksum);
53 + swab32s(&buf[j].file_cksum);
54 + }
55 }
56 + } else {
57 + /* Update numslots based on actual FIS directory size */
58 + numslots = buf[i].size / sizeof (struct fis_image_desc);
59 }
60 break;
61 }