系統移植

系統移植第一天php

 

1 基礎理論

1.1 什麼是嵌入式

以應用爲中心、以計算機技術爲基礎、軟件硬件可裁剪、適應應用系統,對功能、可靠性、成本、體積、功耗嚴格要求的專用計算機系統。css

可裁剪(軟硬件)

1.2 什麼是系統

1.2.1 硬件系統

馮諾依曼結構: 控制器,運算器,輸入,輸出, 存儲器java

傳統的硬件架構: cpu,內存,北橋(高速設備)+ 南橋(慢速設備) --》 芯片組, 顯卡 ,外設等等python

SOC(system on chip) 片上系統 ,一個芯片集成了硬件系統的主要部件 (內存和外存 引出去的目的: 方便定製)linux

arm: a r m 三個系列ios

a系列(高性能) a9 a53 a7x m系列 (低功耗,相對51高性能)m0 m3 m4 m7 r系列 (高實時,高可靠性)git

4412—》 cortex-a9 armv7 stm32f103rct6 --》 cortex-m3github

1.2.2 軟件系統

1.2.2.1 無操做系統(裸機)

應用–》 驅動–》硬件 stm32中 寫程序 調用驅動程序 控制硬件web

1.2.2.2 有操做系統

應用程序 --》 系統調用–》 內核 --》 驅動–》硬件面試

2 什麼是移植

將一些功能 搬移到 指定的硬件平臺上去

2.1 系統移植四大件(五大件)

(1) 交叉編譯器 cross - complier (2) 啓動引導程序 BootLoader (3) 內核(linux操做系統)kernel (4) 根文件系統 rootfs

(5)應用程序

2.2 來裝個系統

2.2.1 交叉編譯器 --》 gcc

2.2.2

bios --》BootLoader bios: basic input output system bios --> uefi t通用外部固件接口

上電的第一段代碼 : 初始化,檢查硬件–》 引導系統–》 給系統傳參

好比咱們的電腦 能夠選擇 硬盤,光驅,優盤,網絡(無盤工做站)來裝系統或者運行系統

2.2.3

內核–》 操做系統內核 (windows NT)

2.2.4

根文件系統 --》 c盤的文件,功能性的,非操做系統的

2.3 以人爲類比

BootLoader 鬧鐘,媽

kernel 靈魂

rootfs 肉體,器官

3 交叉編譯器

通常整個工程項目開始前,交叉編譯器必須定下來,後期不會作較大更改

gcc(本平臺生成本平臺目標機代碼)

x86 —》 x86 程序

cross 交叉(本平臺實現 目標機爲arm 的代碼)

x86 —》 arm 程序

通常狀況下,包含在硬件廠商提供的 板級支持包內 (BSP board support package)

編譯器提供網站下載 https://www.linaro.org/latest/downloads/

arm 嵌入式設備 交叉編譯器提供組織

也能夠本身製做

crosstool-ng 工具 能夠生成 交叉編譯器

3.1 交叉編譯器的配置

1. 上傳gcc文件壓縮包

2. 解壓縮

linux@ubuntu:~$ tar xvf gcc-4.6.4.tar.xz

3. ~/gcc-4.6.4/bin/arm-none-linux-gnueabi-gcc ./1.c
是能夠編譯的,可是不方便 每次要找 gcc的路徑

4. sudo vi /etc/bash.bashrc

在最後一行追加

export PATH=$PATH:/home/linux/gcc-4.6.4/bin

注意點 是 $ 美圓 不是 s
bin 後面不要加斜槓
上面64行 fi 不能亂改

5. source /etc/bash.bashrc
相似於 改完參數以後點應用

6. 輸入 arm-n tab鍵能補齊

arm-none-linux-gnueabi-

7. 或者輸入 arm-none-linux-gnueabi-gcc -v
能顯示版本信息便可

3.2 常見命令

readelf

-h 顯示 elf 頭部信息
-s 顯示段信息

size

計算各個段的大小

nm

顯示符號

strip

刪除符號 --》 精簡文件 --》嵌入式必須

objdump

反彙編 -D

objcopy

拷貝或轉換 目標文件 拷貝二進制 -O binary 注: 大寫O

4 環境搭建

BootLoader: 自己在 板子的emmc內部 已燒寫完畢

內核文件 uImage 是經過tftp傳輸到內存地址的 exyons4412-fs4412.dtb 設備樹文件 也是tftp

根文件系統 /rootfs是經過 nfs的方式 遠程同步的(掛載)

4.1 tftp 和 nfs

tftp 簡單文件傳輸協議 udp

重啓大法:

sudo service tftp-hpa restart

nfs 網絡文件系統 (無盤工做站)

4.2 ubbot 經常使用命令

先在設備管理器裏面看一下端口是幾 putty 選 serial 波特率 115200 com幾寫好 左下角流控制設置爲 none 保存

注意撥碼開關

011x 是emmc上啓動 uboot 100x 是sd卡 啓動uboot

上電 敲任意鍵暫停

若是bootcmd內有內容 則會倒計時等待 不敲任意鍵則會執行 bootcmd

setenv bootcmd
saveenv

顯示 uboot支持的命令 (不是linux的)

(1)help + 命令 相似於man的做用

(2)printenv 打印全部的環境信息

(3)setenv

Usage:
setenv [-f] name value ...
- [forcibly] set environment variable 'name' to 'value ...'
setenv [-f] name
- [forcibly] delete environment variable 'name'

setenv + 變量名 + 值 則設置這個值 只加變量名 則清空這個值

(4)saveenv

(5) md
memory display 顯示內存的內容

md + 地址(16進制) (6)mm nm6 mm 修改後自增地址 (要算) nm 修改後 地址不變

LED3 

gpx1_0 GPX1CON 輸入輸出模式

0x1100_0C20 [3:0] 0x1 = Output

(1) md 0x11000c20

(2) nm 0x11000c20
--》0x1
--》 q
--》 md 0x11000c20 驗證

dat GPX1DAT 實際填入的數值
0x1100_0C24 0x1
(3) nm 0x11000c24 
--> 0x1 亮
--> 0x0 滅

4.3 掛板子

設置板子和Ubuntu的 ip地址

建議 Ubuntu 設置爲 192.168.2.200 右上角標記 新建一個 取名叫board 填入 192.168.2.200 255.255.255.0 192.168.2.1 保存

板子設置爲 192.168.2.100
網關gateway 192.168.2.1
netmask 255.255.255.0
板子上:

ipaddr 板子的地址
serverip 是Ubuntu的地址

(1)
setenv ipaddr 192.168.2.100 (251)
setenv serverip 192.168.2.200 (250)
setenv gatewayip 192.168.2.1
saveenv

(2)
ping 192.168.2.200

看到alive 說明成功

--》 網線沒插
--》 虛擬機的地址不是這個
--》 虛擬機的網絡設置不是橋接 而是 nat
--》 wifi開着
--》 網線有問題


(3)tftp

Usage:
tftpboot 內存地址 (serverip地址,可忽略)文件名

在Ubuntu上 拷貝 uImage 和exyons4412-fs4412.dtb
到 /tftpboot

(1)sudo cp ./uImage /tftpboot
(2)sudo cp ./exyons4412-fs4412.dtb /tftpboot


板子上
(3)tftp 41000000 uImage
(4)tftp 42000000 exynos4412-fs4412.dtb
(5)bootm 41000000 - 42000000

bootm 內核 設備樹 文件系統(ramdisk)

bootcmd 能夠 將連續的操做保存着,若是bootcmd 不是缺省 則 延時會啓用

setenv bootcmd tftp 41000000 uImage \; tftp 42000000 exynos4412-fs4412.dtb \; bootm 41000000 - 42000000

注意反斜槓 和 41000000 42000000 之間的 -號 兩邊加空格

saveenv

此時完成上面操做會出錯

VFS: Cannot open root device 「(null)」 or unknown-block(0,0):

還差 nfs 根文件系統沒掛上

bootargs 須要設置 bootargs 實際上是 uboot給內核的傳參

bootargs 幾個要素: (1) root=?什麼類型 nand啓動 仍是emmc啓動 仍是其餘網絡啓動呢??

root=/dev/nfs 指定了 使用是 nfs方式

(2)nfsroot 在哪裏? nfsroot=ip:/路徑 讀寫

設置前缺認在不在這個目錄

nfsroot=192.168.2.200:/source/rootfs rw

(3) 第一個啓動的程序是誰

init=/linuxrc 第一個程序

(4) 從哪裏顯示

console=ttySAC2,115200

(5) 板子的ip地址

ip=192.168.2.100

(4)和(5)的緣由是 uboot完成啓動內核後,結束了工做,不存在了,因此串口輸出 和 ip地址須要經過傳參的方式發給內核

setenv bootargs root=/dev/nfs nfsroot=192.168.2.200:/source/rootfs rw console=ttySAC2,115200 init=/linuxrc ip=192.168.2.100

rm: can’t remove ‘hehe’: Permission denied

sudo chmod 777 /source/rootfs

做業:

掛板子成功,編譯一個helloworld 在板子上運行

 

 

系統移植次日

markdown

Bootloader

(面試)u-boot 和 bootloader 之間的區別 bootloader中的一種

訊爲itop 友善之臂 u-boot無資料

啓動引導程序

http://www.denx.de/wiki/U-Boot/Documentation ftp://ftp.denx.de/pub/u-boot

不是越新越好 最合適的版本:u-boot-2013.01.tar.bz2

目錄結構

平臺相關:arch board

咱們參考的板子是 origen 參考板 評估板

平臺無關: common uboot的命令源碼 include lib 等

編譯u-boot

make [board_name]_config
make origen_config

make fs4412_config

錯誤:

  1 linux@ubuntu:~/u-boot-2013.01$ make fs4412_config make: *** No rule to make target `fs4412_config’. Stop. make: *** [fs4412_config] Error 1 

解決方法:找到 no rule 在哪裏 

 

1 linux@ubuntu:~/u-boot-2013.01$ grep 「No rule to make target」 * ./* -nF

 

mkconfig:25: echo 「make: *** No rule to make target `$2_config’. Stop.」 >&2 ./mkconfig:25: echo 「make: *** No rule to make target `$2_config’. Stop.」 >&2 

 

–》vi mkconfig +25

–》 boards.cfg 裏面有匹配規則

 

1)target --》 origen (2)arch --》 arm (3)cpu --》 armv7 (4)board name --》 origen (5)vendor --》 samsung (6)soc --> exynos (7)option

 

 

 

操做 複製這一行 在下一行粘貼 把目標改掉

1 linux@ubuntu:~/u-boot-2013.01$ make fs4412_config Configuring for fs4412 board…

下一步 vi Makefile +184 平臺 寫成arm 交叉編譯器: 修改爲 

arm-none-linux-gnueabi-

 

下一步 make

錯誤: from lib/asm-offsets.c:18: /home/linux/u-boot-2013.01/include/config.h:10:28: fatal error: configs/fs4412.h: No such file or directory compilation terminated. make: *** [lib/asm-offsets.s] Error 1

實際上是在 include/configs/ 只有origen.h 沒有fs4412.h

在頂層目錄

 

1  cp ./include/configs/origen.h ./include/configs/fs4412.h 2 
3 操做: 41)make clean 52)make fs4412_config 63)make

 

生成了三個文件: u-boot.bin 二進制 u-boot.lds 連接腳本 u-boot.map

三星支持 u-boot.bin的格式

ubuntu:
sudo cp ./u-boot.bin /tftpboot
上電板子
板子上:
1 tftp 41000000 u-boot.bin 2 go 41000000

加載uboot失敗

(1) 地址不對 查看 u-boot.map 提示 _start地址在 0x43e00000 (三星定義)

(2)串口沒有設置過

u-boot 生成過程

make 出來的 u-boot.bin

–>

439 $(obj)u-boot.bin: $(obj)u-boot 440 $(OBJCOPY) ${OBJCFLAGS} -O binary $< $@ 441 $(BOARD_SIZE_CHECK)

找obj 143 obj := $(OBJTREE)/

找objtree

124 OBJTREE := $(if $(BUILD_DIR),$(BUILD_DIR),$(CURDIR))

找 OBJCOPY 找不到了 咱們要是用 vi -t

創建tags 索引

ctags -R  

搜索的時候 在這個tags存在的目錄下搜索便可

vi -t OBJCOPY config.mk 內 定位到了 150 OBJCOPY = $(CROSS_COMPILE)objcopy

關於連接腳本

 OUTPUT_FORMAT("elf32-littlearm", "elf32-littlearm", "elf32-littlearm") OUTPUT_ARCH(arm) ENTRY(_start) SECTIONS { . = 0x00000000; . = ALIGN(4); .text : { __image_copy_start = .; arch/arm/cpu/armv7/start.o (.text*) *(.text*) } . = ALIGN(4); .rodata : { *(SORT_BY_ALIGNMENT(SORT_BY_NAME(.rodata*))) } . = ALIGN(4); .data : { *(.data*) }

11 arch/arm/cpu/armv7/start.o (.text*)

本質 : u-boot

入口 是 start.S

彙編代碼分析

vi ./arch/arm/cpu/armv7/start.S

//1 初始化異常向量表 
40 ldr pc, _undefined_instruction 41 ldr pc, _software_interrupt 42 ldr pc, _prefetch_abort 43 ldr pc, _data_abort 44 ldr pc, _not_used 45 ldr pc, _irq 46 ldr pc, _fiq //2 設置arm指令集

127 bl save_boot_params 128/* set the cpu to SVC32 mode */

131 mrs r0, cpsr 132 bic r0, r0, #0x1f

133 orr r0, r0, #0xd3

134 msr cpsr,r0 –》 152 /* the mask ROM code should have PLL and others stable */

153 #ifndef CONFIG_SKIP_LOWLEVEL_INIT 154 bl cpu_init_cp15 155 bl cpu_init_crit 156 #endif

157

158 bl _main 159

//3 cpu_init_cp15 //關mmu(內存管理單元)

280 *

281 * cpu_init_cp15 282 *

283 * Setup CP15 registers (cache, MMU, TLBs). The I-cache is turned on unless 284 * CONFIG_SYS_ICACHE_OFF is defined. *
***********************************************************************/

287 ENTRY(cpu_init_cp15) 289 * Invalidate L1 I/D* /
291 mov r0, #0 @ set up for MCR 292 mcr p15, 0, r0, c8, c7, 0 @ invalidate TLBs 293 mcr p15, 0, r0, c7, c5, 0 @ invalidate icache 294 mcr p15, 0, r0, c7, c5, 6 @ invalidate BP array 295 mcr p15, 0, r0, c7, c10, 4 @ DSB 296 mcr p15, 0, r0, c7, c5, 4 @ ISB 297 298 / 299 * disable MMU stuff and caches*/
301 mrc p15, 0, r0, c1, c0, 0

302 bic r0, r0, #0x00002000 @ clear bits 13 (–V-) 303 bic r0, r0, #0x00000007 @ clear bits 2:0 (-CAM) 304 orr r0, r0, #0x00000002 @ set bit 1 (–A-) Align 305 orr r0, r0, #0x00000800 @ set bit 11 (Z—) BTB 306 #ifdef CONFIG_SYS_ICACHE_OFF 307 bic r0, r0, #0x00001000 @ clear bit 12 (I) I-cache 308 #else

309 orr r0, r0, #0x00001000 @ set bit 12 (I) I-cache 310 #endif

311 mcr p15, 0, r0, c1, c0, 0

312 mov pc, lr @ back to my caller 313 ENDPROC(cpu_init_cp15) 314

//4 cpu_init_crit 其餘板級初始化

324 ENTRY(cpu_init_crit) 325 /* * Jump to board specific initialization… The Mask ROM willhave already initializedbasic memory. Go here to bump up clock rate and handle wake up conditions.330 */ 
331 b lowlevel_init @ go setup pll,mux,memory 332 ENDPROC(cpu_init_crit) ==》 b lowlevel_init vi -t 是相似效果 在vi 內選中 關鍵字 ctrl + ‘]’ 前進 ctrl + ‘t’ 後退 追出來的第五十八個 跟origen 有關 81 /* init system clock / 82 bl system_clock_init 84 / Memory initialize / 85 bl mem_ctrl_asm_init 88 / *for UART */

89 bl uart_asm_init 90 bl tzpc_init 91 pop {pc} 初始化話 時鐘 初始化 內存 初始化串口 找 _main 在start.s ctrl +]了 _main 選擇了第一個arm平臺 相關的 .s內 找到了真正的main 98 /* 99 * Set up initial C runtime environment and callboard_init_f(0). */ 初始化 c運行的環境 166 /* call board_init_r / 167 ldr pc, =board_init_r / this is auto-relocated! */

 

調用了 board_init_r arch/arm/lib/board.c 板級相關的信息

運行在43e00000 不行的緣由

涉及到一個 trustzone

 讓u-boot 起來 屏蔽掉 tsz lowlevel_init.s (58那個) 

 

88 /* for UART */ 
89 bl uart_asm_init
90 // bl tzpc_init 
91 pop {pc}

 

 

 

三星的真實

Exynos 4412 SCP has 64 KB ROM (iROM) and 256 KB SRAM (iRAM) as internal memory.

內置 64k的只讀存儲器 irom 256k 內存 iram

The boot loader is comprises the first and the second boot loaders. The characteristics of these boot loaders are:  iROM: It is a small and simple code to initiate SOC. It is implemented on internal ROM of SOC.  First boot loader (BL1): It is chip-specific and stored in external memory device.  Second boot loader (BL2): It is platform-specific and stored in external memory device. User should build and store this in an external memory device. It is not provided by Samsung

三星管 內部的 iROM 和 啓動代碼第一段 BL1 芯片相關

無論 BL2 平臺相關

 iROM is placed in internal 64 KB ROM. It initializes basic system functions such as clock and stack.  iROM loads BL1 image from a specific booting device to internal 256 KB SRAM. The booting device is selected by Operating Mode (OM) pins. According to the secure boot key values, iROM may do an integrity check on BL1 image.  BL1 initializes system clock, and DRAM controller. After initializing DRAM controller, it loads OS image from the booting device to DRAM. According to the secure boot key values, BL1 can do an integrity check on the OS image.  After the booting completes, BL1 jumps to the operating system.

 

系統移植第三天

【1】u-boot

(1)uboot 是bootloader的一種

(2)uboot 做用: 初始化硬件,引導內核啓動,給內核傳參

(3)【面試題】你所使用的uboot的啓動流程

宏觀: 上電以後,4412內的irom代碼(固化代碼,無源碼 bl0)將啓動,從OM開關選擇從 emmc或者sd卡啓動; 接下來 將從只讀存儲器(emmc)讀取 bl1(加載,驗證,解密)到iram, 運行bl1,bl1會去讀取 bl2(14k是u-boot.bin的一部分)到iram;最後再加載 u-boot.bin到內存(dram)有時候,又稱之爲 bl3。

具體:分兩個階段: 第一段: 初始化異常向量表 關中斷 關mmu 初始化系統時鐘 初始化內存 初始化串口 清bss段

第二階段: 進一步初始化外圍設備

u-boot的網卡移植

使用srom的方式 掛載了 dm9000;只要uboot階段 能識別網卡 就能使用 ping 等命令

自制u-boot 出現錯誤:
ORIGEN # ping 192.168.2.250 Unknown command 'ping' - try 'help'
思考:
(1)common的目錄 然而並無  cmd_ping的源碼  
(2)grep "ping" * -n 看不出來 經過百度 找到 do_ping
  vi -t do_ping 找到函數描述
 276 #if defined(CONFIG_CMD_PING)
說明 該函數 依賴於 
 defined(CONFIG_CMD_PING)
經過追蹤 宏 發現定義位置 都在板子的頭文件裏
1 vsp ./include/configs/fs4412.h 2 85 #undef CONFIG_CMD_PING  
85 #undef CONFIG_CMD_PING  發現須要 改爲 #define 從新 編譯 (clean config make)
獲得一對錯誤
error:/home/linux/u-boot-2013.01/net/ping.c:69: undefined reference to `eth_halt'
說明其餘位置也要打開某些 宏的定義
90 #undef CONFIG_CMD_NET
修改爲define
緣由:網卡沒初始化,或者設置呢
vi /arch/arm/lib/board.c  
(看到不少外設的初始化信息函數)
665 #if defined(CONFIG_CMD_NET)
666     puts("Net: "); 667     eth_initialize(gd->bd); 668 #if defined(CONFIG_RESET_PHY_R)
669     debug("Reset Ethernet PHY\n"); 670 reset_phy(); 671 #endif
==》 board_eth_init  板子初始化 網卡
vi -t 發現  跟板子相關  origen
發現跟三星的其餘板子都有 ,咱本身的沒有
進入 2410 看一眼
133
134 #ifdef CONFIG_CMD_NET 135 int board_eth_init(bd_t *bis) 136 { 137     int rc = 0; 138 #ifdef CONFIG_CS8900 139     rc = cs8900_initialize(0, CONFIG_CS8900_BASE); 140 #endif
141     return rc; 142 } 143 #endif
意思就是說咱本身要定義一個  函數 fs4412內 定義這個相似的函數 咱們在 board/samsung/origen/origen.c 內 依葫蘆畫瓢
110 int board_eth_init(bd_t *bis) 111 { 112     int rc = 0; 113
114     rc = dm9000_initialize(bis); 115
116     return rc; 117 } #endif
/home/linux/u-boot-2013.01/board/samsung/origen/origen.c:114: undefined reference to `dm9000_initialize'
說沒定義這個初始化的 函數 設備驅動有關係
追 cs8900_initialize 看到了這個東西在 driver下面的 net下面
思考:在dm9000下應該有吧
626 int dm9000_initialize(bd_t *bis) 627 { 628     struct eth_device *dev = &(dm9000_info.netdev); 629
630     /* Load MAC address from EEPROM */
631 dm9000_get_enetaddr(dev); 632
633     dev->init = dm9000_init; 634     dev->halt = dm9000_halt; 635     dev->send = dm9000_send; 636     dev->recv = dm9000_rx; 637     sprintf(dev->name, "dm9000"); 638
639 eth_register(dev); 640
641     return 0; 642 } 
明明有定義 未找到  
         --》 Makefile 或者 .h的鍋
在 driver/net/Makefile
38 COBJS-$(CONFIG_DRIVER_DM9000) += dm9000x.o    
也就是說要想正常編譯 
          必須定義  CONFIG_DRIVER_DM9000
          在 fs4412.h 倒數第二行 定義 CONFIG_DRIVER_DM9000
#define CONFIG_DRIVER_DM9000
從新編譯 又是一堆  
 dm9000x.c: In function 'dm9000_outblk_8bit':
 思考: 網卡驅動有了,網卡在哪一個引腳上?
    vi -t DM9000_DATA  宏 發現別人的板子有定義 參考 隨便找了一個發現 別人有定義宏
80 #define CONFIG_DM9000_BASE      0x2c000000
81 #define DM9000_IO           CONFIG_DM9000_BASE
82 #define DM9000_DATA         (CONFIG_DM9000_BASE + 0x400)
83 #define CONFIG_DM9000_USE_16BIT     1
84 #define CONFIG_DM9000_NO_SROM       1
85 #undef  CONFIG_DM9000_DEBUG
得看芯片手冊了:原理圖上的 cs  片選  --》 BUF_Xm0cs1
 
官方手冊  19 SROM Controller 章節 有關於這部分的地址
      nGCS[3:0] Output Bank selection signal Xm0CSn_x muxed
    找到 nGCS[3:0] Xm0CSn_x
        ---》
            0x0500_0000 0x0600_0000 16 MB Bank1 of SMC
#define CONFIG_DM9000_BASE      0x5000000
#define DM9000_IO           CONFIG_DM9000_BASE
#define DM9000_DATA         (CONFIG_DM9000_BASE + 4)
再到 fs4412.h 內追加
再編譯,上板子
ping 192.168.2.200
第一個error 沒設置 ipaddr setenv ipaddr IP地址便可 第二個error 沒 ethaddr setenv ethaddr 00:01:02:03:04:05
MAC地址要設置  12個16進制數 第一個字節最好爲0
 

【2】kernel

www.kernel.org

目錄結構

arch 平臺相關 其餘的 平臺無關: 驅動 工具 頭文件,文檔

(0) make mrproper
清潔代碼 ,好比換平臺
make mrproper
 CLEAN   scripts/basic
 CLEAN   scripts/kconfig
 CLEAN   include/config include/generate
(1)交叉編譯器 Makefile
198 ARCH        ?= $(SUBARCH) 199 CROSS_COMPILE   ?= $(CONFIG_CROSS_COMPILE:"%"=%) 改爲 -------> ARCH ?= arm CROSS_COMPILE ?= arm-none-linux-gnueabi-
(2)exynos 是咱們的默認配置 make exynos_config  找不到
  本質 :
cp ./arch/arm/configs/exynos_defconfig ./.config
  (3)  
make menuconfig
退出要選 yes
"make config"      Plain text interface. 文本對話
"make menuconfig"  Text based color menus, radiolists & dialogs. 基於文本,彩色菜單 選擇等
  "make nconfig"     Enhanced text based color menus.
 "make xconfig"     X windows (Qt) based configuration tool.
 "make gconfig"     X windows (Gtk) based configuration tool. 圖形界面
(4)
 make uImage -j(cpu個數)
(5)
sudo cp ./arch/arm/boot/uImage /tftboot/ VFS: Cannot open root device "nfs" or unknown-block(0,255): error -6 vi -t EAGAIN 9 #define ENXIO        6  /* No such device or address */

注意: 須要安裝兩個包

libncurses5-dev (關係到 menuconfig的圖形界面)

sudo apt-get install uboot-mkimage uboot-mkimage(關係到uImage的格式)

make menuconfig 窗口不能過小

 

系統移植第四天

內核移植

根據本身的硬件,修改配置,生成對應的內核鏡像

目錄

平臺相關: arch cpu平臺的支持

其餘重要的目錄:

【很是具備參考價值-- 內核man手冊】Documentation

【驅動參考寶典】driver 包含 驅動源碼 和 Makefile

例如:

linux-3.14/drivers/usb/serial 目錄下有 ch341.c 而同目錄的Makefile有

16 obj-$(CONFIG_USB_SERIAL_CH341)          += ch341.o

本質: ch341將會編譯生成 ch341.o 最後加入到 內核鏡像內

同目錄內 有一個 Kconfig(菜單)

99 config USB_SERIAL_CH341 100     tristate "USB Winchiphead CH341 Single Port Serial Driver"
101 help 102       Say Y here if you want to use a Winchiphead CH341 single port 103 USB to serial adapter. 104
105       To compile this driver as a module, choose M here: the 106       module will be called ch341.

tristate state 狀態 tri- 三個 是,否,模塊

對應的右bool 是仍是否

–》 從新編譯內核

(1)make mrproper

(2)修改Makefile arm arm-none-linux-gnueabi- 注意末尾不要加空格

(3)拷貝 cp ./arh/arm/configs/exynos-defconfig ./.config

  (4) make menuconfig 退出選yes

.config 被修改了

.config 給 Makefile 是用來生成 uImage的菜譜以及注意事項

(5)make uImage -j8 (8是核心數)

生成的文件 uImage 在 arch/arm/boot/uImage

生成過程:

OBJCOPY arch/arm/boot/zImage Kernel: arch/arm/boot/zImage is ready UIMAGE arch/arm/boot/uImage Image Name: Linux-3.14.0 Created: Mon Sep 10 09:44:30 2018 Image Type: ARM Linux Kernel Image (uncompressed) Data Size: 2756512 Bytes = 2691.91 kB = 2.63 MB Load Address: 40008000 Entry Point: 40008000

分析得出

Image --》 zImage --》 uImage

壓縮的zImage 再加64k的頭信息 得 uImage

命令 查看uImage的頭信息

mkimage -l ./uImage Image Name: Linux-3.14.0 Created: Mon Sep 10 09:44:30 2018 Image Type: ARM Linux Kernel Image (uncompressed)未壓縮 Data Size: 2756512 Bytes = 2691.91 kB = 2.63 MB Load Address: 40008000 Entry Point: 40008000

設備樹生成

?設備樹

什麼是設備樹

目的:硬件信息與驅動剝離 詳細請見驅動部分 make dtbs

 DTC     arch/arm/boot/dts/exynos4210-origen.dtb DTC arch/arm/boot/dts/exynos4210-smdkv310.dtb DTC arch/arm/boot/dts/exynos4210-trats.dtb DTC arch/arm/boot/dts/exynos4210-universal_c210.dtb DTC arch/arm/boot/dts/exynos4412-odroidx.dtb DTC arch/arm/boot/dts/exynos4412-origen.dtb DTC arch/arm/boot/dts/exynos4412-smdk4412.dtb DTC arch/arm/boot/dts/exynos4412-tiny4412.dtb DTC arch/arm/boot/dts/exynos4412-trats2.dtb DTC arch/arm/boot/dts/exynos5250-arndale.dtb DTC arch/arm/boot/dts/exynos5250-smdk5250.dtb DTC arch/arm/boot/dts/exynos5250-snow.dtb DTC arch/arm/boot/dts/exynos5420-arndale-octa.dtb DTC arch/arm/boot/dts/exynos5420-smdk5420.dtb DTC arch/arm/boot/dts/exynos5440-sd5v1.dtb DTC arch/arm/boot/dts/exynos5440-ssdk5440.dtb

dtc 是 device tree complier 編譯器 設備樹編譯器 拿源碼 dts source 生成 dtb bin

爲啥沒有咱們的fs4412呢?

  進去找 先複製 exynos4412-origen.dts exynos4412-fs4412.dts

    在頂層目錄 make dtbs 依然沒現象

      誰的鍋? dts 目錄下Makefile的問題

vi 這個Makefile 匹配origen 發現沒有 +=fs4412 64 dtb-$(CONFIG_ARCH_EXYNOS) += exynos4210-origen.dtb \ 65     exynos4210-smdkv310.dtb \ 66     exynos4210-trats.dtb \ 67     exynos4210-universal_c210.dtb \ 68     exynos4412-odroidx.dtb \ 69     exynos4412-origen.dtb \ 70     exynos4412-smdk4412.dtb \ 71     exynos4412-tiny4412.dtb \ 72     exynos4412-trats2.dtb \ 73     exynos5250-arndale.dtb \ 74     exynos5250-smdk5250.dtb \ 75     exynos5250-snow.dtb \ 76     exynos5420-arndale-octa.dtb \ 77     exynos5420-smdk5420.dtb \
複製 origen 一行 改爲 fs4412 69     exynos4412-origen.dtb \ 70     exynos4412-fs4412.dtb \

再回頂層目錄

make dtbs
  DTC     arch/arm/boot/dts/exynos4412-fs4412.dtb

----->生成成功

sudo cp uImage 和設備樹到板子運行看看

--------> 發現板子掛了

開始不從 Makefile 和 .config着手 從菜單開始考慮

Linux/arm 3.14.0 Kernel Configuration ──────────────────────────────┐
 │ Arrow keys navigate the menu. <Enter> selects submenus ---> (or empty submenus ----). │ │ Highlighted letters are hotkeys. Pressing <Y> includes, <N> excludes, <M> modularizes features. │ │ Press <Esc><Esc> to exit, <?> for Help, </> for Search.  Legend: [*] built-in [ ] excluded │ │ <M> module  < > module capable      

 

y 選中 n 不選 m 是模塊

?幫助 esc esc 退出 選擇yes 則保存到 .config

/ 查找

咱們在 make menuconfig的時候

------>在 device driver –》 character device 查到的東西 來自於目錄 ./driver/char/Kconfig

8 config XIEYUXING 9     bool "XIEYUXING device support"
10 help 11       Say Y here if you want to support the xieyuxing 12       When in doubt, say "N".

重新make menuconfig 在原位置看到

  [ ] XIEYUXING device support (NEW)   

[] 表明雙選 Y or N --》 bool

若是咱們 輸入' /'匹配 XIEYUXING 則查到
Symbol: XIEYUXING [=n] │ Type : boolean │ Prompt: XIEYUXING device support │ Location: │ -> Device Drivers │ (1)   -> Character devices │ Defined at drivers/char/Kconfig:8 

----------->

esc 退出保存後 查看頂層目錄的 .config
1118 # Character devices 1119 # 1120 CONFIG_XIEYUXING=y  

再去 driver/cha/Makefile 查看沒有 xxx匹配的規則,說明咱們要本身加

obj-$(CONFIG_XIEYUXING)    += xxxx.o

在同目錄內 編寫 xxx.c

---->再回到頂層目錄

make uImage顯示 CHK include/config/kernel.release CHK include/generated/uapi/linux/version.h CHK include/generated/utsrelease.h make[1]: `include/generated/mach-types.h' is up to date.
CALL    scripts/checksyscalls.sh CHK include/generated/compile.h CC drivers/char/xieyuxing.o drivers/char/xieyuxing.c:1:19: fatal error: stdio.h: No such file or directory compilation terminated. make[2]: *** [drivers/char/xieyuxing.o] Error 1 make[1]: *** [drivers/char] Error 2 make[1]: *** Waiting for unfinished jobs.... make: *** [drivers] Error 2 make: *** Waiting for unfinished jobs.... CC drivers/char/xxx.o

說明咱們想添加驅動的目的達到了若是咱們把char目錄下Kconfig的bool修改爲 tristate進入 make menuconfig 選m 則頂層目錄的 .config

1120 CONFIG_XIEYUXING=m

完成配置 內核 和設備樹 實現第一天的效果

緣由: 目前掛板子不成功的緣由

(1)uImage 沒有配置徹底 網卡驅動? nfs支持?

(2)設備樹? 有沒有dm9000的配置?

[1] dm9000

find -name dm9000.c  ./drivers/net/ethernet/davicom/dm9000.c
vi davicom下面的Makefile
有:
5 obj-$(CONFIG_DM9000) += dm9000.o
再去找  頂層目錄下 找CONFIG_DM9000
894 # CONFIG_DM9000 is not set
--------->說明咱們要去 設置
      make menuconfig 配置就能夠了
  在 裏面輸入 /查找 DM9000
894 # CONFIG_DM9000 is not set
Symbol: DM9000 [=n] │ Type : tristate │ Prompt: DM9000 support │ Location: │ -> Device Drivers │ -> Network device support (NETDEVICES [=y]) │ (1)     -> Ethernet driver support (ETHERNET [=y]) │ Defined at drivers/net/ethernet/davicom/Kconfig:5 │ Depends on: NETDEVICES [=y] && ETHERNET [=y] && (ARM [=y] || BLACKFIN || MIPS || COLDFIRE) │ Selects: CRC32 [=y] && MII [=y]  

 

  按照方法去打開每個 選項 再拷貝 再運行 錯誤以下:
[    1.435000] VFS: Cannot open root device "nfs" or unknown-block(0,255): error -6 [ 1.440000] Please append a correct "root=" boot option; here are the available partitions: [ 1.450000] Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(0,255)
  錯誤中提示 : NFS未配置,rootfs?

網上資料不少 ,可是如何本身思考配置 更多要藉助 "/"做用

root --> Symbol: ROOT_NFS [=n] │ Type : boolean │ Prompt: Root file system on NFS │ Location: │ -> File systems │ (3)   -> Network File Systems (NETWORK_FILESYSTEMS [=y]) │ Defined at fs/nfs/Kconfig:159 │ Depends on: NETWORK_FILESYSTEMS [=y] && NFS_FS [=n]=y && IP_PNP [=n]     

然而咱們找不到"Root file system on NFS" 咱們在依賴上卻 IP_PNP 找 IP_PNP

│ Symbol: IP_PNP [=n] │ Type : boolean │ Prompt: IP: kernel level autoconfiguration │ Location: │ -> Networking support (NET [=y]) │ -> Networking options │ (1)     -> TCP/IP networking (INET [=y]) │ Defined at net/ipv4/Kconfig:107 │ Depends on: NET [=y] && INET [=y]     

選上 kernel level autoconfiguration便可

--------->找 NFS_FS

Symbol: NFS_FS [=n] │ Type : tristate │ Prompt: NFS client support │ Location: │ -> File systems │ (1)   -> Network File Systems (NETWORK_FILESYSTEMS [=y]) │ Defined at fs/nfs/Kconfig:1 │ Depends on: NETWORK_FILESYSTEMS [=y] && INET [=y] && FILE_LOCKING [=y] │ Selects: LOCKD [=n] && SUNRPC [=n] && NFS_ACL_SUPPORT [=n] 

 

配置好後 還有 NFS_ACL_SUPPORT沒有
又依賴
NFS_V3_ACL [=n] || NFSD [=n] Symbol: NFS_V3_ACL [=n] │ Type : boolean │ Prompt: NFS client support for the NFSv3 ACL protocol extension │ Location: │ -> File systems │ -> Network File Systems (NETWORK_FILESYSTEMS [=y]) │ -> NFS client support (NFS_FS [=y]) │ (2)       -> NFS client support for NFS version 3 (NFS_V3 [=y]) │ Defined at fs/nfs/Kconfig:52 │ Depends on: NETWORK_FILESYSTEMS [=y] && NFS_V3 [=y]      
下面是百度上的資料: 進入[*] Networking support  ---> Networking options ---> 選中[*] IP: kernel level autoconfiguration 再進入File systems ---> [*] Network File Systems  ---> 選中以下選項: <*> NFS client support <*>     NFS client support for NFS version 2
 
                                   <*>     NFS client support for NFS version 3 [*]       NFS client support for the NFSv3 ACL protocol extension <*>     NFS client support for NFS version 4 [*] Provide swap over NFS support [*]   NFS client support for NFSv4.1 [*]     NFS client support for NFSv4.2 [*]     NFSv4.1 client support for migration [*]   Root file system on NFS

 

設備樹

描述板子的硬件信息 分離設備信息 和驅動

19     model = "Insignal Origen evaluation board based on Exynos4412";
20     compatible = "insignal,origen4412", "samsung,exynos4412";
 

compatible 用於驅動和設備樹匹配的子節點:

 22     memory {
 23         reg = <0x40000000 0x40000000>;
 24     };

內存地址 地址信息 <1,2> 1:起始地址 2:偏移大小

咱們如何添加 dm9000的信息 到 設備樹(dts)裏面去呢 ?

(1) 百度 必然要找 fs4412相關的信息 :

dm9000具體怎麼設置 ,每一家板子商的寄存器地址都不同

(2) Documentation 找找看?? 配設備樹,-dm9000有關係 猜一下路徑

linux-3.14/Documentation/devicetree/bindings/net/ davicom-dm9000.txt
 

查看

 1Davicom DM9000 Fast Ethernet controller
 2
 3 Required properties:
 4 - compatible = "davicom,dm9000";
 5 - reg : physical addresses and sizes of registers, must contain 2 entries:
 6     first entry : address register,
 7     second entry : data register.
 8 - interrupt-parent : interrupt controller to which the device is connected
 9 - interrupts : interrupt specifier specific to interrupt controller
10
11 Optional properties:
12 - local-mac-address : A bytestring of 6 bytes specifying Ethernet MAC address
13     to use (from firmware or bootloader)
14 - davicom,no-eeprom : Configuration EEPROM is not available
15 - davicom,ext-phy : Use external PHY
16
17 Example:
18
19     ethernet@18000000 {
20         compatible = "davicom,dm9000";
21         reg = <0x18000000 0x2 0x18000004 0x2>;
22         interrupt-parent = <&gpn>;
23         interrupts = <7 4>;
24         local-mac-address = [00 00 de ad be ef];
25         davicom,no-eeprom;
26     };

  

手冊建議咱們要改

ethernet@18000000  名字上的地址也要改
21         reg = <0x18000000 0x2 0x18000004 0x2>;
22         interrupt-parent = <&gpn>;
23         interrupts = <7 4>;

(1)咱們要修改寄存器 Bank1 of SMC 片選 cs 1 找到 0x5000000 6個零

地址寄存器:0x5000000 數據寄存器:0x5000004 reg = <0x5000000 0x2 0x5000004 0x2>;

(2) 找中斷源 INT 找到 DM9000_IRQ 找到 XEINT6

找到了 GPX0_6 估算 中斷父節點 是 gpx0

(3)設置中斷值 不太清楚 再去參考別人的

16 #include 「exynos4412.dtsi」 參考 linux-3.14/Documentation/devicetree/bindings/interrupt-controller/interrupts.txt 13 Example: 14     interrupt-parent = <&intc1>; 15     interrupts = <5 0>, <6 0>; 69 b) two cells 70   ------------
  71   The #interrupt-cells property is set to 2 and the first cell defines the 72   index of the interrupt within the controller, while the second cell is used 73 to specify any of the following flags: 74     - bits[3:0] trigger type and level flags 75         1 = low-to-high edge triggered 76         2 = high-to-low edge triggered 77         4 = active high level-sensitive 78         8 = active low level-sensitive 
找到兩個值怎麼填  第幾組 <6 4>

修改完以後重新生成

22     ethernet@5000000 { 23         compatible = "davicom,dm9000"; 24         reg = <0x5000000 0x2 0x5000004 0x2>; 25         interrupt-parent = <&gpx0>; 26         interrupts = <6 4>; 27         local-mac-address = [00 00 de ad be ef]; 28         davicom,no-eeprom; 29     };

------->而後

make dtbs
  DTC     arch/arm/boot/dts/exynos4412-fs4412.dtb sudo cp arch/arm/boot/uImage  /tftpboot/ sudo cp arch/arm/boot/dts/exynos4412-fs4412.dtb /tftpboot/

 

在 driver/clk/clk.code
529 static bool clk_ignore_unused;
修改成 static bool clk_ignore_unused=true;

-------->最後再 make uImage 拷貝到 /tftpboot 下

 

系統移植第五天

攝像頭移植

(1)內核中的攝像頭驅動 zc3xx 中星微

find . -name zc3xx.c ./drivers/media/usb/gspca/zc3xx.c

 

make menuconfig

 

 

 

┌───────────────────────────────────────── Search Results ──────────────────────────────────────────┐

│ Symbol: USB_GSPCA_ZC3XX [=n]                                                                      
│ Type  : tristate                                                                                  
│ Prompt: ZC3XX USB Camera Driver                                                                   
│   Location:                                                                                       
│     -> Device Drivers                                                                             
│ (1)   -> Multimedia support (MEDIA_SUPPORT [=n])                                                  
│         -> Media USB Adapters (MEDIA_USB_SUPPORT [=n])                                            
│           -> GSPCA based webcams (USB_GSPCA [=n])                                                 
│   Defined at drivers/media/usb/gspca/Kconfig:425                                                  
│   Depends on: USB [=y] && MEDIA_SUPPORT [=n] && MEDIA_USB_SUPPORT [=n] && MEDIA_CAMERA_SUPPORT [= n
 

 

發現最後一項gspca based 沒這個菜單

Symbol: USB_GSPCA [=n]                                                                                                                                                  
 │ Type  : tristate                                                                                                                                                        
 │ Prompt: GSPCA based webcams                                                                                                                                             
 │   Location:                                                                                                                                                             
 │     -> Device Drivers                                                                                                                                                   
 │       -> Multimedia support (MEDIA_SUPPORT [=y])                                                                                                                        
 │ (1)     -> Media USB Adapters (MEDIA_USB_SUPPORT [=y])                                                                                                                  
 │   Defined at drivers/media/usb/gspca/Kconfig:1                                                                                                                          
 │   Depends on: USB [=y] && MEDIA_SUPPORT [=y] && MEDIA_USB_SUPPORT [=y] && MEDIA_CAMERA_SUPPORT [=n] && VIDEO_V4L2 [=n]           

 

  找到 meida_camera_support
Symbol: MEDIA_CAMERA_SUPPORT [=n] │ Type : boolean │ Prompt: Cameras/video grabbers support │ Location: │ -> Device Drivers │ (1)   -> Multimedia support (MEDIA_SUPPORT [=y]) │ Defined at drivers/media/Kconfig:21 │ Depends on: MEDIA_SUPPORT [=y]  

 

          

(2)設備樹

–》 配置usb的設備樹 –》從新dtc生成 設備樹文件 具體參考《系統移植實驗手冊》

然而板子沒起來

usb支持 和 攝像頭的一個UVC配置

make menuconfig
Device Drivers  ---> [*] USB support  --->
<*>     EHCI HCD (USB 2.0) support <*>     EHCI support for Samsung S5P/EXYNOS SoC Series <*> USB Mass Storage support <*> USB3503 HSIC to USB20 Driver USB Physical Layer drivers --->
<*> Samsung USB 2.0 PHY controller Driver SCSI device support --->
<*> SCSI device support <*> SCSI disk support <*> SCSI generic support

 

菜單:
Device Drivers
-》Multimedia support -》Media USB Adapters --- Media USB Adapters │ │ │ │ *** Webcam devices *** │ │ │ │ <*> USB Video Class (UVC) │ │ │ │ [*]     UVC input events device support     

 

       

驗證結果:

ls /dev/video0 說明成功

 

根文件系統 (rootfs)

1.容易混淆的概念

文件系統 : 虛擬文件系統 (VFS)

磁盤文件系統: fat fat32 ntfs 根文件系統: 操做系統鎖必須的 工具,庫,目錄等。

概念:根文件系統(root filesystem)是存放運行、維護系統所必須的各類工具軟件、庫文件、腳本、配置文件和其餘特殊文件的地方,也能夠安裝各類軟件包

實質 --》 rootfs.tar.gz

busybox的做用:生成 目標機的rootfs

目的原因: 嵌入式設備廣泛存儲器不大,功能單一;

信念: 只用 20%的代碼 實現 80%的功能

移植rootfs

busybox

(1) tar xvf busybox (2) cd (3) make menuconfig

(4) 修改交叉編譯器

Location:                                                                                          │
 │     -> Busybox Settings                                                                │
 │       -> Build Options     
BusyBox 1.22.1 Configuration

 

進入輸入 而後tab到ok上保存
(arm-none-linux-gnueabi-) Cross Compiler prefix
(5) make
(6) make install
 
結果:
linux@ubuntu:~/busybox-1.22.1$ cd _install/ linux@ubuntu:~/busybox-1.22.1/_install$ ls bin linuxrc sbin usr

 

  比較目錄,沒有的在_install內加
bin linuxrc sbin usr bin dev etc lib linuxrc mjpg mnt proc root sbin sys tmp usr var www mkdir dev etc lib mnt proc root sys tmp var

 

回到頂層,而後更改_install目錄名

mv ./_install  rootfs

 

 
給之前的備份一下:  
mv /source/rootfs backup_rootfs mv ./rootfs /source/
出現錯誤 Failed to execute /linuxrc (error -2).

缺乏依賴庫,交叉編譯器裏有

cp  -arf ~/gcc-4.6.4/arm-arm1176jzfssf-linux-gnueabi/lib/* /source/rootfs/lib/

能掛載 又出錯誤 :缺乏文件夾

can’t run ‘/etc/init.d/rcS’: No such file or directory

 

cd /source/rootfs/etc/ mkdir init.d touch rcS

又有 can’t run ‘/etc/init.d/rcS’: Permission denied

  給權限------------->chmod 77 /source/rootfs/etc/init.d/rcS

移植sqlite3

想法?

x86 : dpkg -i *deb
 
 sudo apt-get install libsqlite3-dev sqlite3 libsqlite3-0

sqlite3 是執行軟件 libsqlite3 是執行庫 libsqlite3-dev 含頭文件的

沒有arm格式,須要移植arm格式的

(1)下載 https://www.sqlite.org/2018/sqlite-autoconf-3240000.tar.gz
2)上傳到虛擬機 解壓縮    tar xvf + 源碼包 (3) 進入目錄 ./configure --host=arm-none-linux-gnueabi --prefix=/home/linux/sqlite-arm 前面的是交叉編譯器 後面的是結果生成的目錄 (3)vi Makefile 修改一個 -DPACKAGE_STRING=\"sqlite\ 3.24.0\"3.24.0 前面的 '\'和空格刪掉
4)make (5)make install (6)拷貝 sqlite-arm下的bin下的sqlite3 到板子上去 板子上電 執行sqlite 是能夠的 (7) sqlite-arm 下的 lib的庫 拷貝過去 給 程序用 sudo cp libsqlite3.so.0.8.6  /source/rootfs/lib/ 庫的軟連接 名字叫 libsqlite3.so.0 cd /source/rootfs/lib ln -s libsqlite3.so.0.8.6  libsqlite3.so.0 測試: arm-none-linux-gnueabi-gcc sqlite_test.c -lsqlite3 sqlite_test.c:6:21: fatal error: sqlite3.h: No such file or directory compilation terminated. 找不到頭文件 -I 頭文件位置 -L 動態庫位置 arm-none-linux-gnueabi-gcc sqlite_test.c -lsqlite3 -I /home/linux/sqlite-arm/include/ -L /home/linux/sqlite-arm/lib/
相關文章
相關標籤/搜索