Skip to content

Commit 83283c6

Browse files
dgarskedanielinux
authored andcommitted
Fixes for NXP T1024 and booting Integrity OS:
* Fixed PPC spin table based on ePAPR 1.1. * Added flattened device tree (FDT) support. Setting required FDT fields per ePAPR 1.1. * Added Frame Manager microcode upload. * Fixed CPLD and setting QE clock. * Added support for setting logical device numbers and updated device tree. * Fixed QUICC Engine base address (was incorrect, should be 0x140000). * Fixed "cpu-release-addr" to use 64-bit value. * Added secondary cached boot page. * Added L2 cache support to multi-core. * Added flattened device tree parser tool for testing (`make fdt-parser` and `tools/fdt-parser/fdt-parser`). * Added checks for FDT header. * Added automated test case for NXP T1024 FDT.
1 parent a020852 commit 83283c6

25 files changed

Lines changed: 2225 additions & 353 deletions
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
name: Test parsing tools (elf and fdt)
2+
3+
on:
4+
push:
5+
branches: [ 'master', 'main', 'release/**' ]
6+
pull_request:
7+
branches: [ '*' ]
8+
9+
jobs:
10+
11+
build:
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
- uses: actions/checkout@v3
16+
with:
17+
submodules: true
18+
19+
- name: Install cross compilers
20+
run: |
21+
sudo apt-get install -y gcc-arm-none-eabi gcc-powerpc-linux-gnu
22+
23+
- name: make distclean
24+
run: |
25+
make distclean
26+
27+
- name: Select config
28+
run: |
29+
cp config/examples/nxp-t1024.config .config
30+
31+
- name: Build wolfBoot
32+
run: |
33+
make
34+
35+
- name: Build tools
36+
run: |
37+
make elf-parser
38+
make fdt-parser
39+
40+
- name: Run elf-parser test
41+
run: |
42+
./tools/elf-parser/elf-parser
43+
44+
- name: Run fdt-parser test (nxp_t1024.dtb)
45+
run: |
46+
./tools/fdt-parser/fdt-parser ./tools/fdt-parser/nxp_t1024.dtb -t

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ tools/uart-flash-server/ufserver
100100
tools/unit-tests/unit-parser
101101
tools/bin-assemble/bin-assemble
102102
tools/elf-parser/elf-parser
103+
tools/fdt-parser/fdt-parser
103104
tools/tpm/rot
104105
tools/tpm/pcr_read
105106
tools/tpm/pcr_reset

Makefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,7 @@ utilsclean: clean
276276
$(Q)$(MAKE) -C tools/delta -s clean
277277
$(Q)$(MAKE) -C tools/bin-assemble -s clean
278278
$(Q)$(MAKE) -C tools/elf-parser -s clean
279+
$(Q)$(MAKE) -C tools/fdt-parser -s clean
279280
$(Q)$(MAKE) -C tools/check_config -s clean
280281
$(Q)$(MAKE) -C tools/test-expect-version -s clean
281282
$(Q)$(MAKE) -C tools/test-update-server -s clean
@@ -313,6 +314,10 @@ elf-parser:
313314
@$(MAKE) -C tools/elf-parser -s clean
314315
@$(MAKE) -C tools/elf-parser
315316

317+
fdt-parser:
318+
@$(MAKE) -C tools/fdt-parser -s clean
319+
@$(MAKE) -C tools/fdt-parser
320+
316321
config: FORCE
317322
$(MAKE) -C config
318323

arch.mk

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,7 @@ ifeq ($(TARGET),nxp_t1024)
424424
LDFLAGS+=-Wl,--hash-style=both # generate both sysv and gnu symbol hash table
425425
LDFLAGS+=-Wl,--as-needed # remove weak functions not used
426426
OBJS+=src/boot_ppc_mp.o # support for spin table
427+
OBJS+=src/fdt.o
427428
UPDATE_OBJS:=src/update_ram.o
428429
ifeq ($(SPMATH),1)
429430
MATH_OBJS += ./lib/wolfssl/wolfcrypt/src/sp_c32.o
@@ -445,6 +446,7 @@ ifeq ($(TARGET),nxp_t2080)
445446
LDFLAGS+=-Wl,--hash-style=both # generate both sysv and gnu symbol hash table
446447
LDFLAGS+=-Wl,--as-needed # remove weak functions not used
447448
UPDATE_OBJS:=src/update_ram.o
449+
OBJS+=src/fdt.o
448450
ifeq ($(SPMATH),1)
449451
MATH_OBJS += ./lib/wolfssl/wolfcrypt/src/sp_c32.o
450452
else
@@ -750,6 +752,7 @@ BOOT_IMG?=test-app/image.bin
750752
## Update mechanism
751753
ifeq ($(ARCH),AARCH64)
752754
CFLAGS+=-DMMU -DWOLFBOOT_DUALBOOT
755+
OBJS+=src/fdt.o
753756
UPDATE_OBJS:=src/update_ram.o
754757
endif
755758
ifeq ($(DUALBANK_SWAP),1)

hal/nxp_p1021.c

Lines changed: 33 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,24 @@
2222
#include "target.h"
2323
#include "image.h"
2424
#include "printf.h"
25-
#include <string.h>
25+
#include "string.h"
2626

2727
#include "nxp_ppc.h"
2828

2929
/* Debugging */
3030
/* #define DEBUG_EXT_FLASH */
3131
/* #define DEBUG_ESPI 1 */
3232

33-
/* Tests */
34-
/* #define TEST_DDR */
35-
/* #define TEST_FLASH */
36-
/* #define TEST_TPM */
37-
3833
#define ENABLE_ELBC /* Flash Controller */
3934
#define ENABLE_BUS_CLK_CALC
35+
4036
#ifndef BUILD_LOADER_STAGE1
37+
/* Tests */
38+
#if 0
39+
#define TEST_DDR
40+
#define TEST_FLASH
41+
#define TEST_TPM
42+
#endif
4143
#define ENABLE_PCIE
4244
#define ENABLE_CPLD /* Board Configuration and Status Registers (BCSR) */
4345
#define ENABLE_CONF_IO
@@ -50,6 +52,7 @@
5052
/* #define ENABLE_QE_CRC32 */ /* CRC32 check on QE disabled by default */
5153
#endif
5254

55+
/* Foward declarations */
5356
#if defined(ENABLE_DDR) && defined(TEST_DDR)
5457
static int test_ddr(void);
5558
#endif
@@ -421,8 +424,8 @@ enum elbc_amask_sizes {
421424
#define DDR_SDRAM_CLK_CNTL ((volatile uint32_t*)(DDR_BASE + 0x130)) /* DDR SDRAM clock control */
422425

423426
#define DDR_SDRAM_CFG_MEM_EN 0x80000000 /* SDRAM interface logic is enabled */
424-
#define DDR_SDRAM_CFG_32_BE 0x00080000
425427
#define DDR_SDRAM_CFG_ECC_EN 0x20000000
428+
#define DDR_SDRAM_CFG_32_BE 0x00080000
426429
#define DDR_SDRAM_CFG_2_D_INIT 0x00000010 /* data initialization in progress */
427430
#define DDR_SDRAM_CFG_BI 0x00000001 /* Bypass initialization */
428431

@@ -894,7 +897,7 @@ static void hal_ddr_init(void)
894897
/* Map LAW for DDR */
895898
set_law(6, 0, DDR_ADDRESS, LAW_TRGT_DDR, LAW_SIZE_512MB, 0);
896899

897-
/* If DDR is not already enabled */
900+
/* If DDR is already enabled then just return */
898901
if ((get32(DDR_SDRAM_CFG) & DDR_SDRAM_CFG_MEM_EN)) {
899902
return;
900903
}
@@ -1379,7 +1382,7 @@ static int hal_qe_init(void)
13791382
set32(QE_SDMA_SDAQMR, 0);
13801383

13811384
/* Allocate 2KB temporary buffer for sdma */
1382-
sdma_base = 0;
1385+
sdma_base = 0; /* offset in QE_MURAM */
13831386
set32(QE_SDMA_SDEBCR, sdma_base & QE_SDEBCR_BA_MASK);
13841387

13851388
/* Clear sdma status */
@@ -1401,28 +1404,25 @@ static int hal_qe_init(void)
14011404
#ifdef ENABLE_MP
14021405

14031406
/* from boot_ppc_core.S */
1404-
extern uint32_t _mp_page_start;
1407+
extern uint32_t _secondary_start_page;
1408+
extern uint32_t _second_half_boot_page;
14051409
extern uint32_t _spin_table;
1410+
extern uint32_t _spin_table_addr;
14061411
extern uint32_t _bootpg_addr;
14071412

14081413
/* Startup additional cores with spin table and synchronize the timebase */
14091414
static void hal_mp_up(uint32_t bootpg)
14101415
{
14111416
uint32_t up, cpu_up_mask, whoami, bpcr, devdisr;
1412-
uint8_t *spin_table_addr;
14131417
int timeout = 50, i;
14141418

14151419
/* Get current running core number */
14161420
whoami = get32(PIC_WHOAMI);
14171421

1418-
/* Calculate location of spin table in BPTR */
1419-
spin_table_addr = (uint8_t*)(BOOT_ROM_ADDR +
1420-
((uint32_t)&_spin_table - (uint32_t)&_mp_page_start));
1421-
1422-
wolfBoot_printf("MP: Starting core 2 (spin table %p)\n",
1423-
spin_table_addr);
1422+
wolfBoot_printf("MP: Starting core 2 (boot page %p, spin table %p)\n",
1423+
bootpg, (uint32_t)&_spin_table);
14241424

1425-
/* Set the boot page translation reigster */
1425+
/* Set the boot page translation register */
14261426
set32(RESET_BPTR, RESET_BPTR_EN | RESET_BPTR_BOOTPG(bootpg));
14271427

14281428
/* Disable time base on inactive core */
@@ -1444,8 +1444,8 @@ static void hal_mp_up(uint32_t bootpg)
14441444
cpu_up_mask = (1 << whoami);
14451445
while (timeout) {
14461446
for (i = 0; i < CPU_NUMCORES; i++) {
1447-
uint32_t* entry = (uint32_t*)(spin_table_addr +
1448-
(i * ENTRY_SIZE) + ENTRY_ADDR_LOWER);
1447+
uint32_t* entry = (uint32_t*)(
1448+
(uint8_t*)&_spin_table + (i * ENTRY_SIZE) + ENTRY_ADDR_LOWER);
14491449
if (*entry) {
14501450
cpu_up_mask |= (1 << i);
14511451
}
@@ -1480,23 +1480,29 @@ static void hal_mp_up(uint32_t bootpg)
14801480

14811481
static void hal_mp_init(void)
14821482
{
1483-
uint32_t *fixup = (uint32_t*)&_mp_page_start;
1483+
uint32_t *fixup = (uint32_t*)&_secondary_start_page;
14841484
uint32_t bootpg;
14851485
int i_tlb = 0; /* always 0 */
14861486
size_t i;
1487-
const uint32_t *s;
1488-
uint32_t *d;
1487+
const volatile uint32_t *s;
1488+
volatile uint32_t *d;
14891489

14901490
/* Assign virtual boot page at end of DDR */
14911491
bootpg = DDR_ADDRESS + DDR_SIZE - BOOT_ROM_SIZE;
14921492

14931493
/* Store the boot page address for use by additional CPU cores */
1494-
_bootpg_addr = bootpg;
1494+
_bootpg_addr = (uint32_t)&_second_half_boot_page;
1495+
1496+
/* Store location of spin table for other cores */
1497+
_spin_table_addr = (uint32_t)&_spin_table;
1498+
1499+
/* Flush bootpg before copying to invalidate any stale cache lines */
1500+
flush_cache(bootpg, BOOT_ROM_SIZE);
14951501

1496-
/* map reset page to bootpg so we can copy code there */
1502+
/* Map reset page to bootpg so we can copy code there */
14971503
disable_tlb1(i_tlb);
1498-
set_tlb(1, i_tlb, BOOT_ROM_ADDR, bootpg, 0, /* tlb, epn, rpn */
1499-
MAS3_SX | MAS3_SW | MAS3_SR, MAS2_I, /* perms, wimge */
1504+
set_tlb(1, i_tlb, BOOT_ROM_ADDR, bootpg, 0, /* tlb, epn, rpn, urpn */
1505+
(MAS3_SX | MAS3_SW | MAS3_SR), (MAS2_I | MAS2_G), /* perms, wimge */
15001506
0, BOOKE_PAGESZ_4K, 1); /* ts, esel, tsize, iprot */
15011507

15021508
/* copy startup code to virtually mapped boot address */

hal/nxp_p1021.ld

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ SECTIONS
3939
{
4040
_start_vector = .;
4141
KEEP(*(.isr_vector))
42+
. = ALIGN(256);
43+
KEEP(*(.bootmp))
4244
*(.text*)
4345
*(.rodata*)
4446
*(.sdata*)

hal/nxp_ppc.h

Lines changed: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@
3232
#define CCSRBAR_SIZE BOOKE_PAGESZ_1M
3333

3434
#define ENABLE_DDR
35+
#ifndef DDR_SIZE
3536
#define DDR_SIZE (512UL * 1024UL * 1024UL)
37+
#endif
3638

3739
/* Memory used for transferring blocks to/from NAND.
3840
* Maps to eLBC FCM internal 8KB region (by hardware) */
@@ -62,8 +64,9 @@
6264

6365
#elif defined(PLATFORM_nxp_t1024)
6466
/* NXP T1024 */
65-
#define CPU_NUMCORES 2
6667
#define CORE_E5500
68+
#define CPU_NUMCORES 2
69+
#define CORES_PER_CLUSTER 1
6770
#define LAW_MAX_ENTRIES 16
6871

6972
#define CCSRBAR_DEF (0xFE000000) /* T1024RM 4.4.1 default base */
@@ -86,7 +89,9 @@
8689
#endif
8790

8891
#define ENABLE_DDR
92+
#ifndef DDR_SIZE
8993
#define DDR_SIZE (2048ULL * 1024ULL * 1024ULL)
94+
#endif
9095

9196
#define FLASH_BASE_ADDR 0xEC000000UL
9297
#define FLASH_BASE_PHYS_HIGH 0xFULL
@@ -97,9 +102,11 @@
97102

98103
#elif defined(PLATFORM_nxp_t2080)
99104
/* NXP T0280 */
100-
#define CPU_NUMCORES 4
101105
#define CORE_E6500
106+
#define CPU_NUMCORES 4
107+
#define CORES_PER_CLUSTER 4
102108
#define LAW_MAX_ENTRIES 32
109+
#define ENABLE_PPC64
103110

104111
#define CCSRBAR_DEF (0xFE000000UL) /* T2080RM 4.3.1 default base */
105112
#define CCSRBAR_SIZE BOOKE_PAGESZ_16M
@@ -122,7 +129,9 @@
122129
#define ENABLE_INTERRUPTS
123130

124131
#define ENABLE_DDR
132+
#ifndef DDR_SIZE
125133
#define DDR_SIZE (8192UL * 1024UL * 1024UL)
134+
#endif
126135

127136
#define FLASH_BASE_ADDR 0xE8000000UL
128137
#define FLASH_BASE_PHYS_HIGH 0x0ULL
@@ -424,11 +433,32 @@
424433

425434
/* L2 Cache */
426435
#if defined(CORE_E6500)
436+
/* L2 Cache Control - E6500CORERM 2.2.3 Memory-mapped registers (MMRs) */
437+
#define L2_CLUSTER_BASE(n) (CCSRBAR + 0xC20000 + (n * 0x40000))
438+
#define L2PID(n) (0x200 + (n * 0x10)) /* L2 Cache Partitioning ID */
439+
#define L2PIR(n) (0x208 + (n * 0x10)) /* L2 Cache Partitioning Allocation */
440+
#define L2PWR(n) (0x20C + (n * 0x10)) /* L2 Cache Partitioning Way */
441+
427442
/* MMRs */
428443
#define L2CSR0 0x000 /* L2 Cache Control and Status 0 */
429444
#define L2CSR1 0x004 /* L2 Cache Control and Status 1 */
430445
#define L2CFG0 0x008 /* L2 Cache Configuration */
431446
#else
447+
#ifdef CORE_E5500
448+
/* L2 Cache Control - E5500RM 2.15 L2 Cache Registers */
449+
#define L2_BASE (CCSRBAR + 0x20000)
450+
#else
451+
/* E500 */
452+
#define L2_BASE (CCSRBAR + 0x20000)
453+
#define L2CTL 0x000 /* 0xFFE20000 - L2 control register */
454+
#define L2SRBAR0 0x100 /* 0xFFE20100 - L2 SRAM base address register */
455+
456+
#define L2CTL_EN (1 << 31) /* L2 enable */
457+
#define L2CTL_INV (1 << 30) /* L2 invalidate */
458+
#define L2CTL_SIZ(n) (((n) & 0x3) << 28) /* 2=256KB (always) */
459+
#define L2CTL_L2SRAM(n) (((n) & 0x7) << 16) /* 1=all 256KB, 2=128KB */
460+
#endif
461+
432462
/* SPR */
433463
#define L2CFG0 0x207 /* L2 Cache Configuration Register 0 */
434464
#define L2CSR0 0x3F9 /* L2 Data Cache Control and Status Register 0 */
@@ -441,8 +471,6 @@
441471
#define L2CSR0_L2PE 0x40000000 /* L2 Cache Parity/ECC Enable */
442472
#define L2CSR0_L2E 0x80000000 /* L2 Cache Enable */
443473

444-
#define L2CSR0_L2E 0x80000000 /* L2 Cache Enable */
445-
#define L2CSR0_L2PE 0x40000000 /* L2 Cache Parity/ECC Enable */
446474
#define L2CSR0_L2WP 0x1c000000 /* L2 I/D Way Partioning */
447475
#define L2CSR0_L2CM 0x03000000 /* L2 Cache Coherency Mode */
448476
#define L2CSR0_L2FI 0x00200000 /* L2 Cache Flash Invalidate */
@@ -702,17 +730,24 @@ extern void dcache_disable(void);
702730
#define r31 31
703731
#endif
704732

733+
/* ePAPR 1.1 spin table */
705734
/* For multiple core spin table communication */
706-
#define EPAPR_MAGIC (0x45504150)
735+
/* The spin table must be WING 0b001x (memory-coherence required) */
736+
/* For older PPC compat use dcbf to flush spin table entry */
737+
/* Note: spin-table must be cache-line aligned in memory */
738+
#define EPAPR_MAGIC (0x45504150) /* Book III-E CPUs */
707739
#define ENTRY_ADDR_UPPER 0
708740
#define ENTRY_ADDR_LOWER 4
709741
#define ENTRY_R3_UPPER 8
710742
#define ENTRY_R3_LOWER 12
711743
#define ENTRY_RESV 16
712744
#define ENTRY_PIR 20
745+
746+
/* not used for ePAPR 1.1 */
713747
#define ENTRY_R6_UPPER 24
714748
#define ENTRY_R6_LOWER 28
715-
#define ENTRY_SIZE 32
716749

717750

751+
#define ENTRY_SIZE 64
752+
718753
#endif /* !_NXP_PPC_H_ */

0 commit comments

Comments
 (0)