 arm學習筆記(ji)及(ji)嵌入式系統(tong)移植步驟詳解
							時間:2018-08-14      來源:未知(zhi)
							arm學習筆記(ji)及(ji)嵌入式系統(tong)移植步驟詳解
							時間:2018-08-14      來源:未知(zhi) 
							一、arm復習
芯片組成(cheng):控(kong)制器 存儲器 運算器
1、寄存器:
1)通用寄存器:r0-r15 r13:sp r14:lr r15:pc
2)程序狀態寄存器: cpsr spsr 高4位(NZCV) 低8位(FITM)
2、模式
3、異常
通用指令:
移動(dong):mov
四則:add sub
位:and orr
比較(jiao):cmp
moveq
跳轉(zhuan):b bl
mov pc, lr
ldr pc, =main
存取(qu):str ldr
ldr r1, [r0]
str r1, [r0]
多寄(ji)存(cun)器(qi):stmfd ldmfd
1、需求:com2 poll 發送 接收 (字符(fu)串)
2、看原理圖:
1)原理
2)管腳:BUF_XuTXD2---》GPA1_1 BUF_XuRXD2--》GPA1_0
3)控制芯片:有芯片,芯片手冊去看
3、看芯片手冊:
1)管腳: GPA1CON
2)控制芯片(pian):
驅動:
start.S : 啟動(dong)文件
main.c : 源文件(jian),驅動(dong)文件(jian)
makefile :編譯(yi)文件
map.lds :鏈接文件
s-->o : arm-linux-gcc start.S -o start.o -c
o--->elf: arm-linux-ld -Tmap.lds start.o -o start.elf
elf--->bin: arm-linux-objcopy -O binary start.elf start.bin
main.c
void uart_sendch(char a)
{
UTXHn = a;
}
void uart_init(void)
{
/*管腳(jiao)*/
GPA1CON = GPA1CON & ~0xff | 0x22;
/*控(kong)制芯片*/
ULCONn = 0x3;
UCONn = UCONn & ~0xf | 0x1 | 0x1<<2;
UBRDIVn = 0x35;
UFRACVALn = 0x4;
}
void main()
{
char a = 'A';
uart_init();
uart_sendch(a);
}
二、加載內核(he)
sudo apt-get install tftpd-hpa
u-boot-fs4412.bin BootLoader二進制文件
uImage 內(nei)核的二(er)進制文件
Exynos4412-fs4412.dtb 設備樹的二進(jin)制文件
ramdisk.img 根文件(jian)(jian)系統的二進制(zhi)文件(jian)(jian)
rootfs.tar.xz 根文件系統(tong)的壓縮包(bao)
gatewayip=192.168.2.1 網關
ipaddr=192.168.2.42 目標板IP
netmask=255.255.255.0 掩碼
serverip=192.168.2.240 服務器IP
set gatewayip 192.168.2.1
set ipaddr 192.168.2.42
set netmask 255.255.255.0
set serverip 192.168.2.240
save
tftp 41000000 uImage
tftp 42000000 exynos4412-fs4412.dtb
tftp 43000000 ramdisk.img
bootm 41000000 43000000 42000000
1、把壓(ya)縮包放到家目錄(lu)下某(mou)個目錄(lu)
2、進入這(zhe)個目錄 解壓: tar -xvf u-boot-2013.01.tar.bz2
3、cd u-boot-2013.01
修改makefile:
184 #ifeq ($(HOSTARCH),$(ARCH))
185 CROSS_COMPILE ?= arm-linux-
186 #endif
4、make distclean //清理環境,只在第一次使用(yong)
5、make origen_config //選(xuan)中需要編譯的芯片和(he)板子
6、make //編譯
三、uboot流程
1、找入口---》鏈接文件--》Makefile
2、Makefile中找到 arch\arm\cpu\u-boot.lds
3、u-boot.lds --》ENTRY(_start) //入(ru)口函數
CPUDIR/start.o (.text*) //第一個代碼文件
4、_start:(start.S)
-->reset
-->set the cpu to SVC32 mode && 關中斷
-->Setup vector
-->cpu_init_cp15 //Invalidate L1 I/D disable MMU
-->cpu_init_crit
-->lowlevel_init(board/samsung/origen/lowlevel_init.S)
-->如果在(zai)內(nei)存(cun)中:直接(jie)到下一步;如果不在(zai)內(nei)存(cun)中:system_clock_init mem_ctrl_asm_init
--> 初始化uart uart_asm_init
--> tzpc_init
-->_main(arch\arm\lib\crt0.S)
-->搭建C環境
--> 清bss
--> board_init_r (arch\arm\lib\board.c)
-->各種(zhong)設備的(de)初始化,各種(zhong)邏輯(ji)的(de)初始化后
-->for() //等(deng)待命令(ling),執(zhi)行(xing)命令(ling)
--》main_loop
四、uboot移植(zhi)流程(cheng)
1、需求(qiu):把內核加載起來
2、確認芯(xin)片是否(fou)支持(chi)(rch\arm\cpu\armv7)
1)支持 goto 3
2) 不支持(新(xin)的uboot,芯片廠商(shang)
3、確(que)認板子是否支(zhi)持(board)
1)支持:
2)不(bu)支(zhi)持:新uboot 板(ban)子(zi)廠家 找芯(xin)片(pian)一模一樣的(de)板(ban)子(zi)(origen)
4、cp board/samsung/origen board/samsung/fs4412 -af
cp include/configs/origen.h include/configs/fs4412.h
修改(gai) boards.cfg 增(zeng)加(jia):
origen arm armv7 origen samsung exynos
fs4412 arm armv7 fs4412 samsung exynos
5、編譯
6、燒寫:
1)斷電,撥碼開關(guan)撥到 SD卡啟動
2)上電,進(jin)入uboot命(ming)令行 FS4412 #
3)tftp 41000000 u-boot.bin (ubunt 把uboot.bin 拷(kao)貝到 tftp目錄)
4)movi write u-boot 41000000
1)斷電(dian),撥(bo)碼開關(guan)撥(bo)到 EMMC啟(qi)動(dong)
2)上電 ,就(jiu)能看到我們自己做的(de)uboot的(de)效果了(le)
7、驗證:
現(xian)象:板(ban)子變板(ban)磚(zhuan)
思考:程序是(shi)否執行到 ---》 添加一個觀(guan)察點 --》程序開始的地方(fang)點燈
在(zai) start.S中(zhong) 135行下添加:
136 /*led on*/
137 ldr r0, =0x11000c40
138 ldr r1,[r0]
139 bic r1,r1,#0xf0000000
140 orr r1,r1,#0x10000000
141 str r1,[r0]
142
143 ldr r0, =0x11000c44
144 ldr r1,[r0]
145 orr r1,r1,#0x80
146 str r1,[r0]
現象(xiang): 板子依然(ran)是板磚。。。。。
思考(kao): uboot 沒(mei)(mei)有(you)被(bei)執行 ----> 上電 到 uboot啟動 中間有(you)一塊 沒(mei)(mei)有(you)搞清楚(chu)的 ---》 芯(xin)片手(shou)冊 5章節
emmc : bl1 + bl2 + uboot
拷貝 CodeSign4SecureBoot 到 uboot的主目錄下
進(jin)入主(zhu)目錄,執行./build.sh
現象: 板子燈終于亮了(le)(le)(le)。。。。 but 燈滅了(le)(le)(le) then 亮了(le)(le)(le) 滅了(le)(le)(le)。。。。。
思考: uboot在(zai)板子(zi)上運行了(le)。板子(zi)在(zai)不斷的(de)復位
復位原因:1、異常(chang): X
2、看(kan)門狗: X
從下往上找,逆向思維,電源(yuan)---》電源(yuan)管理模塊
ONO 高電平輸出(chu)
現象: 燈一(yi)直亮著(zhu)。。。。 but 終端還是沒有打印(yin)
思考: 去看看串(chuan)口是(shi)否ok ---》 修(xiu)改串(chuan)口時(shi)鐘,確認是(shi)100M
現象:終(zhong)端有顯示了,但是ping命令(ling)沒(mei)有
思考:ping有,但是(shi)是(shi)否編譯進去了, common的(de)目錄下去找ping ,ping由宏(hong)開關控制, 打開這個宏(hong)開關
現(xian)象(xiang):ping命(ming)令有了, but 卡(ka)死了
思考: 懷疑網卡(ka)是不是出了問題(ti)。。。 找(zhao)dm9000初始化 dm9000_initialize
board_init_r--》eth_initialize --》board_eth_init --》dm9000_initialize
在origin.c 里面 添加網卡初始化 及對應的頭文件內容
#ifdef CONFIG_DRIVER_DM9000
int board_eth_init(bd_t *bis)
{
return dm9000_initialize(bis);
}
#endif
頭(tou)文件修改 fs4412.h,具體內容(rong)在(zai)實驗手冊中看
現(xian)象:網(wang)卡有(you)了,但(dan)是出現(xian)下(xia)面(mian)的打(da)印
ERROR: resetting DM9000 -> not responding
dm9000 not found at 0x05000000 id: 0x00000000
ping failed; host 192.168.2.240 is not alive
思考:0x05000000地址的(de)設備(bei)有問題,需要(yao)把這個設備(bei)初始化好,該設備(bei)是(shi)SROMC(這個分(fen)析原(yuan)理圖(tu),由(you)片選得(de)知(zhi)的(de))
在origin.c 中(zhong)增(zeng)加(jia)如下調(diao)用:
board_init (參考的)
--》smc9115_pre_init
--》s5p_gpio_cfg_pin
--》s5p_config_sromc
board_init (我(wo)們自己加的)
--》sdm9000aep_pre_init
--》gpio設置,未封裝
--》exynos_config_sromc
現象:網(wang)絡有了,可以用了
五、編譯內核
修改makefile
ARCH ?= arm
CROSS_COMPILE ?= arm-linux-
1、make exynos_defconfig //arch/arm/configs
2、make menuconfig // 功能的選(xuan)擇 增加或(huo)者刪(shan)減或(huo)者修改
3、make uImage
sudo apt-get install libncurses-dev
mkimage
cp arch/arm/boot/dts/exynos4412-origen.dts arch/arm/boot/dts/exynos4412-fs4412.dts
vi arch/arm/boot/dts/Makefile exynos4412-fs4412.dtb
make dtbs
增加網卡(ka)設備(bei):
1、make menuconfig dm9000增加
2、修改設備(bei)樹文件 exynos4412-fs4412.dts
  #include 
srom-cs1@5000000 {
compatible = "simple-bus";
#address-cells = <1>;
#size-cells = <1>;
reg = <0x5000000 0x8000000>;
ranges;
ethernet@5000000 {
compatible = "davicom,dm9000";
reg = <0x5000000 0x2 0x5000004 0x2>;
interrupt-parent = <&gpx0>;
interrupts = <6 IRQ_TYPE_LEVEL_HIGH>;
davicom,no-eeprom;
};
};
自動的把網卡設備(bei)開啟,把ip設置好
Networking support --->
Networking options --->
[*] IP: kernel level autoconfiguration
bootargs=root=/dev/ram rw console=ttySAC2,115200 init=/linuxrc ip=192.168.2.42 clk_ignore_unused
NFS啟動
解壓rootfs壓縮包,得(de)到一個目錄,比(bi)如是:/home/lyx/mydd/rootfs
在Ubuntu下開啟nfs:
1、修改配(pei)置 /etc/exprots
/home/lyx/mydd/rootfs *(rw,sync,no_root_squash,no_subtree_check)
2、 sudo /etc/init.d/nfs-kernel-server restart
在 uboot界面(mian)下設置:
setenv bootargs root=/dev/nfs nfsroot=192.168.2.240:/home/lyx/mydd/rootfs rw console=ttySAC2,115200 init=/linuxrc ip=192.168.2.42 clk_ignore_unused
set bootcmd tftp 41000000 uImage\;tftp 42000000 exynos4412-fs4412.dtb\;bootm 41000000 - 42000000
修改內核(he)的配置,增加nfs
File systems --->
Network File Systems --->
<*> NFS client support
[*] Root file system on NFS
配置(zhi)好了,make Image 一下
六、busybox 制作(zuo)方法
1、解壓busybox-1.22.1.tar.bz2
2、進入busybox-1.2
2 執行 make menuconfig
Busybox Settings --->
Build Options --->
[*] Build BusyBox as a static binary (no shared libs) x x
(arm-linux-) Cross Compiler prefix
3、make
4、make install
5、cd _install 擴展我們(men)的目錄:etc lib proc sys tmp //自己創建,再添加
6、填(tian)充內容:
etc 參考之前發的 rootfs
lib :cp ~/mydd/gcc-4.6.4/arm-arm1176jzfssf-linux-gnueabi/lib/* lib/ -af
7、rm xxxxx/rootfs -rf
cp _install xxxx/rootfs -af

