Skip to contentSkip to conversation

MIPS: relocate_code: fix relocation area size

PATCH In review Peter Mamonov 2 participants 4 messages Jan 28, 2020 – Jan 29, 2020 MIPS

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 MIPS: relocate_code: fix relocation area size

relocate_code() calculates relocation area size as a sum (barebox_image_size + bss_len). barebox_image_size and bss_len are calculated as (__image_end - __image_start) and (__bss_stop - __bss_start) respectively. This doesn't take into account relocation data placed between __image_end and __bss_start. However relocation preserves BSS position relative to image start, as if relocation data is still there. This causes RAM overflow during BSS initialization in main_entry(). This problem may be hidden due to the alignment of the relocaddr.

---
 arch/mips/lib/reloc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/mips/lib/reloc.c +1 -1
index 32d776a6a6..41e2d5c75f 100644
@@ -121,7 +121,7 @@ void relocate_code(void *fdt, u32 fdt_size, u32 ram_size)
 	memset(__bss_start, 0, bss_len);
 	cpu_probe();
 
-	length = barebox_image_size + bss_len;
+	length = __bss_stop - __image_start;
 	relocaddr = ALIGN_DOWN(ram_size - length, SZ_64K);
 	relocaddr = KSEG0ADDR(relocaddr);
 	new_stack = relocaddr - MALLOC_SIZE - 16;
Signature · 7 lines
2.24.0


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
Tested-by on v1 1/1
#1 lore raw
Quoted 8 lines · Peter Mamonov

relocate_code() calculates relocation area size as a sum (barebox_image_size + bss_len). barebox_image_size and bss_len are calculated as (__image_end - __image_start) and (__bss_stop - __bss_start) respectively. This doesn't take into account relocation data placed between __image_end and __bss_start. However relocation preserves BSS position relative to image start, as if relocation data is still there. This causes RAM overflow during BSS initialization in main_entry(). This problem may be hidden due to the alignment of the relocaddr.

Thx! Works on ar9331

Quoted 27 lines
---
 arch/mips/lib/reloc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/mips/lib/reloc.c +1 -1
index 32d776a6a6..41e2d5c75f 100644
@@ -121,7 +121,7 @@ void relocate_code(void *fdt, u32 fdt_size, u32 ram_size)
 	memset(__bss_start, 0, bss_len);
 	cpu_probe();
 
-	length = barebox_image_size + bss_len;
+	length = __bss_stop - __image_start;
 	relocaddr = ALIGN_DOWN(ram_size - length, SZ_64K);
 	relocaddr = KSEG0ADDR(relocaddr);
 	new_stack = relocaddr - MALLOC_SIZE - 16;
Signature · 7 lines
2.24.0


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
Signature · 4 lines
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

#2 lore raw
Quoted 11 lines · Oleksij Rempel
Quoted 8 lines · Peter Mamonov

relocate_code() calculates relocation area size as a sum (barebox_image_size + bss_len). barebox_image_size and bss_len are calculated as (__image_end - __image_start) and (__bss_stop - __bss_start) respectively. This doesn't take into account relocation data placed between __image_end and __bss_start. However relocation preserves BSS position relative to image start, as if relocation data is still there. This causes RAM overflow during BSS initialization in main_entry(). This problem may be hidden due to the alignment of the relocaddr.

Thx! Works on ar9331

Guess you should squash this patch into "MIPS: remove .bss to __rel_start overlay", since it fixes the issue caused by the latter.

Regards,
Peter

Quoted 25 lines
Quoted 22 lines
---
 arch/mips/lib/reloc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/mips/lib/reloc.c +1 -1
index 32d776a6a6..41e2d5c75f 100644
@@ -121,7 +121,7 @@ void relocate_code(void *fdt, u32 fdt_size, u32 ram_size)
 	memset(__bss_start, 0, bss_len);
 	cpu_probe();
 
-	length = barebox_image_size + bss_len;
+	length = __bss_stop - __image_start;
 	relocaddr = ALIGN_DOWN(ram_size - length, SZ_64K);
 	relocaddr = KSEG0ADDR(relocaddr);
 	new_stack = relocaddr - MALLOC_SIZE - 16;
Signature · 1 line
2.24.0
Quoted 11 lines
Quoted 5 lines

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

Signature · 4 lines
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

#3 lore raw
Quoted 11 lines · Peter Mamonov
Quoted 10 lines · Oleksij Rempel
Quoted 8 lines · Peter Mamonov

relocate_code() calculates relocation area size as a sum (barebox_image_size + bss_len). barebox_image_size and bss_len are calculated as (__image_end - __image_start) and (__bss_stop - __bss_start) respectively. This doesn't take into account relocation data placed between __image_end and __bss_start. However relocation preserves BSS position relative to image start, as if relocation data is still there. This causes RAM overflow during BSS initialization in main_entry(). This problem may be hidden due to the alignment of the relocaddr.

Quoted 4 lines
Quoted 1 line

Thx! Works on ar9331

Guess you should squash this patch into "MIPS: remove .bss to __rel_start overlay", since it fixes the issue caused by the latter.

ACK

Quoted 47 lines

Regards,
Peter

Quoted 25 lines
Quoted 22 lines
---
 arch/mips/lib/reloc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/mips/lib/reloc.c +1 -1
index 32d776a6a6..41e2d5c75f 100644
@@ -121,7 +121,7 @@ void relocate_code(void *fdt, u32 fdt_size, u32 ram_size)
 	memset(__bss_start, 0, bss_len);
 	cpu_probe();
 
-	length = barebox_image_size + bss_len;
+	length = __bss_stop - __image_start;
 	relocaddr = ALIGN_DOWN(ram_size - length, SZ_64K);
 	relocaddr = KSEG0ADDR(relocaddr);
 	new_stack = relocaddr - MALLOC_SIZE - 16;
Signature · 1 line
2.24.0
Quoted 11 lines
Quoted 5 lines

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

Signature · 4 lines
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

Signature · 4 lines
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox