Skip to contentSkip to conversation

Fix malloc hang on 82xx after relocation fixes

PATCH New Rune Torgersen 1 participant 2 messages Oct 24, 2007

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Fix malloc hang on 82xx after relocation fixes

Temporarily set gd->reloc_off so malloc_bin_reloc will work correctly after the relocation fixup patches.

---

Quoted 20 lines

From: Rune Torgersen
Sent: Wednesday, October 24, 2007 8:41 AM
Subject: [U-Boot-Users] Malloc hangs on 82xx boards

the relocation fixup patches (by Grant Likely and others) messes up malloc on at least 8260 boards.
What seems to be happening is that the malloc end address does not get set anymore, and is therefore 0, and malloc start and lengths then end up being negative and ends up in the middle of the IMMR somewhere.

Net effect is that no 826x board I have tried so fat (8260ADS, 8266ADS and an internal board) will boot using u-boot 1.3.0-rc3.

I can get it to work by
1) Commenting out "#define CONFIG_RELOC_FIXUP_WORKS" on line 90 in include common.h
or
2) Backing out commits f82b3b6304b620ef7e28bfaa1ea887a2ad2fa325 and e9514751cfa5cce61ea699fa0d3eb37898a5eeb5.

Quoted 6 lines

2) basically reverts to setting malloc end address from a #define again.

I need help to figure out how to fix this, and this most likely affects
ALL 82xx boards (at least).

I finally tracked it down.
Not sure on how to best fix this.

Malloc uses a statically initialized memory struct with differnet bins in it (an array of type struct malloc_chunk). This array is initialized on compile time. There are fwd and back pointers in this struct to basically make it a linked list. These pointers are in the text segment, and will therefore be pointing to the flash.

When u-boot is relocated to flash, malloc_bin_reloc() gets called to relocate these pointers to RAM instead.

When CONFIG_RELOC_FIXUP_WORKS is defined, gd->reloc_off is set to 0, and the pointers will continue to point to flash.

The correct fix would be to have the compiler set the addresses in the array correct at compile time, but I do not think that is possible, as we don't always know where we'll end up in RAM until runtime.

Another solution would be to generate the table dynamically after relocation.

Right now, this hack will allow at least 82xx to boot with the new relocation stuff in place.

lib_ppc/board.c +9 -0
index 9aa67f9..88363eb 100644
@@ -779,8 +779,17 @@ void board_init_r (gd_t *id, ulong dest_addr)
 
 	/* initialize malloc() area */
 	mem_malloc_init ();
+
+#if defined(CONFIG_RELOC_FIXUP_WORKS)
+	/* Set reloc offset temporarily so malloc_bin_reloc will work */
+	gd->reloc_off = dest_addr - CFG_MONITOR_BASE;
+#endif
 	malloc_bin_reloc ();
 
+#if defined(CONFIG_RELOC_FIXUP_WORKS)
+	gd->reloc_off = 0;
+#endif
+
 #ifdef CONFIG_SPI
 # if !defined(CFG_ENV_IS_IN_EEPROM)
 	spi_init_f ();
#1 lore raw

PATCH 1/1 Fix malloc hang on 82xx after relocationfixes

Quoted 10 lines

From: Rune Torgersen

Temporarily set gd->reloc_off so malloc_bin_reloc will work correctly after the relocation fixup patches.

When CONFIG_RELOC_FIXUP_WORKS is defined, gd->reloc_off is set to 0, and the
pointers will continue to point to flash.

Turns out none of the relocation stuff seems to work.
U-boot boots to command prompt, but if I try to run any commands, I get a machine check exception.

CPU1 =>
CPU1 => ?
Machine check in kernel mode.
Caused by (from msr): regs 0ff99b38 Unknown values in msr
NIP: 5FD84D78 XER: 20000000 LR: FFF15D64 REGS: 0ff99b38 TRAP: 0200 DAR:
00000000
MSR: 0000b000 EE: 1 PR: 0 FP: 1 ME: 1 IR/DR: 00

GPR00: 00000004 0FF99C28 FF2FF7FF FFF29DB0 FFF29DB0 FFF23A6F 0FFAA350 0FFF8684
GPR08: FFFFFFFF 5FD84D7A 00000000 FFF2EDF4 44028024 9FBFFBFD 0FFFE000 00000000
GPR16: 00000000 00000000 00000000 00000000 00003002 0FF99D98 00000000 0FF99C50
GPR24: 00000005 0000004D 0FF99C60 00000001 FFF29DB0 0FF99F64 FFF34F38 0FF99D98
Call backtrace:
PCI: err status 0 err mask 1fff err ctrl 10ff
error address c error data 0 ctrl 3f11abb1
machine check