Skip to content

Commit c2607f7

Browse files
Nicolas PitreRussell King
authored andcommitted
ARM: 8294/1: ATAG_DTB_COMPAT: remove the DT workspace's hardcoded 64KB size
There is currently a hardcoded limit of 64KB for the DTB to live in and be extended with ATAG info. Some DTBs have outgrown that limit: $ du -b arch/arm/boot/dts/omap3-n900.dtb 70212 arch/arm/boot/dts/omap3-n900.dtb Furthermore, the actual size passed to atags_to_fdt() included the stack size which is obviously wrong. The initial DTB size is known, so use it to size the allocated workspace with a 50% growth assumption and relocate the temporary stack above that. This is also clamped to 32KB min / 1MB max for robustness against bad DTB data. Reported-by: Pali Rohár <[email protected]> Tested-by: Pavel Machek <[email protected]> Signed-off-by: Nicolas Pitre <[email protected]> Signed-off-by: Russell King <[email protected]>
1 parent c2273a1 commit c2607f7

File tree

1 file changed

+30
-9
lines changed
  • arch/arm/boot/compressed

1 file changed

+30
-9
lines changed

arch/arm/boot/compressed/head.S

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -263,16 +263,37 @@ restart: adr r0, LC0
263263
* OK... Let's do some funky business here.
264264
* If we do have a DTB appended to zImage, and we do have
265265
* an ATAG list around, we want the later to be translated
266-
* and folded into the former here. To be on the safe side,
267-
* let's temporarily move the stack away into the malloc
268-
* area. No GOT fixup has occurred yet, but none of the
269-
* code we're about to call uses any global variable.
266+
* and folded into the former here. No GOT fixup has occurred
267+
* yet, but none of the code we're about to call uses any
268+
* global variable.
270269
*/
271-
add sp, sp, #0x10000
270+
271+
/* Get the initial DTB size */
272+
ldr r5, [r6, #4]
273+
#ifndef __ARMEB__
274+
/* convert to little endian */
275+
eor r1, r5, r5, ror #16
276+
bic r1, r1, #0x00ff0000
277+
mov r5, r5, ror #8
278+
eor r5, r5, r1, lsr #8
279+
#endif
280+
/* 50% DTB growth should be good enough */
281+
add r5, r5, r5, lsr #1
282+
/* preserve 64-bit alignment */
283+
add r5, r5, #7
284+
bic r5, r5, #7
285+
/* clamp to 32KB min and 1MB max */
286+
cmp r5, #(1 << 15)
287+
movlo r5, #(1 << 15)
288+
cmp r5, #(1 << 20)
289+
movhi r5, #(1 << 20)
290+
/* temporarily relocate the stack past the DTB work space */
291+
add sp, sp, r5
292+
272293
stmfd sp!, {r0-r3, ip, lr}
273294
mov r0, r8
274295
mov r1, r6
275-
sub r2, sp, r6
296+
mov r2, r5
276297
bl atags_to_fdt
277298

278299
/*
@@ -285,11 +306,11 @@ restart: adr r0, LC0
285306
bic r0, r0, #1
286307
add r0, r0, #0x100
287308
mov r1, r6
288-
sub r2, sp, r6
309+
mov r2, r5
289310
bleq atags_to_fdt
290311

291312
ldmfd sp!, {r0-r3, ip, lr}
292-
sub sp, sp, #0x10000
313+
sub sp, sp, r5
293314
#endif
294315

295316
mov r8, r6 @ use the appended device tree
@@ -306,7 +327,7 @@ restart: adr r0, LC0
306327
subs r1, r5, r1
307328
addhi r9, r9, r1
308329

309-
/* Get the dtb's size */
330+
/* Get the current DTB size */
310331
ldr r5, [r6, #4]
311332
#ifndef __ARMEB__
312333
/* convert r5 (dtb size) to little endian */

0 commit comments

Comments
 (0)