细节参见朱老师课程,
代码参见https://github.com/jimingkang/news5pv210里面uboot_2013.10(官方)和aston_uboot_2013.10(朱老师移植的)
-------------------------------------------------------------------------------------------------------------------------------
1 生成补丁;diff -urN u-boot-2013.10 u-boot-2013.10_aston >2013_uboot_aston.txt
2.分析变动,发现主要修改的文件如下:
#第一阶段(BL1)和重定位
arch/arm/cpu/armv7/start.S
arch/arm/lib/crt0.S
/arch/arm/lib/board.c
board/samsung/goni/lowlevel_init.S
arch/arm/cpu/u-boot.lds
board/samsung/goni/Makefile
include/movi.h
include/s5pc110.h
include/configs/s5p_goni.h
arch/arm/cpu/armv7/s5p-common/cpu_info.c .
arch/arm/include/asm/arch-s5pc1xx/cpu.h
#时钟 以后做这个移植
arch/arm/cpu/armv7/s5pc1xx/clock.c
# sd/mmc driver mmc驱动 ,下篇做这个移植
/root/winshare/s5pv210/uboot/u-boot-2013.10/drivers/mmc/mmc.c
/root/winshare/s5pv210/uboot/u-boot-2013.10/drivers/mmc/s3c_hsmmc.c
/root/winshare/s5pv210/uboot/u-boot-2013.10/include/mmc.h
/root/winshare/s5pv210/uboot/u-boot-2013.10/include/s3c_hsmmc.h
/root/winshare/s5pv210/uboot/u-boot-2013.10/common/cmd_mmc.c
/root/winshare/s5pv210/uboot/u-boot-2013.10/drivers/mmc/Makefile
#network 网络
/root/winshare/s5pv210/uboot/u-boot-2013.10/net/eth.c
具体修改如下:
1)start.S
+ // 添加16字节占位,否则和sd_fusing中mkbl1不适配,就会出现校验和失败
+ .word 0x2000
+ .word 0x0
+ .word 0x0
+ .word 0x0
+
+.globl _bss_start
+_bss_start:
+ .word __bss_start
+
+.globl _bss_end
+_bss_end:
+ .word _end
+
+ // 在cpu_init_crit函数中最后初始化完了DDR,然后在下面跳转到了第二阶段,所以
+ // 重定位代码就在这里进行
+
+ // 第一步: 加一个调试信息串口输出字符来做调试定位
+ // 打印字符'A'
+ ldr r1, =0x41414141
+ ldr r2, =0xE2900820
+ str r1, [r2] @'A'
+
+ // 正式开始重定位
+
+ /* get ready to call C functions */
+ ldr sp, _TEXT_BASE /* setup temp stack pointer */
+ sub sp, sp, #12
+ mov fp, #0 /* no previous frame, so fp=0 */
+
+ 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 */
+
+/* If BL1 was copied from SD/MMC CH2 */
+ ldr r0, =0xD0037488
+ ldr r1, [r0]
+ ldr r2, =0xEB200000
+ cmp r1, r2
+ beq mmcsd_boot
+
+mmcsd_boot:
+ bl movi_bl2_copy
+ b after_copy
+
+after_copy:
+ // 这里有一些设置sp的代码,暂时不要,到时候不对了再说
+
+clear_bss:
+ ldr r0, _bss_start /* find start of bss segment */
+ ldr r1, _bss_end /* stop here */
+ mov r2, #0x00000000 /* clear */
+
+clbss_l:
+ str r2, [r0] /* clear loop... */
+ add r0, r0, #4
+ cmp r0, r1
+ ble clbss_l
+ // 第一阶段和第二阶段的分界点
+ ldr pc, __main
+__main: .word _main
2)链接文件
diff -urN u-boot-2013.10/arch/arm/cpu/u-boot.lds u-boot-2013.10_aston/arch/arm/cpu/u-boot.lds
@@ -19,6 +19,9 @@
{
*(.__image_copy_start)
CPUDIR/start.o (.text*)
+ board/samsung/goni/lowlevel_init.o (.text*)
+ board/samsung/goni/cpu_init.o (.text*)
+ board/samsung/goni/movi.o (.text*)
*(.text*)
}
3)cpu.h
diff -urN u-boot-2013.10/arch/arm/include/asm/arch-s5pc1xx/cpu.h u-boot-2013.10_aston/arch/arm/include/asm/arch-s5pc1xx/cpu.h
4)board.c
diff -urN u-boot-2013.10/arch/arm/lib/board.c u-boot-2013.10_aston/arch/arm/lib/board.c
注释//enable_caches();
5) crt0.S
diff -urN u-boot-2013.10/arch/arm/lib/crt0.S u-boot-2013.10_aston/arch/arm/lib/crt0.S
6)cpu_init.S
diff -urN u-boot-2013.10/board/samsung/goni/cpu_init.S u-boot-2013.10_aston/board/samsung/goni/cpu_init.S
增加函数mem_ctrl_asm_init,准备给start.S调用
7)goni.c
diff -urN u-boot-2013.10/board/samsung/goni/goni.c u-boot-2013.10_aston/board/samsung/goni/goni.c
添加:#include
添加函数 dm9000_pre_init
修改:int board_init(void)
{
/* Set Initial global variables */
s5pc110_gpio = (struct s5pc110_gpio *)S5PC110_GPIO_BASE;
- gd->bd->bi_arch_number = MACH_TYPE_GONI;
+ gd->bd->bi_arch_number = MACH_TYPE_SMDKV210; // 在这里更改
gd->bd->bi_boot_params = PHYS_SDRAM_1 + 0x100;
添加网卡初始化
+#ifdef CONFIG_DRIVER_DM9000
+ dm9000_pre_init();
+#endif
int power_init_board(void)
{
+#if 0
int ret;
/*
@@ -39,14 +75,13 @@
ret = pmic_init(I2C_0);
if (ret)
return ret;
-
+#endif
return 0;
}
添加内存条初始化
int dram_init(void)
{
- gd->ram_size = PHYS_SDRAM_1_SIZE + PHYS_SDRAM_2_SIZE +
- PHYS_SDRAM_3_SIZE;
+ gd->ram_size = PHYS_SDRAM_1_SIZE + PHYS_SDRAM_2_SIZE;
return 0;
}
@@ -57,14 +92,14 @@
gd->bd->bi_dram[0].size = PHYS_SDRAM_1_SIZE;
gd->bd->bi_dram[1].start = PHYS_SDRAM_2;
gd->bd->bi_dram[1].size = PHYS_SDRAM_2_SIZE;
- gd->bd->bi_dram[2].start = PHYS_SDRAM_3;
- gd->bd->bi_dram[2].size = PHYS_SDRAM_3_SIZE;
+
}
#ifdef CONFIG_DISPLAY_BOARDINFO
int checkboard(void)
{
- puts("Board:\tGoni\n");
+ //puts("Board:\tGoni\n");
+ puts("Board:\tAston210\n");
return 0;
}
#endif
添加mmc也即是sd卡初始化
#ifdef CONFIG_GENERIC_MMC
int board_mmc_init(bd_t *bis)
{
+#ifdef CONFIG_S3C_HSMMC
+ setup_hsmmc_clock();
+ setup_hsmmc_cfg_gpio();
+ return smdk_s3c_hsmmc_init();
+#else
+ return 0;
+#endif
+
+
+
+#if 0
int i, ret, ret_sd = 0;
/* MASSMEMORY_EN: XMSMDATA7: GPJ2[7] output high */
- s5p_gpio_direction_output(&s5pc110_gpio->j2, 7, 1);
+ s5p_gpio_direction_output(&s5pc110_gpio->j2, 7, 1); // GPJ2_7
/*
* MMC0 GPIO
@@ -88,7 +134,7 @@
if (i == 2)
continue;
/* GPG0[0:6] special function 2 */
- s5p_gpio_cfg_pin(&s5pc110_gpio->g0, i, 0x2);
+ s5p_gpio_cfg_pin(&s5pc110_gpio->g0, i, 0x2); // GPG0_i 0x2
/* GPG0[0:6] pull disable */
s5p_gpio_set_pull(&s5pc110_gpio->g0, i, GPIO_PULL_NONE);
/* GPG0[0:6] drv 4x */
@@ -99,6 +145,23 @@
if (ret)
error("MMC: Failed to init MMC:0.\n");
+ for (i = 0; i < 7; i++) {
+ if (i == 2)
+ continue;
+
+ /* GPG2[0:6] special function 2 */
+ s5p_gpio_cfg_pin(&s5pc110_gpio->g2, i, 0x2);
+ /* GPG2[0:6] pull disable */
+ s5p_gpio_set_pull(&s5pc110_gpio->g2, i, GPIO_PULL_NONE);
+ /* GPG2[0:6] drv 4x */
+ s5p_gpio_set_drv(&s5pc110_gpio->g2, i, GPIO_DRV_4X);
+ }
+
+ ret_sd = s5p_mmc_init(2, 4);
+ if (ret_sd)
+ error("MMC: Failed to init SD card (MMC:2).\n");
+
+#if 0
/*
* SD card (T_FLASH) detect and init
* T_FLASH_DETECT: EINT28: GPH3[4] input mode
@@ -123,8 +186,10 @@
if (ret_sd)
error("MMC: Failed to init SD card (MMC:2).\n");
}
+#endif
return ret & ret_sd;
+#endif
}
#endif
8)level_init.S
diff -urN u-boot-2013.10/board/samsung/goni/lowlevel_init.S u-boot-2013.10_aston/board/samsung/goni/lowlevel_init.S
+#include
// 我们添加的开发板供电制锁的代码
+ ldr r0, =0xE010E81C
+ ldr r1, =0x301
+ str r1, [r0]
+
/* setting SRAM */
ldreq r0, =S5PC100_SROMC_BASE
ldrne r0, =S5PC110_SROMC_BASE
@@ -195,10 +201,25 @@
str r5, [r1, #0xf00] @ INTADDRESS
str r5, [r2, #0xf00] @ INTADDRESS
+ // for clock init
+ bl system_clock_init
+
/* for UART */
bl uart_asm_init
//sram初始化,可以不要,因为三星其他地方帮我们已经初始化了
- bl internal_ram_init
+ // DDR init
+ bl mem_ctrl_asm_init //
+
+ // 打印字符'K'
+
+ ldr r1, =0x4b4b4b4b
+ ldr r2, =0xE2900820
+ str r1, [r2] @'K'
+
+ mov lr, r11
+ mov pc, lr
+
+ //bl internal_ram_init
cmp r7, r8
/* Clear wakeup status register */
@@ -245,145 +266,201 @@
* void system_clock_init(void)
*/
system_clock_init:
- ldr r0, =S5PC110_CLOCK_BASE @ 0xE0100000
//时钟初始化设置
+#if 1
+ ldr r0, =ELFIN_CLOCK_POWER_BASE @0xe0100000
+
+ /* Set Mux to FIN */
+ ldr r1, =0x0
+ str r1, [r0, #CLK_SRC0_OFFSET]
+
+ ldr r1, =APLL_LOCKTIME_VAL
+ str r1, [r0, #APLL_LOCK_OFFSET]
+
+ /* Disable PLL */
+retryloop:
+ ldr r1, =0x0
+ str r1, [r0, #APLL_CON0_OFFSET]
+ ldr r1, =0x0
+ str r1, [r0, #MPLL_CON_OFFSET]
+
+ ldr r1, =0x0
+ str r1, [r0, #MPLL_CON_OFFSET]
+
+ ldr r1, [r0, #CLK_DIV0_OFFSET]
+ ldr r2, =CLK_DIV0_MASK
+ bic r1, r1, r2
+
+ ldr r2, =CLK_DIV0_VAL
+ orr r1, r1, r2
+ str r1, [r0, #CLK_DIV0_OFFSET]
+
+ ldr r1, =APLL_VAL
+ str r1, [r0, #APLL_CON0_OFFSET]
+
+ ldr r1, =MPLL_VAL
+ str r1, [r0, #MPLL_CON_OFFSET]
+
+ ldr r1, =VPLL_VAL
+ str r1, [r0, #VPLL_CON_OFFSET]
+#if defined(CONFIG_EVT1)
+ ldr r1, =AFC_ON
+ str r1, [r0, #APLL_CON1_OFFSET]
+#endif
+ mov r1, #0x10000
+1: subs r1, r1, #1
+ bne 1b
+
+
+ /* MPLL software workaround */
+ ldr r1, [r0, #MPLL_CON_OFFSET]
+ orr r1, r1, #(1<<28)
+ str r1, [r0, #MPLL_CON_OFFSET]
+
+ mov r1, #0x100
+1: subs r1, r1, #1
+ bne 1b
+
+ ldr r1, [r0, #MPLL_CON_OFFSET]
+ and r1, r1, #(1<<29)
+ cmp r1, #(1<<29)
+ bne retryloop
+
+ /* H/W lock detect disable */
+ ldr r1, [r0, #MPLL_CON_OFFSET]
+ bic r1, r1, #(1<<28)
+ str r1, [r0, #MPLL_CON_OFFSET]
+
+
+ ldr r1, [r0, #CLK_SRC0_OFFSET]
+ ldr r2, =0x10001111
+ orr r1, r1, r2
+ str r1, [r0, #CLK_SRC0_OFFSET]
+
+ /* CLK_DIV6 */
+ ldr r1, [r0, #CLK_DIV6_OFFSET]
+ bic r1, r1, #(0x7<<12) @; ONENAND_RATIO: 0
+ str r1, [r0, #CLK_DIV6_OFFSET]
+
+ mov pc, lr
+#endif
internal_ram_init:
ldreq r0, =0xE3800000
@@ -446,4 +523,9 @@
orr r1, r1, #(1 << 7) @ 7 = 7 * 1-bit
str r1, [r0, #0x4] @ S5PC1XX_GPIO_DAT_OFFSET
200:
+ // 串口2输出字符'O'
+ ldr r1, =0x4f4f4f4f
+ ldr r2, =0xE2900820
+ str r1, [r2] @'O'
+
mov pc, lr
9)Makefile
diff -urN u-boot-2013.10/board/samsung/goni/Makefile u-boot-2013.10_aston/board/samsung/goni/Makefile
+COBJS-y := goni.o setup_hsmmc.o
+#SOBJS := lowlevel_init.o
+LOW := lowlevel_init.o cpu_init.o movi.o
SRCS := $(SOBJS:.o=.S) $(COBJS-y:.o=.c)
OBJS := $(addprefix $(obj),$(COBJS-y))
SOBJS := $(addprefix $(obj),$(SOBJS))
+
+all: $(obj).depend $(LOW) $(LIB)
+
$(LIB): $(obj).depend $(SOBJS) $(OBJS)
$(call cmd_link_o_target, $(SOBJS) $(OBJS))
10)movi.c
diff -urN u-boot-2013.10/board/samsung/goni/movi.c u-boot-2013.10_aston/board/samsung/goni/movi.c
添加函数:movi_bl2_copy ,在start.S里用到
@@ -0,0 +1,44 @@
+#include
+#include
+
+#include
+#include
+//#include
+#include
+
+typedef u32(*copy_sd_mmc_to_mem)
+(u32 channel, u32 start_block, u16 block_size, u32 *trg, u32 init);
+
+void movi_bl2_copy(void)
+{
+ ulong ch;
+
+ ch = *(volatile u32 *)(0xD0037488);
+ copy_sd_mmc_to_mem copy_bl2 =
+ (copy_sd_mmc_to_mem) (*(u32 *) (0xD0037F98));
+
+ u32 ret;
+ if (ch == 0xEB000000) {
+ ret = copy_bl2(0, MOVI_BL2_POS, MOVI_BL2_BLKCNT,
+ CFG_PHY_UBOOT_BASE, 0);
+ }
+ else if (ch == 0xEB200000) {
+ ret = copy_bl2(2, MOVI_BL2_POS, MOVI_BL2_BLKCNT,
+ CFG_PHY_UBOOT_BASE, 0);
+ }
+ else
+ return;
+
+ if (ret == 0)
+ while (1)
+ ;
+ else
+ return;
+}
+
3. 编译:
make s5p_goni_config
make CROSS_COMPILE=arm-none-linux-gnueabi-
4.编译后,输出:
--------------------------------------------------------------
SD checksum Error
KA
U-Boot 2013.10 (May 23 2020 - 13:53:39) for ASTON210
CPU: S5PC110@400MHz
Board: Goni
I2C: ready
DRAM: 464 MiB
Board PMIC init
MMC: SAMSUNG SDHCI: 0
Error detected in status(0x208020)!
Error detected in status(0x208020)!
Using default environment
In: serial
Out: serial
Err: serial
Net: Net Initialization Skipped
No ethernet found.
Hit any key to stop autoboot: 0
Unknown command 'onenand' - try 'help'
Wrong Image Format for bootm command
ERROR: can't get kernel image!