Skip to content

Commit 7ca353a

Browse files
committed
[MTD] Improve heuristic for detecting wrong-endian RedBoot partition table
Also limit the amount we scan to one eraseblock. Signed-off-by: David Woodhouse <dwmw2@infradead.org>
1 parent 1119214 commit 7ca353a

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

‎drivers/mtd/redboot.c‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,16 @@ static int parse_redboot_partitions(struct mtd_info *master,
9494
* (NOTE: this is 'size' not 'data_length'; size is
9595
* the full size of the entry.)
9696
*/
97-
if (swab32(buf[i].size) == master->erasesize) {
97+
98+
/* RedBoot can combine the FIS directory and
99+
config partitions into a single eraseblock;
100+
we assume wrong-endian if either the swapped
101+
'size' matches the eraseblock size precisely,
102+
or if the swapped size actually fits in an
103+
eraseblock while the unswapped size doesn't. */
104+
if (swab32(buf[i].size) == master->erasesize ||
105+
(buf[i].size > master->erasesize
106+
&& swab32(buf[i].size) < master->erasesize)) {
98107
int j;
99108
/* Update numslots based on actual FIS directory size */
100109
numslots = swab32(buf[i].size) / sizeof (struct fis_image_desc);
@@ -122,7 +131,7 @@ static int parse_redboot_partitions(struct mtd_info *master,
122131
swab32s(&buf[j].desc_cksum);
123132
swab32s(&buf[j].file_cksum);
124133
}
125-
} else {
134+
} else if (buf[i].size < master->erasesize) {
126135
/* Update numslots based on actual FIS directory size */
127136
numslots = buf[i].size / sizeof(struct fis_image_desc);
128137
}

0 commit comments

Comments
 (0)