系統移植第一天php
以應用爲中心、以計算機技術爲基礎、軟件硬件可裁剪、適應應用系統,對功能、可靠性、成本、體積、功耗嚴格要求的專用計算機系統。css
馮諾依曼結構: 控制器,運算器,輸入,輸出, 存儲器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
應用–》 驅動–》硬件 stm32中 寫程序 調用驅動程序 控制硬件web
應用程序 --》 系統調用–》 內核 --》 驅動–》硬件面試
將一些功能 搬移到 指定的硬件平臺上去
(1) 交叉編譯器 cross - complier (2) 啓動引導程序 BootLoader (3) 內核(linux操做系統)kernel (4) 根文件系統 rootfs
(5)應用程序
bios --》BootLoader bios: basic input output system bios --> uefi t通用外部固件接口
上電的第一段代碼 : 初始化,檢查硬件–》 引導系統–》 給系統傳參
好比咱們的電腦 能夠選擇 硬盤,光驅,優盤,網絡(無盤工做站)來裝系統或者運行系統
內核–》 操做系統內核 (windows NT)
根文件系統 --》 c盤的文件,功能性的,非操做系統的
BootLoader 鬧鐘,媽
kernel 靈魂
rootfs 肉體,器官
通常整個工程項目開始前,交叉編譯器必須定下來,後期不會作較大更改
gcc(本平臺生成本平臺目標機代碼)
x86 —》 x86 程序
cross 交叉(本平臺實現 目標機爲arm 的代碼)
x86 —》 arm 程序
通常狀況下,包含在硬件廠商提供的 板級支持包內 (BSP board support package)
編譯器提供網站下載 https://www.linaro.org/latest/downloads/
arm 嵌入式設備 交叉編譯器提供組織
也能夠本身製做
crosstool-ng 工具 能夠生成 交叉編譯器
-h 顯示 elf 頭部信息
-s 顯示段信息
計算各個段的大小
顯示符號
刪除符號 --》 精簡文件 --》嵌入式必須
反彙編 -D
拷貝或轉換 目標文件 拷貝二進制 -O binary 注: 大寫O
BootLoader: 自己在 板子的emmc內部 已燒寫完畢
內核文件 uImage 是經過tftp傳輸到內存地址的 exyons4412-fs4412.dtb 設備樹文件 也是tftp
根文件系統 /rootfs是經過 nfs的方式 遠程同步的(掛載)
tftp 簡單文件傳輸協議 udp
重啓大法:
nfs 網絡文件系統 (無盤工做站)
先在設備管理器裏面看一下端口是幾 putty 選 serial 波特率 115200 com幾寫好 左下角流控制設置爲 none 保存
注意撥碼開關
011x 是emmc上啓動 uboot 100x 是sd卡 啓動uboot
上電 敲任意鍵暫停
若是bootcmd內有內容 則會倒計時等待 不敲任意鍵則會執行 bootcmd
顯示 uboot支持的命令 (不是linux的)
(1)help + 命令 相似於man的做用
(2)printenv 打印全部的環境信息
(3)setenv
setenv + 變量名 + 值 則設置這個值 只加變量名 則清空這個值
(4)saveenv
(5) md
memory display 顯示內存的內容
md + 地址(16進制) (6)mm nm6 mm 修改後自增地址 (要算) nm 修改後 地址不變
設置板子和Ubuntu的 ip地址
建議 Ubuntu 設置爲 192.168.2.200 右上角標記 新建一個 取名叫board 填入 192.168.2.200 255.255.255.0 192.168.2.1 保存
bootcmd 能夠 將連續的操做保存着,若是bootcmd 不是缺省 則 延時會啓用
此時完成上面操做會出錯
VFS: Cannot open root device 「(null)」 or unknown-block(0,0):
還差 nfs 根文件系統沒掛上
bootargs 須要設置 bootargs 實際上是 uboot給內核的傳參
bootargs 幾個要素: (1) root=?什麼類型 nand啓動 仍是emmc啓動 仍是其餘網絡啓動呢??
(2)nfsroot 在哪裏? nfsroot=ip:/路徑 讀寫
設置前缺認在不在這個目錄
(3) 第一個啓動的程序是誰
(4) 從哪裏顯示
(5) 板子的ip地址
(4)和(5)的緣由是 uboot完成啓動內核後,結束了工做,不存在了,因此串口輸出 和 ip地址須要經過傳參的方式發給內核
rm: can’t remove ‘hehe’: Permission denied
sudo chmod 777 /source/rootfs
做業:
掛板子成功,編譯一個helloworld 在板子上運行
(面試)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 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 操做: 4 (1)make clean 5 (2)make fs4412_config 6 (3)make
生成了三個文件: u-boot.bin 二進制 u-boot.lds 連接腳本 u-boot.map
三星支持 u-boot.bin的格式
sudo cp ./u-boot.bin /tftpboot
1 tftp 41000000 u-boot.bin 2 go 41000000
加載uboot失敗
(1) 地址不對 查看 u-boot.map 提示 _start地址在 0x43e00000 (三星定義)
(2)串口沒有設置過
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 板級相關的信息
涉及到一個 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)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段
第二階段: 進一步初始化外圍設備
使用srom的方式 掛載了 dm9000;只要uboot階段 能識別網卡 就能使用 ping 等命令
ORIGEN # ping 192.168.2.250 Unknown command 'ping' - try 'help'
276 #if defined(CONFIG_CMD_PING)
defined(CONFIG_CMD_PING)
1 vsp ./include/configs/fs4412.h 2 85 #undef CONFIG_CMD_PING
error:/home/linux/u-boot-2013.01/net/ping.c:69: undefined reference to `eth_halt'
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
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
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'
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 }
38 COBJS-$(CONFIG_DRIVER_DM9000) += dm9000x.o
#define CONFIG_DRIVER_DM9000
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
#define CONFIG_DM9000_BASE 0x5000000
#define DM9000_IO CONFIG_DM9000_BASE
#define DM9000_DATA (CONFIG_DM9000_BASE + 4)
第一個error 沒設置 ipaddr setenv ipaddr IP地址便可 第二個error 沒 ethaddr setenv ethaddr 00:01:02:03:04:05
arch 平臺相關 其餘的 平臺無關: 驅動 工具 頭文件,文檔等
make mrproper
198 ARCH ?= $(SUBARCH) 199 CROSS_COMPILE ?= $(CONFIG_CROSS_COMPILE:"%"=%) 改爲 -------> ARCH ?= arm CROSS_COMPILE ?= arm-none-linux-gnueabi-
cp ./arch/arm/configs/exynos_defconfig ./.config
make menuconfig
make uImage -j(cpu個數)
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 在原位置看到
[] 表明雙選 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 退出保存後 查看頂層目錄的 .config1118 # 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
緣由: 目前掛板子不成功的緣由
(1)uImage 沒有配置徹底 網卡驅動? nfs支持?
(2)設備樹? 有沒有dm9000的配置?
[1] dm9000
find -name dm9000.c ./drivers/net/ethernet/davicom/dm9000.c
5 obj-$(CONFIG_DM9000) += dm9000.o
894 # CONFIG_DM9000 is not set
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)
網上資料不少 ,可是如何本身思考配置 更多要藉助 "/"做用
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
描述板子的硬件信息 分離設備信息 和驅動
compatible 用於驅動和設備樹匹配的子節點:
內存地址 地址信息 <1,2> 1:起始地址 2:偏移大小
咱們如何添加 dm9000的信息 到 設備樹(dts)裏面去呢 ?
(1) 百度 必然要找 fs4412相關的信息 :
dm9000具體怎麼設置 ,每一家板子商的寄存器地址都不同
(2) Documentation 找找看?? 配設備樹,-dm9000有關係 猜一下路徑
查看
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 };
手冊建議咱們要改
(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
修改完以後重新生成
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/
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 說明成功
1.容易混淆的概念
文件系統 : 虛擬文件系統 (VFS)
磁盤文件系統: fat fat32 ntfs 根文件系統: 操做系統鎖必須的 工具,庫,目錄等。
概念:根文件系統(root filesystem)是存放運行、維護系統所必須的各類工具軟件、庫文件、腳本、配置文件和其餘特殊文件的地方,也能夠安裝各類軟件包
實質 --》 rootfs.tar.gz
busybox的做用:生成 目標機的rootfs
目的原因: 嵌入式設備廣泛存儲器不大,功能單一;
信念: 只用 20%的代碼 實現 80%的功能
busybox
(1) tar xvf busybox (2) cd (3) make menuconfig
(4) 修改交叉編譯器
Location: │ │ -> Busybox Settings │ │ -> Build Options BusyBox 1.22.1 Configuration
(arm-none-linux-gnueabi-) Cross Compiler prefix
linux@ubuntu:~/busybox-1.22.1$ cd _install/ linux@ubuntu:~/busybox-1.22.1/_install$ ls bin linuxrc sbin usr
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 是執行軟件 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/