ifeq($(HOSTARCH),$(ARCH))CROSS_COMPILE?=endif
下添加
ifeq(arm,$(ARCH))CROSS_COMPILE?=arm-none-linux-gnueabi-endif
交叉编译工具
查看u-boot源码:
arch/arm/cpu/armv7/exynos/
可见U-boot已支持该CPU。
指定产品BOARD 三星公司已经为exynos 4412发布了初始化的程序:origen
cpu硬件信息 对应的该CPU硬件信息头文件位于以下位置:
include/configs/origen.h
该文件定义了uboot启动必须关于exynos 4412必须的一些资源信息。
boards.cfg 在uboot-2013-01中,顶层目录下的boards.cfs文件中查看它支持的开拓板和相应的信息,后续的编译过程须要根据配置名检索到相应的信息。文件格式如下:和以前的老版本比,配置更加规范化了,实在这些便是干系文件分类的一个文件夹的描述。依照这个层次关系,我们可以很方便地对我们开拓板进行配置。
编译u-boot不同版本的uboot的配置命令可能是不同的,源码包的文件README常日会有相应的配置命令【其他版本的uboot会不一样】:
配置和编译命令如下:
$makedistclean$makeorigen_config
改配置命令会天生以下文件:
include/config.h
config.h
编译:
$makeall
编译完成后天生的u-boot.bin便是可实行的镜像文件。
但是并不会天生真正适配我们板子的uboot,只是适配参考板,该文件还不能在我们板子上运行,我们须要对u-boot源代码进行相应的修正。
2. 确认第一条指令有运行到 (点灯法)在arch/arm/cpu/armv7/start.S 134 行后添加点灯程序
#if1ldrr0,=0x11000c40@GPX2_7led2ldrr1,[r0]bicr1,r1,#0xf0000000orrr1,r1,#0x10000000strr1,[r0]ldrr0,=0x11000c44movr1,#0xffstrr1,[r0]#endif
由于uboot刚启动的时候,串口没有来得及初始化,我们可以通过点亮LED的方法来判断程序是否实行到此处。
代码详解参考《十、LED汇编、C措辞驱动编写》
3. 添加三星加密办法exynos 须要三星供应的初始勾引加密后,我们的u-boot,才能被勾引运行,这个中要用到下面的几个命令或三星供应的工具软件,这些操作的目的便是根据三星的芯片的启动哀求对uboot.bin 进行一些处理,包括在特定长度的位置加上和校验信息以及插入一些文件段。
$cpsdfuse_qu-boot-2013.01-rf$chmod777u-boot-2013.01/sdfuse_q-R$cpCodeSign4SecureBootu-boot-2013.01-rf
注:CodeSign4SecureBoot 三星供应的安全启动办法 ,对应的程序由三星供应。sdfuse_q目录下的文件是针对三星堆uboot.bin文件格式哀求进行加密编写的文件。
修正根目录Makefile,实现sdfuse_q的编译 在
$(obj)u-boot.bin:$(obj)u-boot$(OBJCOPY)${OBJCFLAGS}-Obinary$<$@$(BOARD_SIZE_CHECK)
下添加
@#./mkuboot@split-b14336u-boot.binbl2@make-Csdfuse_q/@#cpu-boot.binu-boot-4212.bin@#cpu-boot.binu-boot-4412.bin@#./sdfuse_q/add_sign@./sdfuse_q/chksum@./sdfuse_q/add_padding@rmbl2a@echo
把稳是tab键缩进的,否则makefile编译报错 把稳如果实行了make distclean 需重新拷贝CodeSign4SecureBoot
为方便起见,在根目录下创建编译脚本build.sh,该脚本将自动完成添加加密办法。
1#!/bin/sh23sec_path="CodeSign4SecureBoot/"4CPU_JOB_NUM=$(grepprocessor/proc/cpuinfo|awk'{field=$NF};END{printfield+1}')5ROOT_DIR=$(pwd)6CUR_DIR=${ROOT_DIR##/}78case"$1"in9clean)10echomakeclean11makemrproper12;;13)1415if[!-d$sec_path]16then17echo""18echo"[ERR]pleasegettheCodeSign4SecureBootfirst"19echo""20return21fi2223makeorigen_config2425make-j$CPU_JOB_NUM2627if[!-fchecksum_bl2_14k.bin]28then29echo"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"30echo"Therearesomeerror(s)whilebuildinguboot,pleaseusecommandmaketocheck."31echo"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"32exit033fi3435cp-rfchecksum_bl2_14k.bin$sec_path36cp-rfu-boot.bin$sec_path37rmchecksum_bl2_14k.bin3839cd$sec_path40catE4412_N.bl1.SCP2G.binbl2.binall00_padding.binu-boot.bintzsw_SMDK4412_SCP_2GB.bin>u-boot-origen.bin41mvu-boot-origen.bin$ROOT_DIR4243rmchecksum_bl2_14k.bin44rmu-boot.bin4546echo47echo48;;4950esac
编译脚本
$chmod777u-boot-2013.01/build.sh$./buildsh
注:build.sh 脚本办法完成自动添加加密办法, 编译天生所需文件u-boot_origen.bin
root@ubuntu:/home/peng/uboot/u-boot-2013.01#lsapiconfig.mkexamplesMakefilesdfuse_qu-boot.binarchCOPYINGfsmkconfigsnapshot.commitu-boot.mapboardCREDITShelper.mknand_splsplu-boot-origen.binboards.cfgdiskincludenetSystem.mapu-boot.srecbuild.shdoclibposttestCodeSign4SecureBootdriversMAINTAINERSREADMEtoolscommondtsMAKEALLrules.mku-boot
u-boot_origen.bin
4. 实现串口输出
修正lowlevel_init.S文件
$vimboard/samsung/origen/lowlevel_init.S
a) 添加临时栈,在
41lowlevel_init:
后添加
ldrsp,=0x02060000@useiRomstackinbl2
b) 添加关闭看门狗代码: 在
67beqwakeup_reset
后添加
#if1/forclosewatchdog//PS-Holdhigh/ldrr0,=0x1002330cldrr1,[r0]orrr1,r1,#0x300strr1,[r0]ldrr0,=0x11000c08ldrr1,=0x0strr1,[r0]/ClearMASK_WDT_RESET_REQUEST/ldrr0,=0x1002040cldrr1,=0x00strr1,[r0]#endif
c) 添加串口初始化代码: 在uart_asm_init: 的
351strr1,[r0,#EXYNOS4_GPIO_A1_CON_OFFSET]
后添加
ldrr0,=0x10030000ldrr1,=0x666666ldrr2,=CLK_SRC_PERIL0_OFFSETstrr1,[r0,r2]ldrr1,=0x777777ldrr2,=CLK_DIV_PERIL0_OFFSETstrr1,[r0,r2]
d) 注释掉trustzone初始化 注释掉
104bluart_asm_init
下的代码:
#if0bltzpc_init#endif
5. 网卡移植
由于各个厂家利用的网卡不尽相同,以是三星公司供应的驱动程序只预留了网卡初始化的函数入口,针对不同的板子,我们须要针对电路自己移植网卡的驱动。网卡的驱动详解,我们会在后一章节详细讲解。
1、 添加网络初始化代码
$vimboard/samsung/origen/origen.c
在
31structexynos4_gpio_part2gpio2;
后添加:
#ifdefCONFIG_DRIVER_DM9000#defineEXYNOS4412_SROMC_BASE0X12570000#defineDM9000_Tacs(0x1)#defineDM9000_Tcos(0x1)#defineDM9000_Tacc(0x5)#defineDM9000_Tcoh(0x1)#defineDM9000_Tah(0xC)#defineDM9000_Tacp(0x9)#defineDM9000_PMC(0x1)structexynos_sromc{unsignedintbw;unsignedintbc[6];};/s5p_config_sromc()-selecttheproperSROMCBankandconfigurethebandwidthcontrolandbankcontrolregisterssrom_bank-SROMsrom_bw_conf-SMCBandwitdhregconfigurationvaluesrom_bc_conf-SMCBankControlregconfigurationvalue/voidexynos_config_sromc(u32srom_bank,u32srom_bw_conf,u32srom_bc_conf){unsignedinttmp;structexynos_sromcsrom=(structexynos_sromc)(EXYNOS4412_SROMC_BASE);/ConfigureSMC_BWregistertohandleproperSROMCbank/tmp=srom->bw;tmp&=~(0xF<<(srom_bank4));tmp|=srom_bw_conf;srom->bw=tmp;/ConfigureSMC_BCregister/srom->bc[srom_bank]=srom_bc_conf;}staticvoiddm9000aep_pre_init(void){unsignedinttmp;unsignedcharsmc_bank_num=1;unsignedintsmc_bw_conf=0;unsignedintsmc_bc_conf=0;/gpioconfiguration/writel(0x00220020,0x11000000+0x120);writel(0x00002222,0x11000000+0x140);/16Bitbuswidth/writel(0x22222222,0x11000000+0x180);writel(0x0000FFFF,0x11000000+0x188);writel(0x22222222,0x11000000+0x1C0);writel(0x0000FFFF,0x11000000+0x1C8);writel(0x22222222,0x11000000+0x1E0);writel(0x0000FFFF,0x11000000+0x1E8);smc_bw_conf&=~(0xf<<4);smc_bw_conf|=(1<<7)|(1<<6)|(1<<5)|(1<<4);smc_bc_conf=((DM9000_Tacs<<28)|(DM9000_Tcos<<24)|(DM9000_Tacc<<16)|(DM9000_Tcoh<<12)|(DM9000_Tah<<8)|(DM9000_Tacp<<4)|(DM9000_PMC));exynos_config_sromc(smc_bank_num,smc_bw_conf,smc_bc_conf);}#endif
在
gd->bd->bi_boot_params=(PHYS_SDRAM_1+0x100UL);
后添加
#ifdefCONFIG_DRIVER_DM9000dm9000aep_pre_init();#endif
在文件末端添加
#ifdefCONFIG_CMD_NETintboard_eth_init(bd_tbis){intrc=0;#ifdefCONFIG_DRIVER_DM9000rc=dm9000_initialize(bis);#endifreturnrc;}#endif
2、 修正配置文件添加网络干系配置 $ vim include/configs/origen.h 修正
85#undefCONFIG_CMD_PING
为
#defineCONFIG_CMD_PING
修正
90#undefCONFIG_CMD_NET
为
#defineCONFIG_CMD_NET
在文件末端
#endif/__CONFIG_H/
前面添加
#ifdefCONFIG_CMD_NET#defineCONFIG_NET_MULTI#defineCONFIG_DRIVER_DM90001#defineCONFIG_DM9000_BASE0x05000000//内存基地址#defineDM9000_IOCONFIG_DM9000_BASE#defineDM9000_DATA(CONFIG_DM9000_BASE+4)#defineCONFIG_DM9000_USE_16BIT#defineCONFIG_DM9000_NO_SROM1#defineCONFIG_ETHADDR11:22:33:44:55:66#defineCONFIG_IPADDR192.168.6.187#defineCONFIG_SERVERIP192.168.6.186#defineCONFIG_GATEWAYIP192.168.1.1#defineCONFIG_NETMASK255.255.255.0#endif
个中CONFIG_DM9000_BASE 地址为何是0x05000000,后续章节会详细剖析。
6. FLASH移植 (EMMC)移植EMMC须要添加一些源文件:cmd_mmc.ccmd_mmc_fdisk.ccmd_movi.cmmc.cmmc.hmovi.cmovi.hs5p_mshc.cs5p_mshc.h
这些文件,由三星供应。
添加干系驱动cpmovi.carch/arm/cpu/armv7/exynos/
修正文件arch/arm/cpu/armv7/exynos/Makefile在pinmux.o 后添加movi.o
修正板级文件 board/samsung/origen/origen.c,在
#include<asm/arch/mmc.h>
后面添加
#include<asm/arch/clk.h>#include"origen_setup.h"
在
#ifdefCONFIG_GENERIC_MMC
后面添加
u32sclk_mmc4;/clocksourceforemmccontroller/#define__REGMY(x)(((volatileu32)(x)))#defineCLK_SRC_FSYS__REGMY(EXYNOS4_CLOCK_BASE+CLK_SRC_FSYS_OFFSET)#defineCLK_DIV_FSYS3__REGMY(EXYNOS4_CLOCK_BASE+CLK_DIV_FSYS3_OFFSET)intemmc_init(){u32tmp;u32clock;u32i;/setup_hsmmc_clock//MMC4clocksrc=SCLKMPLL/tmp=CLK_SRC_FSYS&~(0x000f0000);CLK_SRC_FSYS=tmp|0x00060000;/MMC4clockdiv/tmp=CLK_DIV_FSYS3&~(0x0000ff0f);clock=get_pll_clk(MPLL)/1000000;for(i=0;i<=0xf;i++){sclk_mmc4=(clock/(i+1));if(sclk_mmc4<=160)//200{CLK_DIV_FSYS3=tmp|(i<<0);break;}}emmcdbg("[mjdbg]sclk_mmc4:%dMHZ;mmc_ratio:%d\n",sclk_mmc4,i);sclk_mmc4=1000000;/MMC4EMMCGPIOCONFIGGPK0[0]SD_4_CLKGPK0[1]SD_4_CMDGPK0[2]SD_4_CDnGPK0[3:6]SD_4_DATA[0:3]/writel(readl(0x11000048)&~(0xf),0x11000048);//SD_4_CLK/SD_4_CMDpull-downenablewritel(readl(0x11000040)&~(0xff),0x11000040);//cdnsettobeoutputwritel(readl(0x11000048)&~(3<<4),0x11000048);//cdnpull-downdisablewritel(readl(0x11000044)&~(1<<2),0x11000044);//cdnoutput0toshutdowntheemmcpowerwritel(readl(0x11000040)&~(0xf<<8)|(1<<8),0x11000040);//cdnsettobeoutputudelay(1001000);writel(readl(0x11000044)|(1<<2),0x11000044);//cdnoutput1writel(0x03333133,0x11000040);writel(0x00003FF0,0x11000048);writel(0x00002AAA,0x1100004C);#ifdefCONFIG_EMMC_8Bitwritel(0x04444000,0x11000060);writel(0x00003FC0,0x11000068);writel(0x00002AAA,0x1100006C);#endif#ifdefUSE_MMC4smdk_s5p_mshc_init();#endif}
将 int board_mmc_init(bd_t bis)函数内容改写为
intboard_mmc_init(bd_tbis){inti,err;#ifdefCONFIG_EMMCerr=emmc_init();#endifreturnerr;}
在末端添加
#ifdefCONFIG_BOARD_LATE_INIT#include<movi.h>intchk_bootdev(void)//mjforbootdevicecheck{charrun_cmd[100];structmmcmmc;intboot_dev=0;intcmp_off=0x10;ulongstart_blk,blkcnt;mmc=find_mmc_device(0);if(mmc==NULL){printf("ThereisnoeMMCcard,BootingdeviceisSDcard\n");boot_dev=1;returnboot_dev;}start_blk=(241024/MOVI_BLKSIZE);blkcnt=0x10;sprintf(run_cmd,"emmcopen0");run_command(run_cmd,0);sprintf(run_cmd,"mmcread0%lx%lx%lx",CFG_PHY_KERNEL_BASE,start_blk,blkcnt);run_command(run_cmd,0);/switchmmctonormalparitition/sprintf(run_cmd,"emmcclose0");run_command(run_cmd,0);return0;}intboard_late_init(void){intboot_dev=0;charboot_cmd[100];boot_dev=chk_bootdev();if(!boot_dev){printf("\n\nCheckingBootMode...EMMC4.41\n");}return0;}#endif
添加干系命令
$cpcmd_movi.ccommon/$cpcmd_mmc.ccommon/$cpcmd_mmc_fdisk.ccommon/
修正common/Makefile 在
COBJS-$(CONFIG_CMD_MMC)+=cmd_mmc.o
后添加
COBJS-$(CONFIG_CMD_MMC)+=cmd_mmc_fdisk.oCOBJS-$(CONFIG_CMD_MOVINAND)+=cmd_movi.o
添加驱动
$cpmmc.cdrivers/mmc/$cps5p_mshc.cdrivers/mmc/$cpmmc.hinclude/$cpmovi.hinclude/$cps5p_mshc.hinclude/
修正Makefile
$vimdrivers/mmc/Makefile
添加
COBJS-$(CONFIG_S5P_MSHC)+=s5p_mshc.o
添加EMMC干系配置
$viminclude/configs/origen.h
添加
#defineCONFIG_EVT11/EVT1/#ifdefCONFIG_EVT1#defineCONFIG_EMMC44_CH4//eMMC44_CH4(OMPIN[5:1]=4)#ifdefCONFIG_SDMMC_CH2#defineCONFIG_S3C_HSMMC#undefDEBUG_S3C_HSMMC#defineUSE_MMC2#endif#ifdefCONFIG_EMMC44_CH4#defineCONFIG_S5P_MSHC#defineCONFIG_EMMC1#defineUSE_MMC4/#defineCONFIG_EMMC_8Bit/#defineCONFIG_EMMC_EMERGENCY/#defineemmcdbg(fmt,args...)printf(fmt,##args)///foremmcdebug#defineemmcdbg(fmt,args...)#endif#endif/endCONFIG_EVT1/#defineCONFIG_CMD_MOVINAND#defineCONFIG_CLK_1000_400_200#defineCFG_PHY_UBOOT_BASECONFIG_SYS_SDRAM_BASE+0x3e00000#defineCFG_PHY_KERNEL_BASECONFIG_SYS_SDRAM_BASE+0x8000#defineBOOT_MMCSD0x3#defineBOOT_EMMC430x6#defineBOOT_EMMC4410x7#defineCONFIG_BOARD_LATE_INIT
7. 重新编译u-boot
修正顶层Makefile,注释掉spl的编译:
623#$(obj)spl/u-boot-spl.bin:$(SUBDIR_TOOLS)depend624#$(MAKE)-Csplall
重新编译uboot:
$./build.sh
在根目录下会天生bin文件u-boot-origen.bin。
二、SD卡制作1. 烧写脚本三星公司已经给我们供应了制作SD卡启动的烧写的脚本:mkuboot.sh
#!/bin/bash##Thisscriptwillcreateau-bootbinaryformovinand/mmcboot#echo"FuseFS4412trustzoneubootfileintoSDcard"if[-z$1]#判断参数1的字符串是否为空,如果为空,则打印出帮助信息then./sd_fusing_exynos4x12.sh/dev/sdbu-boot-origen.binelse./sd_fusing_exynos4x12.sh$1u-boot-origen.binfi
sd_fusing_exynos4x12.sh
1#!/bin/sh2#3#Copyright(C)2010SamsungElectronicsCo.,Ltd.4#http://www.samsung.com/5#6#Thisprogramisfreesoftware;youcanredistributeitand/ormodify7#itunderthetermsoftheGNUGeneralPublicLicenseversion2as8#publishedbytheFreeSoftwareFoundation.9#10####################################11reader_type1="/dev/sd"12reader_type2="/dev/mmcblk0"1314if[-z$2]#判断参数2的字符串是否为空,如果为空,则打印出帮助信息15then16echo"usage:./sd_fusing.sh<SDReader'sdevicefile><filename>"17exit018fi1920param1=`echo"$1"|awk'{printsubstr($1,1,7)}'`2122if["$param1"="$reader_type1"]23then24partition1=$1"1"25partition2=$1"2"26partition3=$1"3"27partition4=$1"4"2829elif["$1"="$reader_type2"]30then31partition1=$1"p1"32partition2=$1"p2"33partition3=$1"p3"34partition4=$1"p4"3536else37echo"UnsupportedSDreader"38exit039fi4041if[-b$1]#判断参数1所指向的设备节点是否存在42then43echo"$1readerisidentified."44else45echo"$1isNOTidentified."46exit047fi4849####################################50#format51umount$partition12>/dev/null52umount$partition22>/dev/null53umount$partition32>/dev/null54umount$partition42>/dev/null5556echo"$2fusing..."#烧写u-boot-origen.bin到SD卡(512+8K)字节处,512+8K=17x512,即第17个block57ddiflag=dsyncoflag=dsyncif=$2of=$1seek=1&&\58echo"$2imagehasbeenfusedsuccessfully."5960#echo"zImagefusing..."61#ddiflag=dsyncoflag=dsyncif=../../TC4_Kernel_3.0/arch/arm/boot/zImageof=$1seek=1024&&\62#echo"zImagehasbeenfusedsuccessfully."6364#echo"ramdisk-uboot.imgfusing..."65#ddiflag=dsyncoflag=dsyncif=../../TC4_GB_2.3.4/out/target/product/smdk4212/ramdisk-uboot.imgof=$1seek=9216&&\66#echo"ramdisk-uboot.imghasbeenfusedsuccessfully."6768####################################69#<MessageDisplay>70echo"EjectSDcard"71
2. 制作步骤
a) 创建文件mkuboot.sh、sd_fusing_exynos4x12.sh b) 将SD卡插入电脑并被ubuntu识别 c) 拷贝编译好u-boot-origen.bin拷贝到当前目录下
root@ubuntu:/home/peng/uboot/sdfuse_q#lsmkuboot.shsd_fusing_exynos4x12.shu-boot-origen.bin
d) 进入sdfuse_q实行如下操作
root@ubuntu:/home/peng/uboot/sdfuse_q#./mkuboot.sh/dev/sdb
d) 在SD卡中创建目录sdupdate,并把编译好的uboot镜像文件u-boot-origen.bin拷贝到这个目录。
3. 通过sd卡启动烧写uboota) 连接串口和板子,运行串口通信程序putty
选择右上角的”Serial”,然后点击左下角的”Serial”
按照自己的主机的情形选择COM口其他必须一贯,然后点击open打开串口
b) 关闭开拓板电源,将拨码开关SW1调至(1000)(SD启动模式)后打开电源 c) 将刚才做好的SD启动盘插入SD卡插槽 d) 重新打开开拓板能够看到如下界面
在这里插入图片描述
在读秒倒计时时按任意键。由上图所示,已经支持EMMC和dm9000网卡。
e) 烧写 在终端上实行
sdfuseflashall
把稳:上面的命令把SD卡 sdupdate目录下的u-boot-origen.bin烧写到emmc起始位置 等待终端无输出是表示烧写结束
f) 关闭开拓板电源,将拨码开关SW1调至0110(EMMC启动模式)后打开电源即可以从emmc启动
4. 网络烧写uboot如果板子已经可以启动uboot,我们也可以通过网络烧写uboot。
步骤如下:
把编译好的u-boot-origen.bin拷贝到/tftpboot下启动开拓板,在u-boot下先下载u-boot-origen.bin到41000000;再运行moviwriteu-boot41000000
若编译后的u-boot-origen.bin 无法运行,可参考上一节,重新从SD卡勾引烧写。
文中资料后台回答:uboot