一、准备原料
三星原厂提供的UBOOT代码-u-boot-samsung-dev.
二、在4212平台代码基础上修改成自己的平台LHS4412
1.用户目录下新建文件夹lhs4412-uboot cd, mkdir lhs4412-uboot
2.进入lhs4412-uboot文件夹,将三星平台代码压缩文件拷贝至此。解压, 重命名为:lhs4412-uboot tar -vxf u-boot-samsung-dev.tar.gz mv u-boot-samsung-dev lhs4412-uboot
3.拷贝迅为的CodeSign4SecureBoot文件夹到当前目录。至此当前目录结构为:
4.进入文件夹lhs4412-uboot cd lhs4412-uboot 进入三星平台cd board/samsung
cp -rf smdk4212 lhs4412 cd lhs4412
Mv clock_init_smdk4212.S clock_init_lhs4412.S
Mv mem_init_smdk4212.S mem_init_lhs4412.S
Mv smdk4212.c lhs4412.c
Mv smdk4212_val.h lhs4212_val.h
Mv smdk4412_val.h lhs4412_val.h
Vi lowlevel_init.S
#ifdef CONFIG_EXYNOS4412
#include "smdk4412_val.h" //改为#include "lhs4412_val.h"
#else
#include "smdk4212_val.h" //改为#include "lhs4212_val.h"
#endif
Vi clock_init_lhs4412.S
#ifdef CONFIG_EXYNOS4412
#include "smdk4412_val.h" //改为#include "lhs4412_val.h"
#else
#include "smdk4212_val.h" //改为#include "lhs4212_val.h"
#endif
Vi Makefile
33行:COBJS-y := smdk4212.o //改为:COBJS-y := lhs4412.o
37行;SOBJS += mem_init_smdk4212.o //改为:SOBJS += mem_init_lhs4412.o
38 ;SOBJS += clock_init_smdk4212.o //改为:SOBJS += clock_init_lhs4412.o
Cd , cd lhs4412-uboot/lhs4412-uboot
修改boards.cfg 添加lhs4412 arm armv7 lhs4412 samsung exynos
Cp -av include/configs/smdk4412.h include/configs/lhs4412.h
Vi include/configs/lhs4412.h
265: #define CONFIG_SYS_PROMPT "SMDK4412 # "
改为:#define CONFIG_SYS_PROMPT "LHS4412 # "
319:#define CONFIG_IDENT_STRING " for SMDK4412"
改为;#define CONFIG_IDENT_STRING " for LHS4412"
Vi u-boot.lds
board/samsung/smdk4212/libsmdk4212.o (.text)
修改为 :
board/samsung/lhs4412/liblhs4412.o (.text)
5.编译 make lhs4412_config make
6.制作UBOOT
因CPU exynos_4412的启动过程是
BL0 //BL0固化在iram中的程序 (关闭看门狗,关闭中断及MMU,时钟设置,检测om决定启动方式,拷贝bl1到iram中
BL1 <8k /*BL1 初始化化环境(中断初始化,设置堆栈等),搬移bl2代码到RAM中,并允许它,
BL1是三星提供的,无源码,见CodeSign4SecureBoot/E4412_N.bl1.SCP2G.bin
| 如果想看源码,可以反汇编分析,如arm-none-linux-gnueabi-objdump -D -b binary -m arm E4412_N.bl1.SCP2G.bin > b1.asm
BL2 <14k //bl2 完成基本硬件初始化(Low_init.s 时钟串口内存flash等)
u-boot.bin
所以我们单独运行u-boot是不行的,需使用三星提供的BL1 BL2进行打包加密校验
cp -rf sdfuse_q ./ //sdfuse_q 三星提供的加密处理(checksum)
Cp mkuboot ./ //拷贝SD卡制作UBOOT脚 本。
//cp -rf CodeSign4SecureBoot ../ // CodeSign4SecureBoot 三星提供的安全启动方式 前面已拷贝
vim Makefile
修改,添加sdfuse_q的编译 (sdfuse_q主要是进行checksum ,大小等检验,还有通过脚本可制作sd启动盘)
在354 ifeq ($(CONFIG_CPU_EXYNOS5250),y)
./mkbl2 u-boot.bin bl2.bin 14336
Endif后添加
@split -b 14336 u-boot.bin bl2
@+make -C sdfuse_q/
@./sdfuse_q/chksum
@./sdfuse_q/add_padding
@rm bl2a*
@echo
Cp build_uboot.sh ./ 拷贝编译脚本
Vi build_uboot.sh
修改路径:sec_path="../CodeSign4SecureBoot/"
if [ -z $1 ]
then
make tc4_android_config //改make lhs4412_config
elif [ $1 = $option1 ]
then
make tc4_plus_android_config //改make lhs4412_config
else
echo please input right parameter. //改make lhs4412_config
exit 0
Fi
cat E4412_N.bl1.SCP2G.bin bl2.bin all00_padding.bin u-boot.bin tzsw_SMDK4412_SCP_2GB.bin > u-boot-iTOP-4412.bin改 为>u-boot-lhs-4412.bin
mv u-boot-iTOP-4412.bin $ROOT_DIR
改为mv u-boot-lhs-4412.bin $ROOT_DIR
chmod 777 ./build.sh
./build_uboot.sh 编译 生成u-boot-lhs-4412.bin
7.加入点灯代码,确认uboot运行。
Vi board/samsung/lhs4412/lowlevel_init.S
96: /* PS-Hold high */ 电源管理
ldr r0, =0x1002330c
ldr r1, [r0]
orr r1, r1, #0x300
str r1, [r0] 后添加
ldr r0, =0x11000c08
ldr r1, =0x0
str r1, [r0]
/* Clear MASK_WDT_RESET_REQUEST */
ldr r0, =0x1002040c
ldr r1, =0x00
str r1, [r0]
//led test
ldr r0, =0x11000060 //GPK1[1]
ldr r1, [r0]
bic r1, r1, #0xf0
orr r1, r1, #0x10
str r1, [r0]
ldr r1, [r0, #4]
orr r1, r1, #2
str r1, [r0, #4]
保存重新编译,烧到开发板,运行,可 以看灯一闪而过。但是串口无任何输出。
8.开启串口
开发板串口为UART2.
Vi include/configs/lhs4412.h
添加#define DEBUG 输出调试信息
161: #define CONFIG_SERIAL1 1
改为:#define CONFIG_SERIAL2 1
保存编译,烧到开发板,可以看到串口输出信息,进入UBOOT读秒,读取内核,但是EMMC读取速度超慢,无法忍受,但最终读取完成。
9.修改MMC驱动。加快内核的读取速度。
Vi drivers\mmc\mmc.c
1271; 在函数mmc_init中
mmc_set_clock(mmc, 1);
mmc_set_bus_width(mmc, MMC_BUS_WIDTH_1);
修改为:
mmc_set_clock(mmc, 40000000); //40M
mmc_set_bus_width(mmc, MMC_MODE_4BIT);
保存编译,烧到开发板,可以看到串口输出信息,进入UBOOT读秒,读取内核EMMC读取速度超快,读取完成。但是无法加载内核。打印信息如下 :
### main_loop: bootcmd="movi read kernel 0 40008000;movi read rootfs 0 41000000 100000;bootm 40008000 41000000"
Hit any key to stop autoboot: 0
reading kernel..device 0 Start 1063, Count 8192
MMC read: dev # 0, block # 1063, count 8192 ... 8192 blocks read: OK
completed
reading RFS..device 0 Count 9255, Start 2048
MMC read: dev # 0, block # 9255, count 2048 ... 2048 blocks read: OK
completed
## Current stack ends at 0xc3cfbdc8 * kernel: cmdline image address = 0x40008000
Wrong Image Format for bootm command
ERROR: can't get kernel image!
10.修改EMMC分区信息。
Vi arch\arm\include\asm\arch-exynos\Movi_partition.h
修改21-57行为:
#define PART_SIZE_FWBL1 (8 * 1024)
#define PART_SIZE_BL1 (16 * 1024)
#define PART_SIZE_UBOOT (495 * 1024)
#define PART_SIZE_KERNEL (6 * 1024 * 1024)
#define PART_SIZE_ROOTFS (2 * 1024 * 1024)// 2M
////#define PART_SIZE_TZSW (156 * 1024)
#define PART_SIZE_TZSW (24 * 1024) //为了与迅为UBOOT中的 environment start 544一致。
#define MOVI_FWBL1_BLKCNT (PART_SIZE_FWBL1 / MOVI_BLKSIZE)
#define MOVI_BL1_BLKCNT (PART_SIZE_BL1 / MOVI_BLKSIZE)
#define MOVI_ENV_BLKCNT (CONFIG_ENV_SIZE / MOVI_BLKSIZE) /* 16KB */
#define MOVI_UBOOT_BLKCNT (PART_SIZE_UBOOT / MOVI_BLKSIZE) /* 328KB */
#define MOVI_ZIMAGE_BLKCNT (PART_SIZE_KERNEL / MOVI_BLKSIZE) /* 4MB */
#define MOVI_ROOTFS_BLKCNT (PART_SIZE_ROOTFS / MOVI_BLKSIZE) /* 26MB */
#define MOVI_TZSW_BLKCNT (PART_SIZE_TZSW / MOVI_BLKSIZE) /* 160KB */
#define MOVI_UBOOT_POS ((eFUSE_SIZE / MOVI_BLKSIZE) + MOVI_FWBL1_BLKCNT + MOVI_BL1_BLKCNT)
#define MOVI_TZSW_POS ((eFUSE_SIZE / MOVI_BLKSIZE) + MOVI_FWBL1_BLKCNT \
+ MOVI_BL1_BLKCNT + MOVI_UBOOT_BLKCNT)
#define ENV_START_BLOCK MOVI_FWBL1_BLKCNT+MOVI_BL1_BLKCNT+MOVI_UBOOT_BLKCNT+MOVI_TZSW_BLKCNT+1
Vi arch\arm\cpu\armv7\exynos\Movi_partition.c
25: 修改函数init_raw_area_table
Image[2]部分修改为:
image[2].start_blk = location;
image[2].used_blk = MOVI_UBOOT_BLKCNT + MOVI_BL1_BLKCNT + MOVI_FWBL1_BLKCNT;
image[2].size = PART_SIZE_UBOOT + PART_SIZE_FWBL1 + PART_SIZE_BL1;
image[2].attribute = 0x2;
strcpy(image[2].description, "u-boot");
dbg("u-boot: %d\n", image[2].start_blk);
Image[3]部分:
image[3].start_blk = image[2].start_blk + MOVI_UBOOT_BLKCNT;
修改为:image[3].start_blk = image[2].start_blk + MOVI_UBOOT_BLKCNT + MOVI_BL1_BLKCNT + MOVI_FWBL1_BLKCNT;
Image[4]部分
image[4].attribute = 0x10;
strcpy(image[4].description, "environment");
后改为:
if (location == 0)
image[4].start_blk = image[4].start_blk + 2;
else
image[4].start_blk = image[4].start_blk + 1;
为了与迅为UBOOT中的environment start 544一致。
保存编译,烧到开发板,可以看到串口输出信息,进入UBOOT读秒,读取内核EMMC读取速度超快,读取完成。加载内核成功,文件系统也成功加载。但是UBOOT下,fastboot失败!Starting download of 527104 bytes
---------ERROR: DMA Address is not aligned by 8---------
11.使用fastboot功能
Vi include\configs\lhs4412.h
167: #undef CONFIG_USB_CPUMODE
修改为#define CONFIG_USB_CPUMODE
保存编译,烧到开发板.fastboot命令成功
12.环境变量的保存。
到目前为止,环境变量是默认的。迅为开发板环境变量保存在错误的分区了,只要使用saveenv命令,就会破坏EMMC中的文件系统。导致加载文件系统不断重启而失败。最后连fastboot命令都失效。EMMC分区被破坏。重新分区,烧UBOOT, 文件系统。
Vi drivers\mmc\mmc.c
在函数mmc_read_ext_csd中。
959: if (ext_csd_struct > 6) {
printf("unrecognised EXT_CSD structure "
"version %d\n", ext_csd_struct);
err = -1;
goto out;
}
改为
if ((ext_csd_struct > 5) && (7 != ext_csd_struct)) {
printf("unrecognised EXT_CSD structure "
"version %d\n", ext_csd_struct);
err = -1;
goto out;
}
因刚好version =7;
保存编译,烧到开发板.saveenv命令成功 ,现在读取的是EMMC中的环境变量。
13. 疑问:迅为提供的UBOOT E4412_N.bl1.SCP2G.bin 已经将整个UBOOT拷贝到内存中。测试是否如此?
修改lowlevel_init.S
load_uboot函数修改为:
/*****************************************************************************/
.globl load_uboot
load_uboot:
push {lr}
ldr r0, =INF_REG_BASE
ldr r1, [r0, #INF_REG3_OFFSET]
cmp r1, #BOOT_MMCSD
beq mmcsd_boot
cmp r1, #BOOT_EMMC
beq emmc_boot
cmp r1, #BOOT_EMMC_4_4
beq emmc_boot_4_4
cmp r1, #BOOT_SEC_DEV
beq mmcsd_boot
second_mmcsd_boot:
ldr r3, =BOOT_MMCSD
ldr r0, =INF_REG_BASE
str r3, [r0, #INF_REG3_OFFSET]
mmcsd_boot:
#ifdef CONFIG_CLK_1000_400_200
ldr r0, =ELFIN_CLOCK_BASE
ldr r2, =CLK_DIV_FSYS2_OFFSET
ldr r1, [r0, r2]
orr r1, r1, #0xf
str r1, [r0, r2]
#endif
mov r0, #SDMMC_CH2
str r0, _boot_device
bl load_uboot_image
b load_uboot_exit
emmc_boot:
#if defined(CONFIG_CLK_1000_400_200) || defined(CONFIG_CLK_1000_200_200) || defined(CONFIG_CLK_800_400_200)
ldr r0, =ELFIN_CLOCK_BASE
ldr r2, =CLK_DIV_FSYS1_OFFSET
ldr r1, [r0, r2]
orr r1, r1, #0x3
str r1, [r0, r2]
#endif
mov r0, #EMMC
str r0, _boot_device
bl load_uboot_image
b load_uboot_exit
emmc_boot_4_4:
#if defined(CONFIG_CLK_1000_400_200) || defined(CONFIG_CLK_1000_200_200) || defined(CONFIG_CLK_800_400_200)
ldr r0, =ELFIN_CLOCK_BASE
ldr r2, =CLK_DIV_FSYS3_OFFSET
ldr r1, [r0, r2]
orr r1, r1, #0x3
str r1, [r0, r2]
#endif
/* mmc ch4 devider value change */
// bl mmc_ch4_devider_change
mov r0, #EMMC_4_4
str r0, _boot_device
bl load_uboot_image
/* store second boot information in DRAM */
ldr r0, =CONFIG_PHY_UBOOT_BASE
ldr r1, [r0]
ldr r2, =0x2000
cmp r1, r2
bne second_mmcsd_boot
b load_uboot_exit
load_uboot_exit:
pop {pc}
/********************************************************************/
149行附近时钟,内存初始化部分。
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 sdram init and u-boot.bin loading */
ldr r0, =CHIP_ID_BASE
ldr r1, [r0]
lsr r1, r1, #8
and r1, r1, #3
cmp r1, #2
bne v310_1
bl mem_ctrl_asm_init
bl system_clock_init
b 1f
v310_1:
bl system_clock_init
bl mem_ctrl_asm_init_ddr3
1:
b load_uboot
cold_boot:
bl relocate_code
ldr r0, _boot_device
b coldboot
修改为:
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 sdram init and u-boot.bin loading */
ldr r0, =CHIP_ID_BASE
ldr r1, [r0]
lsr r1, r1, #8
and r1, r1, #3
cmp r1, #2
bne v310_1
/* Memory initialize */
bl mem_ctrl_asm_init
/* init system clock */
bl system_clock_init
b 1f
v310_1:
/* init system clock */
bl system_clock_init
/* Memory initialize */
bl mem_ctrl_asm_init_ddr3
1:
bl load_uboot
/******* 若拷贝了则点亮此LED灯*************************/
ldr r0, =0x11000100 // GPL2CON的地址是0x11000100
ldr r1, [r0] // 先读出原值
bic r1, r1, #0xf // 清除bit[3:0]
orr r1, r1, #1 // 设置bit[3:0]为0b0001
str r1, [r0] // 写入GPL2CON
ldr r0, =0x11000104 // GPL0DAT的地址是0x11000104
ldr r1, [r0] // 读出原值
orr r1, r1, #1 // bit[0]为1
str r1, [r0] // 写入GPL0_0
mov r1, #0x1000000
3: subs r1, r1, #1
bne 3b
_boot_device:
.word 0x0
after_copy:
保存编译,烧到开发板.发现另一个LED灯 根本没亮过,说明BL1已经把完整的UBOOT拷贝到 内存。
14 网卡移植,迅为网卡芯片为DM9621, USB接口的网络芯片。驱动与DM9000完全不同,如果哪位移植成功, 请告诉我一声,QQ731793898,谢谢!