navienginebsp/ne1_tb/bootstrap/miniboot.s
changeset 0 5de814552237
equal deleted inserted replaced
-1:000000000000 0:5de814552237
       
     1 ;
       
     2 ; Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 ; All rights reserved.
       
     4 ; This component and the accompanying materials are made available
       
     5 ; under the terms of "Eclipse Public License v1.0"
       
     6 ; which accompanies this distribution, and is available
       
     7 ; at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 ;
       
     9 ; Initial Contributors:
       
    10 ; Nokia Corporation - initial contribution.
       
    11 ;
       
    12 ; Contributors:
       
    13 ;
       
    14 ; Description:  
       
    15 ; \ne1_tb\bootstrap\miniboot.s
       
    16 ; Code to retrieve the core loader image from the NAND flash and
       
    17 ; run it. Expects that the system is in a state where NAND can be
       
    18 ; read and SDRAM can be written.
       
    19 ; See variant_bootstrap.inc for the variant specfic constants 
       
    20 ; Where in RAM should the core loader be copied to (LINKBASE of coreldr)
       
    21 ; There is a companion to this value in the coreloader makefile, they must
       
    22 ; match!
       
    23 ;
       
    24 
       
    25 	INCLUDE e32rom.inc
       
    26 	INCLUDE naviengine.inc
       
    27 
       
    28 KMinibootStackAddr              EQU     0x820003FC
       
    29 KRAMBase						EQU		0x80000000		; base of ram
       
    30 
       
    31 KNandPageSize	EQU	2048
       
    32 KPageByteShift	EQU	11
       
    33 
       
    34 ;Command Set Reg Bits
       
    35 KNandBusyBit	 EQU 0x0100
       
    36 KNandPageReadBM  EQU 0x0101
       
    37 KNandResetBM	 EQU 0x0106
       
    38 
       
    39 ;ECC Reg Bits
       
    40 KNandECCDRC		 EQU 0x0080
       
    41 
       
    42 ; NAND Register Addresses
       
    43 KNandDataWndw		EQU 0x18019000;
       
    44 KNandPgeAdr1Reg 	EQU 0x18019840;
       
    45 KNandPgeAdr2Reg 	EQU 0x18019842;
       
    46 KNandPgeAdrMskReg0 	EQU 0x18019844;
       
    47 KNandPgeAdrMskReg1 	EQU 0x18019846;
       
    48 KNandPgeAdrMskReg2 	EQU 0x18019848;
       
    49 KNandPgeAdrMskReg3 	EQU 0x1801984A;
       
    50 KNandCmdSetReg	  	EQU 0x1801984E;
       
    51 KNandDataAreaECCReg EQU 0x18019850;
       
    52 KNandROMTypeSetup1	EQU 0x18019852;
       
    53 KNandROMTypeSetup2	EQU 0x18019854;
       
    54 KNandChipSelect	  	EQU 0x18019856;
       
    55 
       
    56 
       
    57 ; Which page in NAND holds the Coreldr image
       
    58 KSymbianCoreldrPage			EQU		1 	;
       
    59 KSymbianCoreldrSizePages	EQU		64	; 64 * 2048B = 128KB
       
    60 
       
    61 ; Export the miniboot's only entry point
       
    62 	EXPORT	GetCoreldr
       
    63 
       
    64 ;
       
    65 ; Area definition for ARMLD linker
       
    66 ;
       
    67 	AREA |Boot$$Code|, CODE, READONLY, ALIGN=6
       
    68 
       
    69 ;******************************************************************************
       
    70 ; Boot Entry point for bootloader's miniboot code
       
    71 ;
       
    72 ;	Always runs
       
    73 ;		after the bootloader has initialised the memory subsystem
       
    74 ;		with the SRAM/SDRAM devices available. (RAM >0x8000.0000)
       
    75 ;
       
    76 ;	Tasks
       
    77 ;		Confirm NAND device is as expected
       
    78 ;		read TOC structure at the start of the NAND (in page 0)
       
    79 ;		search TOC array for coreloader image entry
       
    80 ;		load coreloader sized image from NAND offset (from TOC)
       
    81 ;		jump to coreloader entry point
       
    82 ;
       
    83 ;******************************************************************************
       
    84 
       
    85 GetCoreldr
       
    86 	; create a stack so that we can use ordinary function calls
       
    87 	ldr		r13, =KMinibootStackAddr
       
    88 	
       
    89 	; RESET_NAND
       
    90 	LDR		r0, =KNandResetBM 	; CMD_RESET | XROMC_BUSY_BIT_MASK
       
    91 	LDR		r4, =KNandCmdSetReg	; XROMC
       
    92 	STRH	r0, [r4]
       
    93 	
       
    94 	; POLLED_WAIT_FOR_RDY
       
    95 1
       
    96 	LDR		r4, =KNandCmdSetReg  	
       
    97 	LDRH	r0, [r4]				; Get contents of Command setup register
       
    98 	TST		r0, #KNandBusyBit
       
    99 	BNE		%B1	
       
   100 
       
   101 	; Start from a clean, ready system state
       
   102 	; INIT_PNL_DEVICE
       
   103 	LDR		r0, =0xF000	;Unmask address for XROMM0-3
       
   104 	LDR		r4, =KNandPgeAdrMskReg0 
       
   105 	STRH	r0,	[r4]
       
   106 	
       
   107 	LDR		r4, =KNandPgeAdrMskReg1 
       
   108 	STRH	r0,	[r4]
       
   109 	
       
   110 	LDR		r4, =KNandPgeAdrMskReg2 
       
   111 	STRH	r0,	[r4]
       
   112 	
       
   113 	LDR		r4, =KNandPgeAdrMskReg3 
       
   114 	STRH	r0,	[r4]
       
   115 		
       
   116 	;Configure the NAND Type
       
   117 	;CS1 NAND Config: 8bit, 2K
       
   118 	;CS2 NAND Config: 8bit, 2K
       
   119 	LDR		r0,	=0x0101
       
   120 	LDR		r4,	=KNandROMTypeSetup1
       
   121 	STRH	r0,	[r4]
       
   122 	;CS3 NAND Config: 8bit, 2K
       
   123 	LDR		r0,	=0x01
       
   124 	LDR		r4,	=KNandROMTypeSetup2
       
   125 	STRH	r0,	[r4]
       
   126 	
       
   127 	; Select chipset 0 to be used (navi supports upto 4 NAND chips)
       
   128 	LDR		r0, =0x0000	;Select ChipSet 0
       
   129 	LDR		r4, =KNandChipSelect 
       
   130 	STRH	r0,	[r4]
       
   131 
       
   132 	LDR 	r4,=KNandDataAreaECCReg
       
   133 	LDRH	r0,	[r4] ; get contents of register
       
   134 	BIC		r0, r0, #0x1
       
   135 	STRH	r0, [r4] 
       
   136 
       
   137 
       
   138 	; Normally Read the device ID and confirm nand device is as expected
       
   139 	; NAND Controller on NaviEngine doesn't allow the Device id to be read
       
   140 
       
   141 	bl		readhdr16						; read header of 16bit device
       
   142 	; Readhdr16 -> parse_header -> find/load Symbian coreldr -> run coreldr
       
   143 	
       
   144 
       
   145 ;------------------------------------------------------------------------
       
   146 ;
       
   147 ; strcmp - bytewise compare of two strings
       
   148 ;	r0->string A
       
   149 ;	r1->string B
       
   150 ;	r3->size of string A
       
   151 ;
       
   152 ;	if string A == string B return 0 in r0
       
   153 ;	else returns non zero in r0
       
   154 ;
       
   155 ;------------------------------------------------------------------------
       
   156 strcmp	ROUT
       
   157 	stmfd	r13!, {r4-r6,lr}
       
   158 
       
   159 	mov		r4, r0
       
   160 	mov		r5, r1
       
   161 	mov		r6, r3
       
   162 	
       
   163 strloop
       
   164 	ldrb	r2, [r4], #1
       
   165 	ldrb	r3, [r5], #1
       
   166 	
       
   167 	subs	r0, r2, r3
       
   168 	cmp		r2, #0
       
   169 	beq		strreturn
       
   170 	subs	r6, r6, #1
       
   171 	bne		strloop
       
   172 strreturn
       
   173 	ldmfd	r13!, {r4-r6,pc}
       
   174 
       
   175 
       
   176 ;---------------------------------------------------------------------------------
       
   177 ; readpage16
       
   178 ;
       
   179 ;	read 1 page (2048KB) of NAND device,
       
   180 ;	starting at page (r0)
       
   181 ;	put data into address (r1)
       
   182 ;
       
   183 ;---------------------------------------------------------------------------------
       
   184 readpage16	ROUT
       
   185 	stmfd	r13!, {r4-r7,lr}
       
   186 
       
   187 	; set the page start addresss [r0]
       
   188 	; need multiple by page size to get correct address
       
   189 	MOV		r6, #KNandPageSize ; 2048
       
   190 	
       
   191 	;Set Address Reg1 (lower range)
       
   192 	MUL		r7, r0, r6
       
   193 	LDR		r4, =KNandPgeAdr1Reg 
       
   194 	STRH	r7,	[r4]
       
   195 	
       
   196 	;Set Address Reg2 (upper range)
       
   197 	;MUL		r7, r0, r6
       
   198 	LSR		r7, r7, #0x10;
       
   199 	LDR		r4, =KNandPgeAdr2Reg 
       
   200 	STRH	r7,	[r4]
       
   201 
       
   202 	; Issue Read Command
       
   203 	LDR		r5, =KNandPageReadBM 	; CMD_READ | XROMC_BUSY_BIT_MASK
       
   204 	LDR		r4, =KNandCmdSetReg	; XROMC
       
   205 	STRH	r5, [r4]
       
   206 
       
   207 	; Poll Busy Bit
       
   208 1  	
       
   209 	LDRH	r5, [r4]				; Get contents of Command setup register
       
   210 	TST		r5, #KNandBusyBit
       
   211 	BNE		%B1	
       
   212 	
       
   213 	; Poll status DRC(Data Read Complete)
       
   214 2
       
   215 	LDR		r4, =KNandDataAreaECCReg  	
       
   216 	LDRH	r5, [r4]				; Get contents of ECC register
       
   217 	TST		r5, #KNandECCDRC
       
   218 	BNE		%B2
       
   219 	
       
   220 	;Copy page (2048) into address [r1]
       
   221 	LDR		r4, =KNandDataWndw
       
   222 	MOV		r6, #KNandPageSize ; 2048
       
   223 read
       
   224 	LDRH	r5, [r4]
       
   225 	STRH	r5, [r1], #2	; save at target
       
   226 	ADD		r4, r4, #2		; move data wndw pointer
       
   227 	SUBS	r6, r6, #2		; end of page?
       
   228 	BNE		read			; no => copy some more ;)
       
   229 	
       
   230 	ldmfd	r13!, {r4-r7,pc}				; yes, return
       
   231 
       
   232 ;-----------------------------------------------------------------------------------
       
   233 ; readpages16
       
   234 ;
       
   235 ; read <r2> pages of NAND,
       
   236 ; starting at page <r0>
       
   237 ; placing data starting at <r1>
       
   238 ;
       
   239 ;-----------------------------------------------------------------------------------
       
   240 readpages16	ROUT
       
   241 	stmfd	r13!, {r4-r6,lr}
       
   242 	mov		r4, r0
       
   243 	mov		r5, r1
       
   244 	mov		r6, r2
       
   245 loop16
       
   246 	bl		readpage16
       
   247 	subs	r6, r6, #1
       
   248 	ldmeqfd	r13!, {r4-r6,pc}
       
   249 	add		r0, r0, #1
       
   250 	b		loop16
       
   251 
       
   252 ;-----------------------------------------------------------------------------------
       
   253 ;
       
   254 ; readhdr16
       
   255 ;
       
   256 ; Read the NAND header from flash into ram so it may be examined for a Symbian
       
   257 ; signature.
       
   258 ;
       
   259 ;-----------------------------------------------------------------------------------
       
   260 readhdr16
       
   261 	; read the header of a 16b device
       
   262 	;Print page
       
   263 	
       
   264 	ldr		r0, =0x0		; header pag
       
   265 	ldr		r1, =KCoreLoaderAddress			;
       
   266 	bl		readpage16
       
   267 	
       
   268 	b		parse_header
       
   269 
       
   270 ;---------------------------------------------------------------------------
       
   271 ;
       
   272 ; At this point the header buffer contains the first NAND page
       
   273 ; Determine whether the NAND device has been formatted according to the
       
   274 ; new style Symbian FBR layout
       
   275 ;
       
   276 ;---------------------------------------------------------------------------
       
   277 
       
   278 parse_header
       
   279 	bl		find_symbian_coreldr
       
   280 	cmp		r0, #0
       
   281 	beq		load_symbian_coreldr
       
   282 
       
   283 	; Use a label rather than a SUB/PC as it makes a symbol for a debugger.
       
   284 SymbianCoreldrNotFound
       
   285 
       
   286 	b		SymbianCoreldrNotFound			; spin forever
       
   287 
       
   288 	; NOTREACHED
       
   289 
       
   290 ;---------------------------------------------------------------------------------
       
   291 ;
       
   292 ; find_symbian_coreldr
       
   293 ;
       
   294 ; searches for the Symbian1 signature in the FBR then assumes
       
   295 ; that the coreldr will be stored in the 30 pages (15k) starting
       
   296 ; at page 4.
       
   297 ;
       
   298 ;---------------------------------------------------------------------------------
       
   299 
       
   300 Symbian_Signature		DCB		"1naibmyS"
       
   301 Symbian_Signature_size  EQU		8
       
   302 
       
   303 
       
   304 find_symbian_coreldr	ROUT
       
   305 		stmfd	r13!, {r4,lr}
       
   306 		ldr		r0, =KCoreLoaderAddress
       
   307 		add		r0, r0, #4						; signature at byte 4 in page 0
       
   308 		ADR		r1, Symbian_Signature 
       
   309 		ldr		r3, =Symbian_Signature_size
       
   310 		bl		strcmp
       
   311 		ldmfd	r13!, {r4,pc}
       
   312 
       
   313 ;---------------------------------------------------------------------------------
       
   314 ;
       
   315 ; load_symbian_coreldr
       
   316 ;
       
   317 ; Assumses Coreloader starts at page 1 and can be as big as 64 pages (128KB)
       
   318 ;
       
   319 ;---------------------------------------------------------------------------------
       
   320 load_symbian_coreldr	ROUT
       
   321 
       
   322 		mov		r0, #KSymbianCoreldrPage
       
   323 		ldr		r1, =KCoreLoaderAddress
       
   324 		mov		r2, #KSymbianCoreldrSizePages
       
   325 		bl		readpages16
       
   326 
       
   327 		; restart CPUs, by calling restart vertor.
       
   328 		mov		r0, #KtRestartReasonCoreLdr 
       
   329 		add		pc, r12,  #TRomHeader_iRestartVector
       
   330 
       
   331 		; NOTREACHED
       
   332 	END