3131/* #define DEBUG_FLASH */
3232
3333#ifndef BUILD_LOADER_STAGE1
34- #ifndef BOARD_CW_VPX3152
35- /* CW VPX3-152: hal_mp_init() calls disable_tlb1(0) which invalidates the
36- * 16 MB boot TLB Entry 0 (which contains wolfBoot code). Without a separate
37- * flash TLB entry covering wolfBoot's code, the next instruction fetch
38- * faults. NAII works because its 256 KB boot TLB doesn't cover wolfBoot
39- * code (which is in flash TLB Entry 2 at 0xE8000000-0xEFFFFFFF).
40- * For VPX3-152, secondary cores remain disabled. */
4134 #define ENABLE_MP /* multi-core support */
4235#endif
43- #endif
4436
4537/* generic shared NXP QorIQ driver code */
4638#include "nxp_ppc.c"
@@ -80,6 +72,12 @@ static void hal_mp_init(void);
8072#define FLASH_UNLOCK_ADDR2 0x555
8173#endif
8274
75+ /* FLASH_CMD_SECTOR: sector used for flash command sequences that don't target
76+ * a specific sector (reset, unlock, PPB entry/exit). AMD flash command decode
77+ * only looks at the low address bits, so sector 0 works for all boards with
78+ * a properly mapped full-flash TLB entry. */
79+ #define FLASH_CMD_SECTOR 0
80+
8381/* Flash IO Helpers */
8482#if FLASH_CFI_WIDTH == 16
8583#define FLASH_IO8_WRITE (sec , n , val ) *((volatile uint16_t*)(FLASH_BASE_ADDR + (FLASH_SECTOR_SIZE * (sec)) + ((n) * 2))) = (((val) << 8) | (val))
@@ -375,15 +373,9 @@ static void hal_reconfigure_cpc_as_cache(void)
375373
376374/* Make flash TLB cacheable for XIP code performance.
377375 * Changes TLB Entry 2 (flash) from MAS2_I|MAS2_G to MAS2_M.
378- * This enables L1 I-cache + L2 + CPC to cache flash instructions.
379- *
380- * For BOARD_CW_VPX3152: TLB1 Entry 2 is NOT used (256 MB flash TLB would
381- * overlap with the 16 MB boot ROM TLB at the top of flash, causing e6500
382- * multi-hit). The boot TLB covers wolfBoot + partitions cache-inhibited;
383- * skip the caching update — flash runs uncached (slower but correct). */
376+ * This enables L1 I-cache + L2 + CPC to cache flash instructions. */
384377static void hal_flash_enable_caching (void )
385378{
386- #ifndef BOARD_CW_VPX3152
387379 /* Rewrite flash TLB entry with cacheable attributes.
388380 * MAS2_M = memory coherent, enables caching */
389381 set_tlb (1 , 2 ,
@@ -393,7 +385,6 @@ static void hal_flash_enable_caching(void)
393385
394386 /* Invalidate L1 I-cache so new TLB attributes take effect */
395387 invalidate_icache ();
396- #endif
397388
398389#ifdef DEBUG_UART
399390 wolfBoot_printf ("Flash: caching enabled (L1+L2+CPC)\n" );
@@ -481,21 +472,17 @@ void hal_init(void)
481472 * returns a bus error (DSI). */
482473static void RAMFUNCTION hal_flash_cache_disable (void )
483474{
484- #ifndef BOARD_CW_VPX3152
485475 set_tlb (1 , 2 , FLASH_BASE_ADDR , FLASH_BASE_ADDR , FLASH_BASE_PHYS_HIGH ,
486476 MAS3_SX | MAS3_SW | MAS3_SR , MAS2_I | MAS2_G , 0 , FLASH_TLB_PAGESZ , 1 );
487- #endif
488477}
489478
490479/* Restore flash TLB to cacheable mode after flash operation.
491480 * Flash must be back in read-array mode before calling (AMD_CMD_RESET sent).
492481 * Invalidate caches afterward so stale pre-erase data is not served. */
493482static void RAMFUNCTION hal_flash_cache_enable (void )
494483{
495- #ifndef BOARD_CW_VPX3152
496484 set_tlb (1 , 2 , FLASH_BASE_ADDR , FLASH_BASE_ADDR , FLASH_BASE_PHYS_HIGH ,
497485 MAS3_SX | MAS3_SW | MAS3_SR , MAS2_M , 0 , FLASH_TLB_PAGESZ , 1 );
498- #endif
499486 invalidate_dcache ();
500487 invalidate_icache ();
501488}
@@ -539,9 +526,9 @@ static int RAMFUNCTION hal_flash_ppb_unlock(uint32_t sector)
539526 uint32_t timeout ;
540527
541528 /* Enter PPB ASO (Address Space Overlay) */
542- FLASH_IO8_WRITE (0 , FLASH_UNLOCK_ADDR1 , AMD_CMD_UNLOCK_START );
543- FLASH_IO8_WRITE (0 , FLASH_UNLOCK_ADDR2 , AMD_CMD_UNLOCK_ACK );
544- FLASH_IO8_WRITE (0 , FLASH_UNLOCK_ADDR1 , AMD_CMD_SET_PPB_ENTRY );
529+ FLASH_IO8_WRITE (FLASH_CMD_SECTOR , FLASH_UNLOCK_ADDR1 , AMD_CMD_UNLOCK_START );
530+ FLASH_IO8_WRITE (FLASH_CMD_SECTOR , FLASH_UNLOCK_ADDR2 , AMD_CMD_UNLOCK_ACK );
531+ FLASH_IO8_WRITE (FLASH_CMD_SECTOR , FLASH_UNLOCK_ADDR1 , AMD_CMD_SET_PPB_ENTRY );
545532
546533 /* Read PPB status for target sector: DQ0=0 means protected.
547534 * On 16-bit bus, must read both chip lanes to check both devices. */
@@ -553,16 +540,16 @@ static int RAMFUNCTION hal_flash_ppb_unlock(uint32_t sector)
553540 if ((ppb_status & 0x01 ) == 0x01 ) {
554541#endif
555542 /* Both chips report unprotected — exit PPB mode and return */
556- FLASH_IO8_WRITE (0 , 0 , AMD_CMD_SET_PPB_EXIT_BC1 );
557- FLASH_IO8_WRITE (0 , 0 , AMD_CMD_SET_PPB_EXIT_BC2 );
543+ FLASH_IO8_WRITE (FLASH_CMD_SECTOR , 0 , AMD_CMD_SET_PPB_EXIT_BC1 );
544+ FLASH_IO8_WRITE (FLASH_CMD_SECTOR , 0 , AMD_CMD_SET_PPB_EXIT_BC2 );
558545 return 0 ;
559546 }
560547
561548 /* Exit PPB ASO before calling printf (flash must be in read-array
562549 * mode for I-cache misses to fetch valid instructions) */
563- FLASH_IO8_WRITE (0 , 0 , AMD_CMD_SET_PPB_EXIT_BC1 );
564- FLASH_IO8_WRITE (0 , 0 , AMD_CMD_SET_PPB_EXIT_BC2 );
565- FLASH_IO8_WRITE (0 , 0 , AMD_CMD_RESET );
550+ FLASH_IO8_WRITE (FLASH_CMD_SECTOR , 0 , AMD_CMD_SET_PPB_EXIT_BC1 );
551+ FLASH_IO8_WRITE (FLASH_CMD_SECTOR , 0 , AMD_CMD_SET_PPB_EXIT_BC2 );
552+ FLASH_IO8_WRITE (FLASH_CMD_SECTOR , 0 , AMD_CMD_RESET );
566553 udelay (50 );
567554
568555#ifdef DEBUG_FLASH
@@ -571,36 +558,36 @@ static int RAMFUNCTION hal_flash_ppb_unlock(uint32_t sector)
571558#endif
572559
573560 /* Re-enter PPB ASO for erase */
574- FLASH_IO8_WRITE (0 , FLASH_UNLOCK_ADDR1 , AMD_CMD_UNLOCK_START );
575- FLASH_IO8_WRITE (0 , FLASH_UNLOCK_ADDR2 , AMD_CMD_UNLOCK_ACK );
576- FLASH_IO8_WRITE (0 , FLASH_UNLOCK_ADDR1 , AMD_CMD_SET_PPB_ENTRY );
561+ FLASH_IO8_WRITE (FLASH_CMD_SECTOR , FLASH_UNLOCK_ADDR1 , AMD_CMD_UNLOCK_START );
562+ FLASH_IO8_WRITE (FLASH_CMD_SECTOR , FLASH_UNLOCK_ADDR2 , AMD_CMD_UNLOCK_ACK );
563+ FLASH_IO8_WRITE (FLASH_CMD_SECTOR , FLASH_UNLOCK_ADDR1 , AMD_CMD_SET_PPB_ENTRY );
577564
578565 /* PPB Erase All (clears all sectors' PPBs) */
579- FLASH_IO8_WRITE (0 , 0 , AMD_CMD_PPB_UNLOCK_BC1 ); /* 0x80 */
580- FLASH_IO8_WRITE (0 , 0 , AMD_CMD_PPB_UNLOCK_BC2 ); /* 0x30 */
566+ FLASH_IO8_WRITE (FLASH_CMD_SECTOR , 0 , AMD_CMD_PPB_UNLOCK_BC1 ); /* 0x80 */
567+ FLASH_IO8_WRITE (FLASH_CMD_SECTOR , 0 , AMD_CMD_PPB_UNLOCK_BC2 ); /* 0x30 */
581568
582569 /* Wait for PPB erase completion — poll for toggle stop.
583570 * On 16-bit bus, read both chip lanes to ensure both complete. */
584571 timeout = 0 ;
585572 do {
586573#if FLASH_CFI_WIDTH == 16
587- read1 = FLASH_IO16_READ (0 , 0 );
588- read2 = FLASH_IO16_READ (0 , 0 );
574+ read1 = FLASH_IO16_READ (FLASH_CMD_SECTOR , 0 );
575+ read2 = FLASH_IO16_READ (FLASH_CMD_SECTOR , 0 );
589576#else
590- read1 = FLASH_IO8_READ (0 , 0 );
591- read2 = FLASH_IO8_READ (0 , 0 );
577+ read1 = FLASH_IO8_READ (FLASH_CMD_SECTOR , 0 );
578+ read2 = FLASH_IO8_READ (FLASH_CMD_SECTOR , 0 );
592579#endif
593580 if (read1 == read2 )
594581 break ;
595582 udelay (10 );
596583 } while (timeout ++ < 100000 ); /* 1 second */
597584
598585 /* Exit PPB ASO */
599- FLASH_IO8_WRITE (0 , 0 , AMD_CMD_SET_PPB_EXIT_BC1 );
600- FLASH_IO8_WRITE (0 , 0 , AMD_CMD_SET_PPB_EXIT_BC2 );
586+ FLASH_IO8_WRITE (FLASH_CMD_SECTOR , 0 , AMD_CMD_SET_PPB_EXIT_BC1 );
587+ FLASH_IO8_WRITE (FLASH_CMD_SECTOR , 0 , AMD_CMD_SET_PPB_EXIT_BC2 );
601588
602589 /* Reset to read-array mode */
603- FLASH_IO8_WRITE (0 , 0 , AMD_CMD_RESET );
590+ FLASH_IO8_WRITE (FLASH_CMD_SECTOR , 0 , AMD_CMD_RESET );
604591 udelay (50 );
605592
606593 if (timeout >= 100000 ) {
@@ -717,7 +704,7 @@ int RAMFUNCTION hal_flash_write(uint32_t address, const uint8_t *data, int len)
717704
718705 /* Reset flash to read-array mode in case previous operation left it
719706 * in command mode (e.g. after a timeout or incomplete operation) */
720- FLASH_IO8_WRITE (0 , 0 , AMD_CMD_RESET );
707+ FLASH_IO8_WRITE (FLASH_CMD_SECTOR , 0 , AMD_CMD_RESET );
721708 udelay (50 );
722709
723710 /* Program one word at a time using AMD single-word program (0xA0).
@@ -788,7 +775,7 @@ int RAMFUNCTION hal_flash_erase(uint32_t address, int len)
788775
789776 /* Reset flash to read-array mode in case previous operation left it
790777 * in command mode (e.g. after a timeout or incomplete operation) */
791- FLASH_IO8_WRITE (0 , 0 , AMD_CMD_RESET );
778+ FLASH_IO8_WRITE (FLASH_CMD_SECTOR , 0 , AMD_CMD_RESET );
792779 udelay (50 );
793780
794781 while (len > 0 ) {
@@ -1033,14 +1020,7 @@ void hal_prepare_boot(void)
10331020#ifdef MMU
10341021void * hal_get_dts_address (void )
10351022{
1036- #ifdef BOARD_CW_VPX3152
1037- /* DTS is at 0xF0040000 which is below the 16 MB boot TLB
1038- * (covers 0xFF000000-0xFFFFFFFF). Return NULL to skip DTS loading
1039- * until a separate flash TLB is added for the DTS region. */
1040- return NULL ;
1041- #else
10421023 return (void * )WOLFBOOT_DTS_BOOT_ADDRESS ;
1043- #endif
10441024}
10451025
10461026int hal_dts_fixup (void * dts_addr )
0 commit comments