Skip to content

Commit 040c387

Browse files
committed
Fixes for T2080 from VxWorks testing
1 parent 09d1a14 commit 040c387

7 files changed

Lines changed: 71 additions & 29 deletions

File tree

arch.mk

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1063,6 +1063,9 @@ ifeq ($(TARGET),nxp_t2080)
10631063
CFLAGS+=$(ARCH_FLAGS)
10641064
BIG_ENDIAN=1
10651065
CFLAGS+=-DMMU -DWOLFBOOT_FDT -DWOLFBOOT_DUALBOOT
1066+
# Support U-Boot legacy uImage header: strip 64-byte header before jumping
1067+
# to the OS image (e.g. uVxWorks, uImage Linux kernel).
1068+
CFLAGS+=-DWOLFBOOT_UBOOT_LEGACY
10661069
CFLAGS+=-pipe # use pipes instead of temp files
10671070
CFLAGS+=-feliminate-unused-debug-types
10681071
LDFLAGS+=$(ARCH_FLAGS)

config/examples/nxp-t2080.config

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ WOLFBOOT_LOAD_DTS_ADDRESS?=0x200000
8989
#WOLFBOOT_PARTITION_SWAP_ADDRESS=0xFFDD0000
9090
#WOLFBOOT_DTS_BOOT_ADDRESS=0xF0040000
9191
#WOLFBOOT_DTS_UPDATE_ADDRESS=0xF0050000
92+
#WOLFBOOT_LOAD_DTS_ADDRESS=0xF000000
9293

9394
# Flash erase/write/read test at update partition address
9495
#TEST_FLASH?=1

docs/Targets.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4071,6 +4071,17 @@ flash VA range (`0xF0000000`–`0xFFFFFFFF`). The startup assembly relocates
40714071
CCSRBAR to `0xEF000000` (just below flash). The CPC SRAM and L1 cache addresses
40724072
are also relocated to `0xEE900000`/`0xEE800000` to avoid overlap.
40734073

4074+
**Boot ROM TLB invalidation (CW VPX3-152 only)**
4075+
4076+
For VPX3-152, TLB1 Entry 2 maps the full 256 MB flash at `0xF0000000-0xFFFFFFFF`
4077+
with IPROT. This range overlaps with the boot ROM TLB (default 4 KB at
4078+
`0xFFFFF000`, resized to 256 KB at `0xFFFC0000` by `shrink_default_tlb1`).
4079+
Overlapping TLB1 entries cause an e6500 multi-hit machine check. After Entry 2
4080+
is created, the boot ROM TLB is cleared via `tlbwe` with `V=0` and `IPROT=0`;
4081+
Entry 2 then serves all instruction fetches for the flash region including the
4082+
boot ROM range. For NAII 68PPC2 and T2080 RDB (128 MB flash at `0xE8000000`),
4083+
there is no overlap and the boot ROM TLB remains valid alongside Entry 2.
4084+
40744085
**RAMFUNCTION Constraints**
40754086

40764087
The NOR flash (two S29GL01GS x8 in parallel, 16-bit bus) enters

hal/nxp_ppc.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -217,11 +217,13 @@
217217
#endif
218218
#endif
219219

220-
/* DDR stack configuration - relocate from CPC SRAM after DDR init
221-
* Stack is at top of first 32MB of DDR, with 64KB reserved for stack
222-
* Stack grows downward from DDR_STACK_TOP */
220+
/* DDR stack configuration - relocate from CPC SRAM after DDR init.
221+
* Stack must be ABOVE the image load area to avoid being overwritten
222+
* when the OS image is copied to WOLFBOOT_LOAD_ADDRESS (0x100000).
223+
* With WOLFBOOT_PARTITION_SIZE=0x800000 the image area ends at 0x900000.
224+
* Place stack at 16MB to be safely above the image + DTS regions. */
223225
#define DDR_STACK_SIZE (64 * 1024) /* 64KB stack in DDR */
224-
#define DDR_STACK_TOP 0x02000000UL /* Top of first 32MB */
226+
#define DDR_STACK_TOP 0x01000000UL /* 16MB - above image area */
225227
#define DDR_STACK_BASE (DDR_STACK_TOP - DDR_STACK_SIZE)
226228

227229
/* DDR address where .ramcode is copied before CPC SRAM is released.

include/image.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1380,7 +1380,11 @@ static inline int wb_flash_write_verify_word(struct wolfBoot_image *img,
13801380

13811381
/* -- Image Formats -- */
13821382
/* Legacy U-Boot Image */
1383+
#ifdef BIG_ENDIAN_ORDER
1384+
#define UBOOT_IMG_HDR_MAGIC 0x27051956UL
1385+
#else
13831386
#define UBOOT_IMG_HDR_MAGIC 0x56190527UL
1387+
#endif
13841388
#define UBOOT_IMG_HDR_SZ 64
13851389

13861390
/* --- Flattened Device Tree Blob */

src/boot_ppc_mp.S

Lines changed: 42 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,31 @@
2727

2828
#define TORESET(x) (x - _secondary_start_page + BOOT_ROM_ADDR)
2929

30+
/* e6500 has 64-bit GPRs. When loading 32-bit addresses with bit 31 set
31+
* (addresses >= 0x80000000), the lis instruction sign-extends, putting
32+
* 0xFFFFFFFF in the upper 32 bits. This causes memory access failures.
33+
* Use LOAD_ADDR32 macro to properly load 32-bit addresses on e6500. */
34+
#ifdef CORE_E6500
35+
#define LOAD_ADDR32(reg, addr) \
36+
li reg, 0; \
37+
oris reg, reg, (addr)@h; \
38+
ori reg, reg, (addr)@l
39+
#else
40+
#define LOAD_ADDR32(reg, addr) \
41+
lis reg, (addr)@h; \
42+
ori reg, reg, (addr)@l
43+
#endif
44+
3045
/* Additional cores (mp) assembly code for core minimum startup and spin table.
3146
* All code must fit in 4KB, which gets virtually mapped via the TLB1 (MMU) and
3247
* loaded by core 0. Spin table entry TLB1(0) mapped for work is 64MB.
3348
*/
3449
.section .bootmp, "ax"
3550
.globl _secondary_start_page
3651
_secondary_start_page:
37-
/* Time base, MAS7 and machine check pin enable */
38-
lis r0, (HID0_EMCP | HID0_TBEN | HID0_ENMAS7)@h
39-
ori r0, r0, (HID0_EMCP | HID0_TBEN | HID0_ENMAS7)@l
52+
/* Time base, MAS7 and machine check pin enable.
53+
* HID0_EMCP=0x80000000 has bit 31 set; use LOAD_ADDR32 for e6500. */
54+
LOAD_ADDR32(r0, (HID0_EMCP | HID0_TBEN | HID0_ENMAS7))
4055
mtspr SPRN_HID0, r0
4156

4257
#ifdef CORE_E500
@@ -98,9 +113,10 @@ branch_prediction:
98113
andi. r1, r3, L1CSR_CE@l
99114
beq 2b
100115

101-
/* Get our PIR to figure out our table entry */
102-
lis r3, TORESET(_spin_table_addr)@h
103-
ori r3, r3, TORESET(_spin_table_addr)@l
116+
/* Get our PIR to figure out our table entry.
117+
* TORESET(...) resolves to address near BOOT_ROM_ADDR (0xFFFFF000),
118+
* bit 31 set; use LOAD_ADDR32 for e6500. */
119+
LOAD_ADDR32(r3, TORESET(_spin_table_addr))
104120
lwz r3, 0(r3)
105121

106122
/* Use PIR to determine cluster/core for spin table base at r10 */
@@ -160,8 +176,9 @@ l2_poll_invclear:
160176
addi r3, r8, 1
161177
mtspr L2CSR1, r3
162178

163-
/* enable L2 with no parity */
164-
lis r3, (L2CSR0_L2E)@h
179+
/* enable L2 with no parity.
180+
* L2CSR0_L2E=0x80000000 has bit 31 set; use LOAD_ADDR32 for e6500. */
181+
LOAD_ADDR32(r3, L2CSR0_L2E)
165182
mtspr L2CSR0, r3
166183
isync
167184
2:
@@ -171,33 +188,37 @@ l2_poll_invclear:
171188
#endif
172189
#endif /* CORE_E5500 || CORE_E6500 */
173190
3:
174-
/* setup mapping for the spin table, WIMGE=0b00100 */
175-
lis r13, TORESET(_spin_table_addr)@h
176-
ori r13, r13, TORESET(_spin_table_addr)@l
191+
/* setup mapping for the spin table, WIMGE=0b00100.
192+
* TORESET(...) has bit 31 set; use LOAD_ADDR32 for e6500. */
193+
LOAD_ADDR32(r13, TORESET(_spin_table_addr))
177194
lwz r13, 0(r13)
178195
/* mask by 4K */
179196
rlwinm r13, r13, 0, 0, 19
180197

181198
lis r11, (MAS0_TLBSEL(1) | MAS0_ESEL(1))@h
182199
mtspr MAS0, r11
183-
lis r11, (MAS1_VALID | MAS1_IPROT)@h
184-
ori r11, r11, (MAS1_TS | MAS1_TSIZE(BOOKE_PAGESZ_4K))@l
200+
/* MAS1_VALID=0x80000000 has bit 31 set; use LOAD_ADDR32 for e6500. */
201+
LOAD_ADDR32(r11, (MAS1_VALID | MAS1_IPROT | MAS1_TS |
202+
MAS1_TSIZE(BOOKE_PAGESZ_4K)))
185203
mtspr MAS1, r11
204+
/* Build MAS2 = r13 (spin table base, 4K aligned) | MAS2_M | MAS2_G.
205+
* Note: both oris and ori must use r11 as source for the second op
206+
* (the original code erroneously used r13 on the second op, which
207+
* overwrote the upper 16 bits from the first oris). */
186208
oris r11, r13, (MAS2_M | MAS2_G)@h
187-
ori r11, r13, (MAS2_M | MAS2_G)@l
209+
ori r11, r11, (MAS2_M | MAS2_G)@l
188210
mtspr MAS2, r11
189211
oris r11, r13, (MAS3_SX | MAS3_SW | MAS3_SR)@h
190-
ori r11, r13, (MAS3_SX | MAS3_SW | MAS3_SR)@l
212+
ori r11, r11, (MAS3_SX | MAS3_SW | MAS3_SR)@l
191213
mtspr MAS3, r11
192214
li r11, 0
193215
mtspr MAS7, r11
194216
tlbwe
195217

196218
/* _bootpg_addr has the address of _second_half_boot_page
197-
* jump there in AS=1 space with cache enabled
198-
*/
199-
lis r13, TORESET(_bootpg_addr)@h
200-
ori r13, r13, TORESET(_bootpg_addr)@l
219+
* jump there in AS=1 space with cache enabled.
220+
* TORESET(...) has bit 31 set; use LOAD_ADDR32 for e6500. */
221+
LOAD_ADDR32(r13, TORESET(_bootpg_addr))
201222
lwz r11, 0(r13)
202223
mtspr SRR0, r11
203224
mfmsr r13
@@ -295,8 +316,8 @@ _second_half_boot_page:
295316
/* Add tlb 1 entry 0 64MB for new entry */
296317
lis r10, (MAS0_TLBSEL(1) | MAS0_ESEL(0))@h
297318
mtspr MAS0, r10
298-
lis r10, (MAS1_VALID | MAS1_IPROT)@h
299-
ori r10, r10, (MAS1_TSIZE(BOOKE_PAGESZ_64M))@l
319+
/* MAS1_VALID=0x80000000 has bit 31 set; use LOAD_ADDR32 for e6500. */
320+
LOAD_ADDR32(r10, (MAS1_VALID | MAS1_IPROT | MAS1_TSIZE(BOOKE_PAGESZ_64M)))
300321
mtspr MAS1, r10
301322
mtspr MAS2, r12 /* WIMGE = 0 */
302323
ori r12, r12, (MAS3_SX | MAS3_SW | MAS3_SR)

src/update_ram.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -277,10 +277,10 @@ void RAMFUNCTION wolfBoot_start(void)
277277
image_ptr = wolfBoot_peek_image(&os_image, 0, NULL);
278278
if (image_ptr) {
279279
if (*((uint32_t*)image_ptr) == UBOOT_IMG_HDR_MAGIC) {
280-
/* Note: Could parse header and get load address at 0x10 */
281-
282-
/* Skip 64 bytes (size of Legacy format image header) */
283-
load_address += UBOOT_IMG_HDR_SZ;
280+
/* Skip 64-byte legacy header in source; load address unchanged
281+
* so kernel is placed at WOLFBOOT_LOAD_ADDRESS */
282+
wolfBoot_printf("U-Boot Legacy header detected, skipping %d bytes\n",
283+
UBOOT_IMG_HDR_SZ);
284284
os_image.fw_base += UBOOT_IMG_HDR_SZ;
285285
os_image.fw_size -= UBOOT_IMG_HDR_SZ;
286286
}

0 commit comments

Comments
 (0)