Skip to content

Commit 51136f1

Browse files
committed
Progress with DDR (working now on NAII 6xppc2)
1 parent ec28be7 commit 51136f1

5 files changed

Lines changed: 155 additions & 20 deletions

File tree

hal/nxp_ppc.h

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -118,17 +118,17 @@
118118
#define ENABLE_L1_CACHE
119119
#define ENABLE_L2_CACHE
120120

121-
/* T2080 CPC SRAM config - 512KB per T2080RM */
122-
#define L2SRAM_ADDR (0xF8F80000UL) /* CPC as SRAM (512KB) */
123-
#define L2SRAM_SIZE (512UL * 1024UL)
121+
/* T2080 CPC SRAM config - 1MB for ECC P384 stack requirements */
122+
#define L2SRAM_ADDR (0xF8F00000UL) /* CPC as SRAM (1MB) */
123+
#define L2SRAM_SIZE (1024UL * 1024UL)
124124

125125
#define INITIAL_SRAM_ADDR L2SRAM_ADDR
126126
/* CPC SRAM transactions traverse the CoreNet interconnect, which
127127
* requires a LAW to route them. LAW_TRGT_DDR_1 (0x10) is the CPC
128128
* target per T2080RM Table 2-2 (Target ID Assignments). */
129-
#define INITIAL_SRAM_LAW_SZ LAW_SIZE_512KB
129+
#define INITIAL_SRAM_LAW_SZ LAW_SIZE_1MB
130130
#define INITIAL_SRAM_LAW_TRGT LAW_TRGT_DDR_1
131-
#define INITIAL_SRAM_BOOKE_SZ BOOKE_PAGESZ_512K
131+
#define INITIAL_SRAM_BOOKE_SZ BOOKE_PAGESZ_1M
132132

133133
#define ENABLE_INTERRUPTS
134134

@@ -593,6 +593,10 @@
593593
#endif
594594

595595
#define mtspr(rn, v) __asm__ __volatile__("mtspr " WC_STRINGIFY(rn) ",%0" : : "r" (v))
596+
#define mfspr(rn) ({ \
597+
unsigned int rval; \
598+
__asm__ __volatile__("mfspr %0," WC_STRINGIFY(rn) : "=r" (rval)); rval; \
599+
})
596600

597601
#define mfmsr() ({ \
598602
unsigned int rval; \

hal/nxp_t2080.c

Lines changed: 129 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,8 @@ void hal_ddr_init(void)
230230
set_law(4, 0, DDR_ADDRESS, LAW_TRGT_DDR_1, LAW_SIZE_2GB, 0);
231231

232232
/* If DDR is already enabled then just return */
233-
if (get32(DDR_SDRAM_CFG) & DDR_SDRAM_CFG_MEM_EN) {
233+
reg = get32(DDR_SDRAM_CFG);
234+
if (reg & DDR_SDRAM_CFG_MEM_EN) {
234235
return;
235236
}
236237

@@ -369,6 +370,129 @@ static void hal_cpld_init(void)
369370
#endif
370371
}
371372

373+
#if defined(DEBUG_UART) && defined(ENABLE_DDR)
374+
/* DDR memory test - writes patterns and verifies readback */
375+
static int hal_ddr_test(void)
376+
{
377+
volatile uint32_t *ddr = (volatile uint32_t *)DDR_ADDRESS;
378+
uint32_t patterns[] = {0x55555555, 0xAAAAAAAA, 0x12345678, 0xDEADBEEF};
379+
uint32_t test_offsets[] = {0, 0x100, 0x1000, 0x10000, 0x100000, 0x1000000};
380+
int i, j;
381+
int errors = 0;
382+
uint32_t reg;
383+
384+
/* Show DDR controller status */
385+
reg = get32(DDR_SDRAM_CFG);
386+
wolfBoot_printf("DDR: SDRAM_CFG=0x%x (MEM_EN=%d)\n", reg,
387+
(reg & DDR_SDRAM_CFG_MEM_EN) ? 1 : 0);
388+
reg = get32(DDR_SDRAM_CFG_2);
389+
wolfBoot_printf("DDR: SDRAM_CFG_2=0x%x (D_INIT=%d)\n", reg,
390+
(reg & DDR_SDRAM_CFG_2_D_INIT) ? 1 : 0);
391+
392+
/* Show DDR LAW configuration (LAW 4) */
393+
wolfBoot_printf("DDR LAW4: H=0x%x L=0x%x AR=0x%x\n",
394+
get32(LAWBARH(4)), get32(LAWBARL(4)), get32(LAWAR(4)));
395+
396+
/* Read DDR TLB entry 12 using tlbre */
397+
{
398+
uint32_t mas0, mas1, mas2, mas3, mas7;
399+
/* Select TLB1, entry 12 */
400+
mas0 = (1 << 28) | (12 << 16); /* TLBSEL=1, ESEL=12 */
401+
mtspr(MAS0, mas0);
402+
__asm__ __volatile__("isync; tlbre; isync");
403+
mas1 = mfspr(MAS1);
404+
mas2 = mfspr(MAS2);
405+
mas3 = mfspr(MAS3);
406+
mas7 = mfspr(MAS7);
407+
wolfBoot_printf("DDR TLB12: MAS1=0x%x MAS2=0x%x MAS3=0x%x MAS7=0x%x\n",
408+
mas1, mas2, mas3, mas7);
409+
/* Check if TLB entry is valid */
410+
if (!(mas1 & 0x80000000)) {
411+
wolfBoot_printf("DDR: ERROR - TLB12 not valid!\n");
412+
return -1;
413+
}
414+
}
415+
416+
/* Check if DDR is enabled */
417+
if (!(get32(DDR_SDRAM_CFG) & DDR_SDRAM_CFG_MEM_EN)) {
418+
wolfBoot_printf("DDR: ERROR - Memory not enabled!\n");
419+
return -1;
420+
}
421+
422+
/* Check if DDR LAW is enabled */
423+
reg = get32(LAWAR(4));
424+
if (!(reg & LAWAR_ENABLE)) {
425+
wolfBoot_printf("DDR: ERROR - LAW4 not enabled!\n");
426+
return -1;
427+
}
428+
429+
/* Show DDR chip select configuration */
430+
wolfBoot_printf("DDR CS0: BNDS=0x%x CFG=0x%x\n",
431+
get32(DDR_CS_BNDS(0)), get32(DDR_CS_CONFIG(0)));
432+
wolfBoot_printf("DDR CS1: BNDS=0x%x CFG=0x%x\n",
433+
get32(DDR_CS_BNDS(1)), get32(DDR_CS_CONFIG(1)));
434+
435+
/* Show DDR debug status registers */
436+
wolfBoot_printf("DDR DDRDSR_1=0x%x DDRDSR_2=0x%x\n",
437+
get32(DDR_DDRDSR_1), get32(DDR_DDRDSR_2));
438+
wolfBoot_printf("DDR DDRCDR_1=0x%x DDRCDR_2=0x%x\n",
439+
get32(DDR_DDRCDR_1), get32(DDR_DDRCDR_2));
440+
441+
/* Check for pre-existing DDR errors */
442+
reg = get32(DDR_ERR_DETECT);
443+
wolfBoot_printf("DDR ERR_DETECT=0x%x\n", reg);
444+
if (reg != 0) {
445+
wolfBoot_printf("DDR: ERROR - Pre-existing DDR errors!\n");
446+
wolfBoot_printf(" Bit 31 (MME): %d - Multiple errors\n", (reg >> 31) & 1);
447+
wolfBoot_printf(" Bit 7 (APE): %d - Address parity\n", (reg >> 7) & 1);
448+
wolfBoot_printf(" Bit 3 (ACE): %d - Auto calibration\n", (reg >> 3) & 1);
449+
wolfBoot_printf(" Bit 2 (CDE): %d - Correctable data\n", (reg >> 2) & 1);
450+
wolfBoot_printf("DDR: Skipping memory test due to errors\n");
451+
return -1;
452+
}
453+
454+
wolfBoot_printf("DDR Test: base=0x%x\n", DDR_ADDRESS);
455+
wolfBoot_printf("DDR: Attempting simple read at 0x%x...\n", DDR_ADDRESS);
456+
457+
/* First just try to read - don't write yet */
458+
{
459+
volatile uint32_t val = *ddr;
460+
wolfBoot_printf("DDR: Read returned 0x%x\n", val);
461+
}
462+
463+
for (i = 0; i < (int)(sizeof(test_offsets)/sizeof(test_offsets[0])); i++) {
464+
uint32_t offset = test_offsets[i];
465+
volatile uint32_t *addr = ddr + (offset / sizeof(uint32_t));
466+
467+
for (j = 0; j < (int)(sizeof(patterns)/sizeof(patterns[0])); j++) {
468+
uint32_t pattern = patterns[j];
469+
uint32_t readback;
470+
471+
/* Write pattern */
472+
*addr = pattern;
473+
__asm__ __volatile__("sync" ::: "memory");
474+
475+
/* Read back */
476+
readback = *addr;
477+
478+
if (readback != pattern) {
479+
wolfBoot_printf(" FAIL: @0x%x wrote 0x%x read 0x%x\n",
480+
(uint32_t)addr, pattern, readback);
481+
errors++;
482+
}
483+
}
484+
}
485+
486+
if (errors == 0) {
487+
wolfBoot_printf("DDR Test: PASSED\n");
488+
} else {
489+
wolfBoot_printf("DDR Test: FAILED (%d errors)\n", errors);
490+
}
491+
492+
return errors;
493+
}
494+
#endif /* DEBUG_UART && ENABLE_DDR */
495+
372496
void hal_init(void)
373497
{
374498
#if defined(DEBUG_UART) && defined(ENABLE_CPLD)
@@ -401,6 +525,10 @@ void hal_init(void)
401525
#ifdef ENABLE_MP
402526
hal_mp_init();
403527
#endif
528+
529+
#if defined(DEBUG_UART) && defined(ENABLE_DDR)
530+
hal_ddr_test();
531+
#endif
404532
}
405533

406534
static void hal_flash_unlock_sector(uint32_t sector)

hal/nxp_t2080.h

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@ enum ifc_amask_sizes {
233233
#define DDR_TRTP_PS 7500
234234
#define DDR_REF_RATE_PS 7800000
235235

236+
/* DDR values from working U-Boot on NAII 68PPC2 board */
236237
#define DDR_CS0_BNDS_VAL 0x000000FF
237238
#define DDR_CS1_BNDS_VAL 0x010001FF
238239
#define DDR_CS2_BNDS_VAL 0x0300033F
@@ -243,29 +244,30 @@ enum ifc_amask_sizes {
243244
#define DDR_CS3_CONFIG_VAL 0x00040202
244245
#define DDR_CS_CONFIG_2_VAL 0x00000000
245246

246-
#define DDR_TIMING_CFG_0_VAL 0xFF550004
247-
#define DDR_TIMING_CFG_1_VAL 0xBCB48C56
248-
#define DDR_TIMING_CFG_2_VAL 0x0040C114
249-
#define DDR_TIMING_CFG_3_VAL 0x010C1000
247+
#define DDR_TIMING_CFG_0_VAL 0xFF530004
248+
#define DDR_TIMING_CFG_1_VAL 0x98906345
249+
#define DDR_TIMING_CFG_2_VAL 0x0040A114
250+
#define DDR_TIMING_CFG_3_VAL 0x010A1100
250251
#define DDR_TIMING_CFG_4_VAL 0x00000001
251-
#define DDR_TIMING_CFG_5_VAL 0x03402400
252+
#define DDR_TIMING_CFG_5_VAL 0x04402400
252253

253254
#define DDR_SDRAM_MODE_VAL 0x00441C70
254255
#define DDR_SDRAM_MODE_2_VAL 0x00980000
255256
#define DDR_SDRAM_MODE_3_8_VAL 0x00000000
256257
#define DDR_SDRAM_MD_CNTL_VAL 0x00000000
257258

258-
#define DDR_SDRAM_CFG_VAL 0xE7044000
259-
#define DDR_SDRAM_CFG_2_VAL 0x00401050
259+
#define DDR_SDRAM_CFG_VAL 0xE7040000
260+
#define DDR_SDRAM_CFG_2_VAL 0x00401000
260261

261262
#define DDR_SDRAM_INTERVAL_VAL 0x0C300100
262263
#define DDR_DATA_INIT_VAL 0xDEADBEEF
263264
#define DDR_SDRAM_CLK_CNTL_VAL 0x02400000
264265
#define DDR_ZQ_CNTL_VAL 0x89080600
265266

266-
#define DDR_WRLVL_CNTL_VAL 0x8675F608
267-
#define DDR_WRLVL_CNTL_2_VAL 0x080A0A0C
268-
#define DDR_WRLVL_CNTL_3_VAL 0x0C0E0E0D
267+
/* Write leveling - CRITICAL: board-specific values from U-Boot */
268+
#define DDR_WRLVL_CNTL_VAL 0x8675F604
269+
#define DDR_WRLVL_CNTL_2_VAL 0x05060607
270+
#define DDR_WRLVL_CNTL_3_VAL 0x080A0A0B
269271

270272
#define DDR_SDRAM_RCW_1_VAL 0x00000000
271273
#define DDR_SDRAM_RCW_2_VAL 0x00000000
@@ -317,6 +319,7 @@ enum ifc_amask_sizes {
317319
#define DDR_DDRCDR_2 ((volatile uint32_t*)(DDR_BASE + 0xB2C)) /* DDR Control Driver Register 2 */
318320
#define DDR_DDRDSR_1 ((volatile uint32_t*)(DDR_BASE + 0xB20)) /* DDR Debug Status Register 1 */
319321
#define DDR_DDRDSR_2 ((volatile uint32_t*)(DDR_BASE + 0xB24)) /* DDR Debug Status Register 2 */
322+
#define DDR_ERR_DETECT ((volatile uint32_t*)(DDR_BASE + 0xE40)) /* Memory error detect */
320323
#define DDR_ERR_DISABLE ((volatile uint32_t*)(DDR_BASE + 0xE44)) /* Memory error disable */
321324
#define DDR_ERR_INT_EN ((volatile uint32_t*)(DDR_BASE + 0xE48)) /* Memory error interrupt enable */
322325
#define DDR_ERR_SBE ((volatile uint32_t*)(DDR_BASE + 0xE58)) /* Single-Bit ECC memory error management */

hal/nxp_t2080.ld

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ MEMORY
1313
{
1414
FLASH (rx) : ORIGIN = @WOLFBOOT_ORIGIN@, LENGTH = @BOOTLOADER_PARTITION_SIZE@
1515

16-
/* CPC as SRAM - 512KB (T2080 supports up to 2MB, using 512KB)
16+
/* CPC as SRAM - 1MB (T2080 supports up to 2MB, using 1MB for P384 stack)
1717
* Layout: .ramcode at bottom, stack grows down from top */
18-
RAM (rwx) : ORIGIN = 0xF8F80000, LENGTH = 0x80000
18+
RAM (rwx) : ORIGIN = 0xF8F00000, LENGTH = 0x100000
1919

2020
/* DDR - 2GB */
2121
DRAM (rwx) : ORIGIN = 0x00000000, LENGTH = 0x7FFFFFFF

src/boot_ppc_start.S

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -596,8 +596,8 @@ cpc_poll_invalidate:
596596
stw r0, CPCSRCR1(r1) /* SRAM high address = 0 */
597597
/* SRAM low address - use LOAD_ADDR32 on e6500 to avoid sign extension */
598598
LOAD_ADDR32(r0, L2SRAM_ADDR)
599-
/* Enable SRAM and set size (must match L2SRAM_SIZE = 512KB) */
600-
ori r0, r0, (CPCSRCR0_SRAMSZ_512 | CPCSRCR0_SRAMEN)
599+
/* Enable SRAM and set size (must match L2SRAM_SIZE = 1MB for P384) */
600+
ori r0, r0, (CPCSRCR0_SRAMSZ_1024 | CPCSRCR0_SRAMEN)
601601
stw r0, CPCSRCR0(r1)
602602
mbar
603603
isync

0 commit comments

Comments
 (0)