| 1 | /************************************************************************* |
|---|
| 2 | ** Broadcom Corp. Confidential |
|---|
| 3 | ** Copyright 2010 Broadcom Corp. All Rights Reserved. |
|---|
| 4 | ** |
|---|
| 5 | ** THIS SOFTWARE MAY ONLY BE USED SUBJECT TO AN EXECUTED SOFTWARE LICENSE |
|---|
| 6 | ** AGREEMENT BETWEEN THE USER AND BROADCOM. YOU HAVE NO RIGHT TO USE OR |
|---|
| 7 | ** EXPLOIT THIS MATERIAL EXCEPT SUBJECT TO THE TERMS OF SUCH AN AGREEMENT. |
|---|
| 8 | ** |
|---|
| 9 | ** File: bls1.S |
|---|
| 10 | ** Description: stage 1 of two stage bootloader for 755x chip. |
|---|
| 11 | ** Created: alexp |
|---|
| 12 | ** |
|---|
| 13 | ** REVISION: |
|---|
| 14 | ** |
|---|
| 15 | ***************************************************************************/ |
|---|
| 16 | |
|---|
| 17 | #include "bmips3300.h" |
|---|
| 18 | #include "bchp.h" |
|---|
| 19 | #include "bchp_common.h" |
|---|
| 20 | #include "bchp_sun_top_ctrl.h" |
|---|
| 21 | #include "bchp_memc_ddr23_aphy_ac_0.h" |
|---|
| 22 | #include "memc_0_config.h" |
|---|
| 23 | #include "chip_secure.physical_7550.h" |
|---|
| 24 | |
|---|
| 25 | #define SHMOO_STACK_START 0x80000000 |
|---|
| 26 | #define SHMOO_STACK_SIZE 0x4000 |
|---|
| 27 | |
|---|
| 28 | #define BCHP_REG_BASE PHYS_TO_K1(BCHP_PHYSICAL_OFFSET) |
|---|
| 29 | #define INITIAL_SR ((CP0_STATUS_SR_MASK | CP0_STATUS_CU1_MASK | CP0_STATUS_BEV_MASK | CP0_STATUS_IE_MASK) & ~( CP0_STATUS_ERL_MASK | CP0_STATUS_EXL_MASK)) |
|---|
| 30 | BL_STACK_SIZE = 0x1000 |
|---|
| 31 | #if defined(RSA_BITS) |
|---|
| 32 | RSA_KEY_SIZE = (RSA_BITS/8) |
|---|
| 33 | #else |
|---|
| 34 | RSA_KEY_SIZE = 0x80 |
|---|
| 35 | #endif |
|---|
| 36 | .lcomm bl_stack, BL_STACK_SIZE |
|---|
| 37 | .text |
|---|
| 38 | .globl __start |
|---|
| 39 | .set noreorder |
|---|
| 40 | |
|---|
| 41 | __start: |
|---|
| 42 | b init_cpu |
|---|
| 43 | nop |
|---|
| 44 | nop |
|---|
| 45 | nop |
|---|
| 46 | /* size of stage1+stage2 */ |
|---|
| 47 | .word _bootloader_size |
|---|
| 48 | .org __start+0x380 |
|---|
| 49 | rom_gen_ex: # general exception will loop here |
|---|
| 50 | b rom_gen_ex |
|---|
| 51 | nop |
|---|
| 52 | nop |
|---|
| 53 | nop |
|---|
| 54 | .org __start+0x400 |
|---|
| 55 | .globl key1 |
|---|
| 56 | key1: |
|---|
| 57 | .include "BCM7572_UDTA_key1_m0.S" |
|---|
| 58 | /* .include "test_key1_m0.S" */ |
|---|
| 59 | /* .include "test1024_key1.S" */ |
|---|
| 60 | /* .include "example_key1.S"*/ |
|---|
| 61 | external_root_key: |
|---|
| 62 | .fill RSA_KEY_SIZE, 1, 0xdd |
|---|
| 63 | bootloader_signature: |
|---|
| 64 | .fill RSA_KEY_SIZE, 1, 0xee |
|---|
| 65 | bootloader_header: |
|---|
| 66 | .fill 0x40, 1, 0x55 |
|---|
| 67 | init_cpu: |
|---|
| 68 | li t0, INITIAL_SR |
|---|
| 69 | mtc0 t0, CP0_STATUS |
|---|
| 70 | nop |
|---|
| 71 | nop |
|---|
| 72 | |
|---|
| 73 | move $28, $0 |
|---|
| 74 | .if 0 /* Surendra and Andrew indicate this is needed in the bootloader */ |
|---|
| 75 | /* DRAM for HD DTA */ |
|---|
| 76 | li t0, BCHP_REG_BASE | BCHP_MEMC_DDR23_APHY_AC_0_PLL_FREQ_CNTL |
|---|
| 77 | lw t2, 0(t0) |
|---|
| 78 | and t3, t2, ~BCHP_MEMC_DDR23_APHY_AC_0_PLL_FREQ_CNTL_MDIV_MASK |
|---|
| 79 | or t3, (5 << BCHP_MEMC_DDR23_APHY_AC_0_PLL_FREQ_CNTL_MDIV_SHIFT) |
|---|
| 80 | sw t3, 0(t0) |
|---|
| 81 | sync |
|---|
| 82 | .endif |
|---|
| 83 | /* check if otp_rom_uart_disable bit is set */ |
|---|
| 84 | li t0, BCHP_REG_BASE | XPT_OTP_MSP_WORD_8 |
|---|
| 85 | lw t2, 0(t0) |
|---|
| 86 | andi t2, 0x10 |
|---|
| 87 | bnez t2, skip_uart_init |
|---|
| 88 | nop |
|---|
| 89 | |
|---|
| 90 | bal init_serial |
|---|
| 91 | nop |
|---|
| 92 | |
|---|
| 93 | bal _writeasm |
|---|
| 94 | li a0, '$' |
|---|
| 95 | skip_uart_init: |
|---|
| 96 | bal do_chip_init |
|---|
| 97 | nop |
|---|
| 98 | |
|---|
| 99 | bal _writeasm |
|---|
| 100 | li a0, '?' |
|---|
| 101 | |
|---|
| 102 | bal init_mips |
|---|
| 103 | nop |
|---|
| 104 | |
|---|
| 105 | bal _writeasm |
|---|
| 106 | li a0, '+' |
|---|
| 107 | |
|---|
| 108 | li a0, SHMOO_STACK_START |
|---|
| 109 | li a1, SHMOO_STACK_SIZE |
|---|
| 110 | bal lock_d_cache |
|---|
| 111 | nop |
|---|
| 112 | |
|---|
| 113 | /* now initialize sp to stack start */ |
|---|
| 114 | la sp, (SHMOO_STACK_START + SHMOO_STACK_SIZE - 48) |
|---|
| 115 | # create a stack space for the the memc_init arguments. |
|---|
| 116 | addiu sp, -16 |
|---|
| 117 | # load parameters in a0-a3 for memc_init |
|---|
| 118 | |
|---|
| 119 | /*int memc_init(int32_t memc_num_to_shmoo, int32_t write_dqs_shmoo_range, uint32_t num_byte_slices, uint32_t gate_value) |
|---|
| 120 | */ |
|---|
| 121 | li a0, 0x0 |
|---|
| 122 | lui a1, MEMC_0_DEFAULT_WRITE_DQS_PHASE_RANGE_UPPER |
|---|
| 123 | ori a1, MEMC_0_DEFAULT_WRITE_DQS_PHASE_RANGE_LOWER |
|---|
| 124 | li a2, 2 #16bit DDR |
|---|
| 125 | li a3, MEMC_0_DEFAULT_GATE_VALUE |
|---|
| 126 | |
|---|
| 127 | la t0, memc_init |
|---|
| 128 | jalr t0 |
|---|
| 129 | nop |
|---|
| 130 | #if defined(BOOT_SCRAMBLE_DRAM) |
|---|
| 131 | #if (BCHP_VER>=BCHP_VER_B0) |
|---|
| 132 | la t0, do_dram_scramble |
|---|
| 133 | #else |
|---|
| 134 | la t0, scramble_dram |
|---|
| 135 | #endif |
|---|
| 136 | jalr t0 |
|---|
| 137 | nop |
|---|
| 138 | #endif |
|---|
| 139 | bal _writeasm |
|---|
| 140 | li a0, 'H' |
|---|
| 141 | |
|---|
| 142 | /* index-writeback-invalidate-d */ |
|---|
| 143 | bal clear_all_d_cache |
|---|
| 144 | nop |
|---|
| 145 | |
|---|
| 146 | bal _writeasm |
|---|
| 147 | li a0, 'E' |
|---|
| 148 | bal _writeasm |
|---|
| 149 | li a0, 'L' |
|---|
| 150 | |
|---|
| 151 | /* clear bss segment */ |
|---|
| 152 | la a0,_fbss |
|---|
| 153 | la a1,_end |
|---|
| 154 | subu a1,a1,a0 |
|---|
| 155 | |
|---|
| 156 | beqz a1, 2f |
|---|
| 157 | nop |
|---|
| 158 | 1: |
|---|
| 159 | sw zero,0(a0) |
|---|
| 160 | sub a1, a1, 4 |
|---|
| 161 | addi a0, a0, 4 |
|---|
| 162 | bnez a1, 1b |
|---|
| 163 | nop |
|---|
| 164 | 2: |
|---|
| 165 | la sp, (bl_stack + BL_STACK_SIZE - 48) |
|---|
| 166 | |
|---|
| 167 | la a0, _stage2_start |
|---|
| 168 | la a1, __start_s2 |
|---|
| 169 | la a2, _stage2_size |
|---|
| 170 | bal aligned_copy |
|---|
| 171 | nop |
|---|
| 172 | bal _writeasm |
|---|
| 173 | li a0, 'L' |
|---|
| 174 | |
|---|
| 175 | /* index-writeback-invalidate-d */ |
|---|
| 176 | bal clear_all_d_cache |
|---|
| 177 | nop |
|---|
| 178 | jal stage1_main |
|---|
| 179 | nop |
|---|
| 180 | bal _writeasm |
|---|
| 181 | li a0, 'O' |
|---|
| 182 | |
|---|
| 183 | la t0,__start_s2 |
|---|
| 184 | or t0, 0x20000000 |
|---|
| 185 | jalr t0 |
|---|
| 186 | nop |
|---|
| 187 | loop: |
|---|
| 188 | b loop |
|---|
| 189 | nop |
|---|
| 190 | |
|---|
| 191 | |
|---|
| 192 | LEAF(aligned_copy) |
|---|
| 193 | |
|---|
| 194 | 1: |
|---|
| 195 | lw v0, 0(a0) |
|---|
| 196 | addiu a2, a2, -4 |
|---|
| 197 | sw v0, 0(a1) |
|---|
| 198 | addiu a0, a0, 4 |
|---|
| 199 | bnez a2, 1b |
|---|
| 200 | addiu a1, a1, 4 |
|---|
| 201 | |
|---|
| 202 | jr ra |
|---|
| 203 | nop |
|---|
| 204 | |
|---|
| 205 | END(aligned_copy) |
|---|
| 206 | |
|---|
| 207 | .if 0 |
|---|
| 208 | /* test routine */ |
|---|
| 209 | LEAF(word_compare) |
|---|
| 210 | |
|---|
| 211 | 1: |
|---|
| 212 | lw v0, 0(a0) |
|---|
| 213 | addiu a2, a2, -4 |
|---|
| 214 | lw v1, 0(a1) |
|---|
| 215 | 2: |
|---|
| 216 | bne v0,v1, 2b |
|---|
| 217 | nop |
|---|
| 218 | |
|---|
| 219 | addiu a0, a0, 4 |
|---|
| 220 | bnez a2, 1b |
|---|
| 221 | addiu a1, a1, 4 |
|---|
| 222 | |
|---|
| 223 | jr ra |
|---|
| 224 | nop |
|---|
| 225 | |
|---|
| 226 | END(word_compare) |
|---|
| 227 | .endif |
|---|
| 228 | |
|---|
| 229 | #include "uart.s" |
|---|
| 230 | #include "chip.s" |
|---|
| 231 | #undef RelAddrPrintChar |
|---|
| 232 | #undef RelAddrPrintHex32 |
|---|
| 233 | #undef SHMOO_STACK_START |
|---|
| 234 | #undef SHMOO_STACK_SIZE |
|---|
| 235 | #include "common_routines.s" |
|---|
| 236 | #include "memc_0_client_prog.s" |
|---|
| 237 | #include "memc_0_access.s" |
|---|
| 238 | #include "run_shmoo.s" |
|---|
| 239 | #include "cache_lib.s" |
|---|
| 240 | #include "mips_libs.s" |
|---|
| 241 | #if defined(BOOT_SCRAMBLE_DRAM) |
|---|
| 242 | #undef REG |
|---|
| 243 | #if (BCHP_VER<BCHP_VER_B0) |
|---|
| 244 | #include "scramble_dram.s" |
|---|
| 245 | #endif |
|---|
| 246 | #endif |
|---|