当前位置:网站首页>Start of u-boot S analysis (III)

Start of u-boot S analysis (III)

2022-06-12 23:44:00 Cheap sword

Reset stack

/* get ready to call C functions */
ldr	sp, _TEXT_PHY_BASE	/* setup temp stack pointer */
sub	sp, sp, #12
mov	fp, #0			/* no previous frame, so fp=0 */
  • stay u-boot And start.S analysis ( One ) We have set the stack address in the last part of the , however Only less than 8K Size , This is obviously not enough . Because we did not initialize at that time DDR, Therefore, the stack can only be set to the interior that does not need initialization IRAM in . Now we have DDR Initialization is done , So you need to move the stack back to DDR in , This avoids the risk of stack overflow
  • _TEXT_PHY_BASE Refer to uboot The base address of the code segment's physical address , Finally, I found its source ( as follows )
  1. start.S The beginning of the is CFG_PHY_UBOOT_BASE The macro definition of , But because we defined CONFIG_ENABLE_MMU, So this is about CFG_PHY_UBOOT_BASE Statements defined by macros do not work .
#ifndef CONFIG_ENABLE_MMU
#ifndef CFG_PHY_UBOOT_BASE
#define CFG_PHY_UBOOT_BASE CFG_UBOOT_BASE
#endif
#endif
  1. Finally, the definition is found in the header file , So the final value is 0x33e00000, In our DRAM0 Inside
#define MEMORY_BASE_ADDRESS 0x30000000
#define CFG_PHY_UBOOT_BASE MEMORY_BASE_ADDRESS + 0x3e00000

 Insert picture description here

  • Here, the address of the stack is located at 0x33e00000, because MMU The relationship between , The address is TEXT_BASE Defined snippet address 0xc3e00000(u-boot Memory address mapping ). because ARM yes Full reduction stack , So the stack goes down from the high address , So there is no impact on the code snippet .

Determine if relocation is required

/* when we already run in ram, we don't need to relocate U-Boot. * and actually, memory controller must be configured before U-Boot * is running in ram. */
ldr	r0, =0xff000fff
bic	r1, pc, r0		/* r0 <- current base addr of code */
ldr	r2, _TEXT_BASE		/* r1 <- original base addr in ram */
bic	r2, r2, r0		/* r0 <- current base addr of code */
cmp     r1, r2                  /* compare r0, r1 */
beq     after_copy		/* r0 == r1 then skip flash copy */
  • Determine whether the running address is in SRAM still DDR in , To carry on uboot The repositioning of .
  • Cold start uboot The previous part of the boot automatically starts from SD The card is loaded into SRAM Run in ,uboot Part two ( It's actually the whole uboot) Still in SD In the card .
  • All you have to do here is load the second part into DDR At the link address of (0x33e00000).

SD Card device judgment

#if defined(CONFIG_EVT1)
	/* If BL1 was copied from SD/MMC CH2 */
	ldr	r0, =0xD0037488
	ldr	r1, [r0]
	ldr	r2, =0xEB200000
	cmp	r1, r2
	beq     mmcsd_boot
#endif
  • 0xD0037488 Address from 《S5PV210_iROM_ApplicationNote_Preliminary_20091126.pdf》 file , The value in this address indicates from which SD Card address enabled .

 Insert picture description here

  • SDMMC0,1,2 The starting addresses of the devices are 0xEB00_0000,0xEB10_0000,0xEB20_0000
  • therefore cmp r1, r2 Is to detect whether from the outside SD Card activation
  • The code eventually enters mmcsd_boot Perform relocation

relocation

void movi_bl2_copy(void)
{
    
	ulong ch;
#if defined(CONFIG_EVT1)
	ch = *(volatile u32 *)(0xD0037488);
	copy_sd_mmc_to_mem copy_bl2 =
	    (copy_sd_mmc_to_mem) (*(u32 *) (0xD0037F98));

	#if defined(CONFIG_SECURE_BOOT)
	ulong rv;
	#endif
#else
	ch = *(volatile u32 *)(0xD003A508);
	copy_sd_mmc_to_mem copy_bl2 =
	    (copy_sd_mmc_to_mem) (*(u32 *) (0xD003E008));
#endif
	u32 ret;
	if (ch == 0xEB000000) {
    
		ret = copy_bl2(0, MOVI_BL2_POS, MOVI_BL2_BLKCNT,
			CFG_PHY_UBOOT_BASE, 0);

#if defined(CONFIG_SECURE_BOOT)
		/* do security check */
		rv = Check_Signature( (SecureBoot_CTX *)SECURE_BOOT_CONTEXT_ADDR,
				      (unsigned char *)CFG_PHY_UBOOT_BASE, (1024*512-128),
			              (unsigned char *)(CFG_PHY_UBOOT_BASE+(1024*512-128)), 128 );
		if (rv != 0){
    
				while(1);
			}
#endif
	}
	else if (ch == 0xEB200000) {
    
		ret = copy_bl2(2, MOVI_BL2_POS, MOVI_BL2_BLKCNT,
			CFG_PHY_UBOOT_BASE, 0);
		
#if defined(CONFIG_SECURE_BOOT)
		/* do security check */
		rv = Check_Signature( (SecureBoot_CTX *)SECURE_BOOT_CONTEXT_ADDR,
				      (unsigned char *)CFG_PHY_UBOOT_BASE, (1024*512-128),
			              (unsigned char *)(CFG_PHY_UBOOT_BASE+(1024*512-128)), 128 );
		if (rv != 0) {
    
			while(1);
		}
#endif
	}
	else
		return;

	if (ret == 0)
		while (1)
			;
	else
		return;
}
  • The code ends up executing a long jump statement bl movi_bl2_copy perform C Language program , After searching , This function is located in cpu/s5pc11x/movi.c In file

Memory management unit (MMU)

/* enable domain access */
	ldr	r5, =0x0000ffff
	mcr	p15, 0, r5, c3, c0, 0		@load domain access register

	/* Set the TTB register */
	ldr	r0, _mmu_table_base
	ldr	r1, =CFG_PHY_UBOOT_BASE
	ldr	r2, =0xfff00000
	bic	r0, r0, r2
	orr	r1, r0, r1
	mcr	p15, 0, r1, c2, c0, 0
	/* enable domain access */
	ldr	r5, =0x0000ffff
	mcr	p15, 0, r5, c3, c0, 0		@load domain access register

	/* Set the TTB register */
	ldr	r0, _mmu_table_base
	ldr	r1, =CFG_PHY_UBOOT_BASE
	ldr	r2, =0xfff00000
	bic	r0, r0, r2
	orr	r1, r0, r1
	mcr	p15, 0, r1, c2, c0, 0

	/* Enable the MMU */
mmu_on:
	mrc	p15, 0, r0, c1, c0, 0
	orr	r0, r0, #1
	mcr	p15, 0, r0, c1, c0, 0
  • MMU Unit in CP15 Control in coprocessor , So we have to do something about cp15 Coprocessor registers are programmed
  • To set the base address of the address translation table (translation table base,TTB) And enable MMU
  • _mmu_table_base Is to convert the base address of the table , This last indication is mmu_table, This is in lowlevel_init.S in
  • The memory address is mapped to u-boot Memory address mapping Detailed analysis
原网站

版权声明
本文为[Cheap sword]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202280605175817.html