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
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 )
5457static 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 ;
14051409extern uint32_t _spin_table ;
1410+ extern uint32_t _spin_table_addr ;
14061411extern uint32_t _bootpg_addr ;
14071412
14081413/* Startup additional cores with spin table and synchronize the timebase */
14091414static 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
14811481static 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 */
0 commit comments