知識
不管是網(wǎng)站,軟件還是小程序,都要直接或間接能為您產(chǎn)生價值,我們在追求其視覺表現(xiàn)的同時,更側(cè)重于功能的便捷,營銷的便利,運營的高效,讓網(wǎng)站成為營銷工具,讓軟件能切實提升企業(yè)內(nèi)部管理水平和效率。優(yōu)秀的程序為后期升級提供便捷的支持!
【嵌入式開發(fā)】嵌入式開發(fā)工具簡介(裸板調(diào)試示例|交叉
發(fā)表時間:2020-10-19
發(fā)布人:葵宇科技
瀏覽次數(shù):175
作者 : 韓曙亮
博客地址 : http://blog.csdn.net/shulianghan/article/details/42239705
參考博客 : 【嵌入式開辟】嵌入式 開辟情況 (長途登錄 | 文件共享 | NFS TFTP 辦事器 | 串口連接 | Win8.1 + RedHat Enterprise 6.3 + Vmware11)
開辟情況 :
-- 操作體系 : Vmware11 + RedHat6.3 企業(yè)版 + Win8.1;
-- 硬件 : OK-6410-A 開辟板, JLink;
一. 編譯并燒寫裸板法度榜樣示例
1. 設(shè)置交叉編譯對象
OK-6410-A 應(yīng)用 4.3.2 的交叉編譯對象鏈, 將交叉編譯對象鏈設(shè)置成 Ubuntu 的默認交叉編譯對象鏈;
安裝交叉編譯對象鏈 : 解壓 arm-linux-gcc-4.3.2.tgz 文件
-- 安裝敕令 : 應(yīng)用敕令 tar -xvzf arm-linux-gcc-4.3.2.tgz -C /, 因為 tgz 緊縮文件內(nèi)也是存在目次構(gòu)造, 解壓后, 交叉編譯對象鏈直接解壓到了 /usr/local/arm/4.3.2 目次;
-- 設(shè)備情況變量 : 情況變量在 /etc/profile 中設(shè)備, 在該文件中添加如下代碼 :
ARM_LINUX="/usr/local/arm/4.3.2/bin" export PATH=$PATH:$ARM_LINUX-- 使設(shè)備文件生效 : 履行 source /etc/profile 敕令, 該設(shè)備即可生效, 履行 arm-linux 按 tab 鍵 :
octopus@octopus:~$ arm-linux- arm-linux-addr2line arm-linux-c++filt arm-linux-gcc-4.3.2 arm-linux-gprof arm-linux-objdump arm-linux-sprite arm-linux-ar arm-linux-cpp arm-linux-gcov arm-linux-ld arm-linux-ranlib arm-linux-strings arm-linux-as arm-linux-g++ arm-linux-gdb arm-linux-nm arm-linux-readelf arm-linux-strip arm-linux-c++ arm-linux-gcc arm-linux-gdbtui arm-linux-objcopy arm-linux-size
2. 編譯代碼
(1) 代碼示例
代碼直接是開辟板的示例代碼:
-- led.S :
octopus@octopus:~/arm/01_code$ more led.S .text .globl _start #define VIC0_INT 0x71200000 #define VIC1_INT 0x71300000 _start: bl reset ldr pc, _undefined_instruction ldr pc, _software_interrupt ldr pc, _prefetch_abort ldr pc, _data_abort ldr pc, _not_used ldr pc, _irq ldr pc, _fiq _undefined_instruction:b . _software_interrupt:b . _prefetch_abort:b . _data_abort:b . _not_used:b . _irq:b . _fiq:b . reset: mrs r0,cpsr bic r0,r0,#0x1f orr r0,r0,#0xd3 msr cpsr,r0 bl set_peri_port bl disable_watchdog bl disable_irq bl init_led bl light_led halt: bl halt set_peri_port: @告訴cpu外設(shè)的地址 ldr r0, =0x70000000 orr r0, r0, #0x13 mcr p15,0,r0,c15,c2,4 mov pc, lr disable_watchdog: @封閉看門狗 ldr r0, =0x7E004000 mov r1, #0 str r1, [r0] @ str, store, mov pc, lr disable_irq: @樊籬中斷 ldr r1, =0x0 ldr r0, =VIC0_INT str r1, [r0] ldr r1, =0x0 ldr r0, =VIC1_INT str r1, [r0] mov pc, lr init_led: @設(shè)置GPN為輸出模式 ldr r1, =0x7F008820 ldr r0, =0x1111 str r0, [r1] mov pc, lr light_led: @點亮LED1 ldr r1, =0x7F008824 mov r0, #0xf str r0, [r1] mov r0,#0xe str r0,[r1] mov pc, lr-- led.lds :
octopus@octopus:~/arm/01_code$ more led.lds OUTPUT_FORMAT("elf32-littlearm", "elf32-littlearm", "elf32-littlearm") OUTPUT_ARCH(arm) ENTRY(_start) SECTIONS { . = 0x50008000; . = ALIGN(4); .text : { led.o (.text) *(.text) } . = ALIGN(4); .rodata : { *(SORT_BY_ALIGNMENT(SORT_BY_NAME(.rodata*))) } . = ALIGN(4); .data : { *(.data) } . = ALIGN(4); __bss_start = .; .bss (NOLOAD) : { *(.bss) . = ALIGN(4); } _end = .; }
-- Makefile :
octopus@octopus:~/arm/01_code$ more Makefile all: led.o arm-linux-ld -Tled.lds -o led.elf led.o arm-linux-objcopy -O binary led.elf led.bin led.o : led.S arm-linux-gcc -g -o led.o -c led.S .PHONY: clean clean: rm *.o led.elf led.bin
(2) 編譯
編譯 : 在該目次履行 make 敕令, 編譯后多了 led.o, led.elf, led.bin 三個文件, 個中 led.bin 是要燒寫到 nand flash 中的可履行二進制法度榜樣;
-- 編譯前 :
octopus@octopus:~/arm/01_code$ ls led.lds led.S Makefile
-- 編譯后 :
octopus@octopus:~/arm/01_code$ make arm-linux-gcc -g -o led.o -c led.S arm-linux-ld -Tled.lds -o led.elf led.o arm-linux-objcopy -O binary led.elf led.bin octopus@octopus:~/arm/01_code$ ls led.bin led.elf led.lds led.o led.S Makefile
3. 燒寫 led.bin
(1) 啟動方法切換
sd 卡啟動 : (1~8) 地位 : 0, 0, 0, 1, 1, 1, 1, 1;
nand flash 啟動 : (1~8) 地位 : x, x, x, 1, 1, 0, 0, 1;
nor flash 啟動 : (1~8) 地位 : x, x, x, 1, 0, 1, 0, x;
(2) 制造SD卡啟動盤
具體過程參照 : http://blog.csdn.net/shulianghan/article/details/42254237#t42
(3) 串口操作
開辟板串口計整潔 -- 應(yīng)用SecureCRT 串口連接 :
-- 設(shè)備治理器中查看串口端口 : COM7;
[img]http://img.blog.csdn.net/20150103122834119
-- 串口連接屬性 :
[img]http://img.blog.csdn.net/20150103122856178
-- 連接串口 :
[img]http://img.blog.csdn.net/20150103122938032
開辟板串口籌劃二 -- 打開 minicom 對象 : minicom 串口調(diào)試對象;
-- 留意 : 應(yīng)用 root 用戶打開, sudo minicom;
sd 卡啟動 :
-- 啟動方法 : 插入 sd 卡, 將啟動模式設(shè)置為 sd 卡啟動, 即將 屏幕右側(cè)的 8個開關(guān)設(shè)置成 (1~8) 地位 : 0, 0, 0, 1, 1, 1, 1, 1, 打開電源;
-- 留意 : 打開電源時 一向按 空格鍵;
-- 串口終端顯示 :
U-Boot 1.1.6 (Oct 9 2012 - 13:20:58) for SMDK6410 **************************************** ** u-boot 1.1.6 ** ** Updated for OK6410 TE6410 Board ** ** Version (2012-09-23) ** ** OEM: Forlinx Embedded ** ** Web: http://www.witech.com.cn ** **************************************** CPU: S3C6410 @532MHz Fclk = 532MHz, Hclk = 133MHz, Pclk = 66MHz, Serial = CLKUART (SYNC Mode) Board: SMDK6410 DRAM: 256 MB Flash: 0 kB NandFlash Information: Nandflash:ChipType= SLC ChipName=MT29F16G08ABACAWP No No Calc pagesize, blocksize, erasesize, use ids table ............. NandFlash:name=NAND 2GiB 1,8V 8-bit,id=38, pagesize=4096 ,chipsize=1024 MB,erasesize=524288 oobsize=128 NandFlash Size is 1024 MB SD/MMC: SD 2.0 / Manufacturer: 0x1B,OEM: "SM/00000",REV: 1.0,S/N: -1320320343,DATE: 2008/3 MMC/SD size: 971 MiB Freq = 25MHz In: serial Out: lcd Err: lcd Hit any key to stop autoboot: 0 ###################### User Menu for OK6410##################### [1] Format the nand flash [2] Burn image from SD card [3] Burn image from USB [4] Reboot the u-boot [5] Exit to command line -----------------------------Select--------------------------------- Enter your Selection:
格局化 nand flash : 在膳綾擎的 minicom 敕令行, 選擇 1 ([1] Format the nand flash -- 格局化 nand Flash), 彈出 Really scrub this NAND flash? <y/N> 時 選擇 y;
-----------------------------Select--------------------------------- Enter your Selection:1 NAND scrub: device 0 whole chip Warning: scrub option will erase all factory set bad blocks! There is no reliable way to recover them. Use this command only for testing purposes if you are sure of what you are doing! Really scrub this NAND flash? <y/N> Erasing at 0x3ff80000 -- 100% complete. Scanning device for bad blocks OK ###################### User Menu for OK6410##################### [1] Format the nand flash [2] Burn image from SD card [3] Burn image from USB [4] Reboot the u-boot [5] Exit to command line -----------------------------Select--------------------------------- Enter your Selection:
選擇大年夜 usb 燒寫竽暌鉤像 : 選擇 3 ([3] Burn image from USB -- 大年夜usb燒寫竽暌鉤像);
-----------------------------Select--------------------------------- Enter your Selection:3 ##### Select the fuction ##### [1] Flash u-boot [2] Flash kernel [3] Flash system [4] Exit Enter your Selection:
選擇 燒寫 u-boot 類型法度榜樣 : 裸板法度榜樣都屬于 u-boot 類型的;
##### Select the fuction ##### [1] Flash u-boot [2] Flash kernel [3] Flash system [4] Exit Enter your Selection:1 NAND erase: device 0 offset 0x0, size 0x200000 Erasing at 0x180000 -- 100% complete. OK Insert a OTG cable into the connector!
設(shè)置虛擬機的 USB 接口 : 之前寫過, 詳情見 http://blog.csdn.net/shulianghan/article/details/42254237#t45 ;
(3) Linux 操作
編譯 led 源碼 :
-- 進入 led 源碼目次 : 履行 make 敕令, 將編譯后的文件 拷貝到 dnw 地點目次;
[img]http://img.blog.csdn.net/20150103124624219
燒寫 led.bin :
-- 加載 dnw 驅(qū)動 : 應(yīng)用 insmod dnw_usb.ko 敕令;
[img]http://img.blog.csdn.net/20150103125228588
-- 燒寫 led.bin : 應(yīng)用 ./dnw led.bin 50008000 敕令;
[img]http://img.blog.csdn.net/20150103125520640
-- 串口終端顯示 : 如下顯示, 燒寫成功;
[img]http://img.blog.csdn.net/20150103125619203
-- 封閉開辟板應(yīng)用 nand flash 啟動 : 可以看到 LED1 點亮;
二. 交叉對象鏈
1. 交叉編譯器
(1) 通俗編譯
編譯下面的代碼 :
/************************************************************************* > File Name: main.c > Author: octopus > Mail: octopus_work.163.com > Created Time: 2015年01月03日 禮拜六 14時25分11秒 ************************************************************************/ #include<stdio.h> int main(int argc, char** argv) { printf("Hello World!\n"); return 0; }-- 編譯履行代碼 :
[root@localhost 02_gcc_demo]# gcc main.c [root@localhost 02_gcc_demo]# ./a.out Hello World!
(2) 交叉編譯并在開辟板運行
交叉編譯 : 應(yīng)用 arm-linux-gcc main.c 敕令交叉編譯, 經(jīng)由交叉編譯的 a.out 不克不及再 x86 平臺履行;
[img]http://img.blog.csdn.net/20150103145216218
應(yīng)用 U 盤將法度榜樣拷貝到開辟板 : 將 a.out 拷貝到 U 盤, 然后將 U 盤拷貝到開辟板上;
-- 拷貝敕令 : cp a.out /media/UUI/, UUI 是 U 盤名稱;
-- 開辟板插入 U 盤 : 將 U 盤插入開辟板(已安裝 Linux 操作體系) USB 口, 根目次下出現(xiàn) udisk 目次, 該目次就是 U 盤;
-- 履行交叉編譯后的法度榜樣 : 履行 a.out 法度榜樣, 履行成功;
[img]http://img.blog.csdn.net/20150103152207075
(3) 交叉|通俗編譯結(jié)不雅比較
比較交叉編譯 和 通俗編譯 的可履行文件 : 經(jīng)由過程 file 敕令比較可履行文件;
-- 交叉編譯 : 應(yīng)用 arm-linux-gcc main.c -o hello-arm 敕令交叉編譯結(jié)不雅 hello-arm, 應(yīng)用 file hello-arm 敕令查看文件屬性;
root@localhost 02_gcc_demo]# file hello-arm hello-arm: ELF 32-bit LSB executable, ARM, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.14, not stripped
-- 通俗編譯 : 應(yīng)用 gcc main.c -o hello-x86 敕令通俗編譯結(jié)不雅 hello-x86, 應(yīng)用 file hello-x86 敕令查看文件屬性;
[root@localhost 02_gcc_demo]# file hello-x86 hello-x86: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.18, not stripped[img]http://img.blog.csdn.net/20150103152825313
(4) 查找目次
查算作找目次 : 應(yīng)用 arm-linux-gcc -print-search-dirs 敕令查看;
[root@localhost ~]# arm-linux-gcc -print-search-dirs install: /usr/local/arm/4.3.2/bin/../lib/gcc/arm-none-linux-gnueabi/4.3.2/ programs: =/usr/local/arm/4.3.2/bin/../libexec/gcc/arm-none-linux-gnueabi/4.3.2/:/usr/local/arm/4.3.2/bin/../libexec/gcc/:/usr/local/arm/4.3.2/bin/../lib/gcc/arm-none-linux-gnueabi/4.3.2/../../../../arm-none-linux-gnueabi/bin/arm-none-linux-gnueabi/4.3.2/:/usr/local/arm/4.3.2/bin/../lib/gcc/arm-none-linux-gnueabi/4.3.2/../../../../arm-none-linux-gnueabi/bin/ libraries: =/usr/local/arm/4.3.2/bin/../lib/gcc/arm-none-linux-gnueabi/4.3.2/armv4t/:/usr/local/arm/4.3.2/bin/../lib/gcc/armv4t/:/usr/local/arm/4.3.2/bin/../lib/gcc/arm-none-linux-gnueabi/4.3.2/../../../../arm-none-linux-gnueabi/lib/arm-none-linux-gnueabi/4.3.2/armv4t/:/usr/local/arm/4.3.2/bin/../lib/gcc/arm-none-linux-gnueabi/4.3.2/../../../../arm-none-linux-gnueabi/lib/armv4t/:/usr/local/arm/4.3.2/bin/../arm-none-linux-gnueabi/libc/armv4t/lib/arm-none-linux-gnueabi/4.3.2/armv4t/:/usr/local/arm/4.3.2/bin/../arm-none-linux-gnueabi/libc/armv4t/lib/armv4t/:/usr/local/arm/4.3.2/bin/../arm-none-linux-gnueabi/libc/armv4t/usr/lib/arm-none-linux-gnueabi/4.3.2/armv4t/:/usr/local/arm/4.3.2/bin/../arm-none-linux-gnueabi/libc/armv4t/usr/lib/armv4t/:/usr/local/arm/4.3.2/bin/../lib/gcc/arm-none-linux-gnueabi/4.3.2/:/usr/local/arm/4.3.2/bin/../lib/gcc/:/usr/local/arm/4.3.2/bin/../lib/gcc/arm-none-linux-gnueabi/4.3.2/../../../../arm-none-linux-gnueabi/lib/arm-none-linux-gnueabi/4.3.2/:/usr/local/arm/4.3.2/bin/../lib/gcc/arm-none-linux-gnueabi/4.3.2/../../../../arm-none-linux-gnueabi/lib/:/usr/local/arm/4.3.2/bin/../arm-none-linux-gnueabi/libc/armv4t/lib/arm-none-linux-gnueabi/4.3.2/:/usr/local/arm/4.3.2/bin/../arm-none-linux-gnueabi/libc/armv4t/lib/:/usr/local/arm/4.3.2/bin/../arm-none-linux-gnueabi/libc/armv4t/usr/lib/arm-none-linux-gnueabi/4.3.2/:/usr/local/arm/4.3.2/bin/../arm-none-linux-gnueabi/libc/armv4t/usr/lib/ [root@localhost ~]#
2. 交叉鏈接器
(1) Makefile 示例
查看 led Makefile : 查看膳綾擎的 led 法度榜樣的 Makefile文件;
all: led.o arm-linux-ld -Tled.lds -o led.elf led.o arm-linux-objcopy -O binary led.elf led.bin led.o : led.S arm-linux-gcc -g -o led.o -c led.S .PHONY: clean clean: rm *.o led.elf led.bin
(2) 交叉鏈接器鏈接過程
鏈接過程 :
-- 交叉編譯 : 應(yīng)用 arm-linux-gcc -g -o led.o -c led.S 敕令, 獲取 led.o 文件, 交叉編譯結(jié)不雅是 生成 led.o 文件;
[img]http://img.blog.csdn.net/20150103154521703
-- 鏈接 : 鏈接 led.o 生成 led.elf 文件, 應(yīng)用 arm-linux-ld -Tled.lds -o led.elf led.o 敕令;
[img]http://img.blog.csdn.net/20150103154601872
-- 鏈接器敕令格局 : -T 后面跟著鏈接器腳本, 這里 鏈接器腳本是 led.lds, -o 是鏈接器的生成結(jié)不雅名稱;
3. arm-linux-readelf 對象
(1) arm-linux-readelf 解讀 .elf 文件
arm-linux-readelf 應(yīng)用示例 : 履行 arm-linux-readelf -a led.elf 敕令, 解讀 led.elf 文件;
-- 小端處理器運行 : "Data: 2's complement, little endian" 表示在小端 CPU 上履行, 如不雅法度榜樣大年夜小端 與 CPU 不一致, 便不克不及履行;
-- 運行平臺 : "Machine: ARM" 表示該法度榜樣在 ARM 平臺運行;
[root@localhost 01_led]# arm-linux-readelf -a led.elf ELF Header: Magic: 7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00 Class: ELF32 Data: 2's complement, little endian Version: 1 (current) OS/ABI: UNIX - System V ABI Version: 0 Type: EXEC (Executable file) Machine: ARM Version: 0x1 Entry point address: 0x50008000 Start of program headers: 52 (bytes into file) Start of section headers: 33344 (bytes into file) Flags: 0x5000002, has entry point, Version5 EABI Size of this header: 52 (bytes) Size of program headers: 32 (bytes) Number of program headers: 1 Size of section headers: 40 (bytes) Number of section headers: 10 Section header string table index: 7 Section Headers: [Nr] Name Type Addr Off Size ES Flg Lk Inf Al [ 0] NULL 00000000 000000 000000 00 0 0 0 [ 1] .text PROGBITS 50008000 008000 0000e0 00 AX 0 0 4 [ 2] .ARM.attributes ARM_ATTRIBUTES 00000000 0080e0 000018 00 0 0 1 [ 3] .debug_line PROGBITS 00000000 0080f8 000064 00 0 0 1 [ 4] .debug_info PROGBITS 00000000 00815c 000045 00 0 0 1 [ 5] .debug_abbrev PROGBITS 00000000 0081a1 000014 00 0 0 1 [ 6] .debug_aranges PROGBITS 00000000 0081b8 000020 00 0 0 8 [ 7] .shstrtab STRTAB 00000000 0081d8 000066 00 0 0 1 [ 8] .symtab SYMTAB 00000000 0083d0 0001a0 10 9 23 4 [ 9] .strtab STRTAB 00000000 008570 0000c3 00 0 0 1 Key to Flags: W (write), A (alloc), X (execute), M (merge), S (strings) I (info), L (link order), G (group), x (unknown) O (extra OS processing required) o (OS specific), p (processor specific) There are no section groups in this file. Program Headers: Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align LOAD 0x008000 0x50008000 0x50008000 0x000e0 0x000e0 R E 0x8000 Section to Segment mapping: Segment Sections... 00 .text There is no dynamic section in this file. There are no relocations in this file. There are no unwind sections in this file. Symbol table '.symtab' contains 26 entries: Num: Value Size Type Bind Vis Ndx Name 0: 00000000 0 NOTYPE LOCAL DEFAULT UND 1: 50008000 0 SECTION LOCAL DEFAULT 1 2: 00000000 0 SECTION LOCAL DEFAULT 2 3: 00000000 0 SECTION LOCAL DEFAULT 3 4: 00000000 0 SECTION LOCAL DEFAULT 4 5: 00000000 0 SECTION LOCAL DEFAULT 5 6: 00000000 0 SECTION LOCAL DEFAULT 6 7: 50008000 0 NOTYPE LOCAL DEFAULT 1 $a 8: 5000803c 0 NOTYPE LOCAL DEFAULT 1 reset 9: 50008020 0 NOTYPE LOCAL DEFAULT 1 _undefined_instruction 10: 50008024 0 NOTYPE LOCAL DEFAULT 1 _software_interrupt 11: 50008028 0 NOTYPE LOCAL DEFAULT 1 _prefetch_abort 12: 5000802c 0 NOTYPE LOCAL DEFAULT 1 _data_abort 13: 50008030 0 NOTYPE LOCAL DEFAULT 1 _not_used 14: 50008034 0 NOTYPE LOCAL DEFAULT 1 _irq 15: 50008038 0 NOTYPE LOCAL DEFAULT 1 _fiq 16: 50008064 0 NOTYPE LOCAL DEFAULT 1 set_peri_port 17: 50008074 0 NOTYPE LOCAL DEFAULT 1 disable_watchdog 18: 50008084 0 NOTYPE LOCAL DEFAULT 1 disable_irq 19: 500080a0 0 NOTYPE LOCAL DEFAULT 1 init_led 20: 500080b0 0 NOTYPE LOCAL DEFAULT 1 light_led 21: 50008060 0 NOTYPE LOCAL DEFAULT 1 halt 22: 500080c8 0 NOTYPE LOCAL DEFAULT 1 $d 23: 50008000 0 NOTYPE GLOBAL DEFAULT 1 _start 24: 500080e0 0 NOTYPE GLOBAL DEFAULT ABS __bss_start 25: 500080e0 0 NOTYPE GLOBAL DEFAULT ABS _end No version information found in this file. Attribute Section: aeabi File Attributes Tag_CPU_name: "4T" Tag_CPU_arch: v4T Tag_ARM_ISA_use: Yes [root@localhost 01_led]#
(2) arm-linux-readelf 解讀 可履行法度榜樣須要的庫文件
法度榜樣無法運行排錯辦法 :
-- 運行平臺紕謬 : ARM 平臺 和 x86 平臺之間的法度榜樣不克不及互相運行;
-- CPU 大年夜小端紕謬 : 大年夜端格局的法度榜樣不克不及運行在小端 CPU 上;
-- 庫紕謬 : 應(yīng)用 arm-linux-readelf -d hello-arm 查看法度榜樣運行須要的庫, "0x00000001 (NEEDED) Shared library: [libc.so.6]", 表示須要有l(wèi)ibc.so.6 庫;
[root@localhost 02_gcc_demo]# arm-linux-readelf -d hello-arm Dynamic section at offset 0x460 contains 24 entries: Tag Type Name/Value 0x00000001 (NEEDED) Shared library: [libc.so.6] 0x0000000c (INIT) 0x8274 0x0000000d (FINI) 0x8428 0x00000019 (INIT_ARRAY) 0x10454 0x0000001b (INIT_ARRAYSZ) 4 (bytes) 0x0000001a (FINI_ARRAY) 0x10458 0x0000001c (FINI_ARRAYSZ) 4 (bytes) 0x00000004 (HASH) 0x8168 0x00000005 (STRTAB) 0x81e0 0x00000006 (SYMTAB) 0x8190 0x0000000a (STRSZ) 65 (bytes) 0x0000000b (SYMENT) 16 (bytes) 0x00000015 (DEBUG) 0x0 0x00000003 (PLTGOT) 0x10548 0x00000002 (PLTRELSZ) 32 (bytes) 0x00000014 (PLTREL) REL 0x00000017 (JMPREL) 0x8254 0x00000011 (REL) 0x824c 0x00000012 (RELSZ) 8 (bytes) 0x00000013 (RELENT) 8 (bytes) 0x6ffffffe (VERNEED) 0x822c 0x6fffffff (VERNEEDNUM) 1 0x6ffffff0 (VERSYM) 0x8222 0x00000000 (NULL) 0x0 [root@localhost 02_gcc_demo]#
4. 反匯編器(arm-linux-objdump)
(1) 反匯編
反匯編示例 : arm-linux-objdump -D -S hello-arm, 太多, 省略后面幾百行;
[root@localhost 02_gcc_demo]# arm-linux-objdump -D -S hello-arm hello-arm: file format elf32-littlearm Disassembly of section .interp: 00008134 <.interp>: 8134: 62696c2f rsbvs r6, r9, #12032 ; 0x2f00 8138: 2d646c2f stclcs 12, cr6, [r4, #-188]! 813c: 756e696c strbvc r6, [lr, #-2412]! 8140: 6f732e78 svcvs 0x00732e78 8144: Address 0x00008144 is out of bounds. Disassembly of section .note.ABI-tag:... ...
(2) 編譯附加調(diào)試信息
帶調(diào)試信息的反編譯 :
-- 交叉編譯帶調(diào)試信息 : arm-linux-gcc -g main.c 敕令, 進行交叉編譯, 結(jié)不雅 a.out;
-- 反編譯 : arm-linux-objdump -S -D a.out 敕令, 反編譯結(jié)不雅 每行 C 代碼都對應(yīng) 匯編代碼;
... ... #include<stdio.h> int main(int argc, char** argv) { 837c: e92d4800 push {fp, lr} 8380: e28db004 add fp, sp, #4 ; 0x4 8384: e24dd008 sub sp, sp, #8 ; 0x8 8388: e50b0008 str r0, [fp, #-8] 838c: e50b100c str r1, [fp, #-12] printf("Hello World!\n"); 8390: e59f0014 ldr r0, [pc, #20] ; 83ac <main+0x30> 8394: ebffffc8 bl 82bc <_init+0x48> return 0; 8398: e3a03000 mov r3, #0 ; 0x0 } ... ...
5. 文件格局轉(zhuǎn)換器(arm-linux-objcopy)
文件格局轉(zhuǎn)換 :
-- 轉(zhuǎn)換原因 : elf 格局文件不克不及再 arm 處理器履行;
-- 轉(zhuǎn)換敕令 : 進入 led 目次, 持續(xù)膳綾擎的 led 編譯, 鏈接 生成了 led.elf 文件, 履行 arm-linux-objcopy -O binary led.elf led.bin 敕令, 將 elf 文件轉(zhuǎn)換為 bin 文件;
-- 敕令解析 : -O 表示輸出格局, -O binary 表示輸出二進制格局;
[img]http://img.blog.csdn.net/20150103161913668
三. Makefile 文件
Makefile 示例 :
all: led.o arm-linux-ld -Tled.lds -o led.elf led.o arm-linux-objcopy -O binary led.elf led.bin led.o : led.S arm-linux-gcc -g -o led.o -c led.S .PHONY: clean clean: rm *.o led.elf led.bin
1. Makefile 規(guī)矩
(1) 通俗規(guī)矩
規(guī)矩 : 用于解釋文件生成過程;
-- 規(guī)矩語法 :
target(目標(biāo)) : prerequisites(依附)
command(敕令)
led.o : led.S arm-linux-gcc -g -o led.o -c led.S
-- 語法解析 : led.o 是目標(biāo), led.S 是依附, arm-linux-gcc -g -o led.o -c led.S 是敕令;
(2) 通用規(guī)矩
通用規(guī)矩示例 :
%.o : %.c
arm-linux-gcc -o %.o %.c
-- 解析 : 編譯 main.c 生成 main.o;
2. Makefile 目標(biāo)
(1) 偽目標(biāo)
Makefile 中的偽目標(biāo)示例 : 偽目標(biāo) 只有敕令, 沒有依附;
.PHONY: clean clean: rm *.o led.elf led.bin-- 偽目標(biāo)標(biāo)示 : ".PHONY: clean" 將 clean 聲明為 偽目標(biāo);
(2) 最注目標(biāo)
最注目標(biāo) : Makefile 默認履行 第一個目標(biāo), 第一個目標(biāo)就是最注目標(biāo);
3. Makefile 變量
(1) 自定義變量
變量應(yīng)用示例 :
-- 應(yīng)用標(biāo)量前 :
app1: app1.o func1.o func2.o gcc app1.o func1.o func2.o -o app1 app2: app2.o func1.o func2.o gcc app2.o func1.o func2.o -o app2-- 定義變量 : obj=func1.o func2.o, 將該定義的變量應(yīng)用于 Makefile;
obj=func1.o func2.o app1: app1.o $(obj) gcc app1.o $(obj) -o app1 app2: app2.o $(obj) gcc app2.o $(obj) -o app2
(2) 體系定義變量
體系定義變量 :
-- $^ : 代表依附的文件;
-- $@ : 代表目標(biāo);
-- $< : 代表第一個依附文件;
-- 應(yīng)用體系變量前 :
all: led.o arm-linux-ld -Tled.lds -o led.elf led.o arm-linux-objcopy -O binary led.elf led.bin led.o : led.S arm-linux-gcc -g -o led.o -c led.S .PHONY: clean clean: rm *.o led.elf led.bin-- 應(yīng)用體系變量后 :
all: led.o arm-linux-ld -Tled.lds -o led.elf $^ arm-linux-objcopy -O binary led.elf led.bin led.o : led.S arm-linux-gcc -g -o $@ -c $^ .PHONY: clean clean: rm *.o led.elf led.bin-- 編譯運行 : 編譯結(jié)不雅與 不應(yīng)用體系變量時的規(guī)矩雷同;
[img]http://img.blog.csdn.net/20150103171543569
4. Makefile 技能
(1) Makefile 去回顯
Makefile 去回顯 :
-- 回顯 : 履行編譯時, 會周詳令打印到敕令行中;
[img]http://img.blog.csdn.net/20150103171933640
-- 去回顯 : 在敕令前添加 "@" 符號;
all: led.o @arm-linux-ld -Tled.lds -o led.elf $^ @arm-linux-objcopy -O binary led.elf led.bin led.o : led.S arm-linux-gcc -g -o $@ -c $^ .PHONY: clean clean: rm *.o led.elf led.bin-- 履行結(jié)不雅 : 此時就沒有膳綾擎兩條顯示了;
[img]http://img.blog.csdn.net/20150103172000031
(2) Makefile 文件名稱修改
Makefile 文件名稱 :
-- 默擾綾軀稱 : make 對象默認尋找 "Makefile" 或者 "makefile" 文件, 如不雅沒有回報錯;
[img]http://img.blog.csdn.net/20150103172801718
-- 指明 Makefile 文件 : make -f Makefile-ARM 敕令;
[img]http://img.blog.csdn.net/20150103172845583
四. 鏈接器腳本
1. 鏈接器腳本示例
可履行法度榜樣構(gòu)成 : 代碼段, 數(shù)據(jù)段, bss 段; 鏈接器腳本就是設(shè)備這些段信息;
簡單的鏈接器腳本示例 :
-- 代碼段 : .text 表示代碼段, * 表示所有文件, *(.text) 表示所有文件的代碼;
-- 數(shù)據(jù)段 : .data 表示數(shù)據(jù)段, * 表示所有文件, *(.data) 表示所有文件的數(shù)據(jù)段;
-- bss 段 : .bss 表示 bss 段, * 表示所有文件, *(.bss) 表示所有文件的 bss 段;
SECTIONS{ .text : { *(.text) } .data : { *(.data) } .bss : { *(.bss) } }
2. 設(shè)置肇端鏈接器地址
設(shè)置鏈接器肇端地址 :
-- 語法 : ". = 地址";
-- lds 腳本示例 :
SECTIONS{ . =0x0; .text : { *(.text) } .data : { *(.data) } .bss : { *(.bss) } }-- 反編譯編譯后的 elf 文件 : "00000000 <_start>:" 表示大年夜 0 地址開端;
[root@localhost 01_led]# arm-linux-objdump -D -S led.elf led.elf: file format elf32-littlearm Disassembly of section .text: 00000000 <_start>: .text .globl _start #define VIC0_INT 0x71200000 #define VIC1_INT 0x71300000-- 修改首地址后的腳本 : 將肇端地址修改為 0x30008000;
SECTIONS{ . =0x30008000; .text : { *(.text) } .data : { *(.data) } .bss : { *(.bss) } }
-- 反編譯elf : 履行 arm-linux-objdump -D -S led.elf 敕令, "30008000 <_start>:" 肇端地址是 0x30008000;
[root@localhost 01_led]# arm-linux-objdump -D -S led.elf led.elf: file format elf32-littlearm Disassembly of section .text: 30008000 <_start>: .text .globl _start #define VIC0_INT 0x71200000 #define VIC1_INT 0x71300000 ... ...
地址比較 :
-- 鏈接器肇端地址 0x000000 :
[img]http://img.blog.csdn.net/20150103184202997
-- 鏈接器肇端地址 0x30008000 :
[img]http://img.blog.csdn.net/20150103184220906
3. 對齊設(shè)置
對齊典范 : . = ALIGN(4); 表示大年夜當(dāng)前開端 4 字節(jié)對齊;
SECTIONS{ . =0x30008000; . = ALIGN(4); .text : { *(.text) } . = ALIGN(4); .data : { *(.data) } . = ALIGN(4); .bss : { *(.bss) } }
4. 變量
變量示例 : 變量保存之后, 可以再法度榜樣頂用到變量;
-- 示例 :
SECTIONS{ . =0x30008000; . = ALIGN(4); .text : { *(.text) } . = ALIGN(4); .data : { *(.data) } . = ALIGN(4); bss_start = . ; .bss : { *(.bss) } bss_end = . ; }
5. 設(shè)置代碼段首文件
設(shè)置首文件 :
-- 語法 : start.o(.text);
-- 示例 :
SECTIONS{ . =0x30008000; . = ALIGN(4); .text : { start.o(.text) *(.text) } . = ALIGN(4); .data : { *(.data) } . = ALIGN(4); bss_start = . ; .bss : { *(.bss) } bss_end = . ; }
五. eclipse 在線調(diào)試
1. eclipse 集成開辟情況示意圖
eclipse 集成開辟情況示意圖 :
-- 硬件 : 開辟板, JLink;
-- 軟件 : eclipse, GDB Server, JLink 軟件;
[img]http://img.blog.csdn.net/20150103191717659
2. 預(yù)備工作
(1) 格局化 nand flash
格局化 nand flash : 留意必須格局化 NandFlash 不然會出現(xiàn)弗成預(yù)知缺點;
(2) 硬件連接
硬件連接 : JLink 連接, 串口連接, 電源連接, 開辟板 nand flash 啟動;
(3) 安裝 JLink Windows 驅(qū)動
JLink Windows 驅(qū)動安裝 : 買 JLink 時會帶著這個安裝盤, 安裝 JLink Windows 驅(qū)動 才可聲調(diào)試成功, 不然會在 Windows 這一關(guān)被擋下 導(dǎo)致連接不成功;
(3) 安裝 gdb server
安裝 arm-linux-gdb-7.5.tar.gz :
-- 解壓 : tar -xvzf arm-linux-gdb-7.5.tar.gz 敕令;
[img]http://img.blog.csdn.net/20150103194547031
-- 查看 build-all 腳本 : 可以看到腳本履行流程是 解壓 gdb-7.5.tar.gz, 然后生成 Makefile文件, 之落后編譯安裝到 /opt/arm-linux-gdb 目次下;
[root@localhost arm-linux-gdb-7.5]# cat build-all #/bin/sh rm -fr gdb-7.5 rm -r /opt/arm-linux-gdb/ tar xvzf gdb-7.5.tar.gz cd gdb-7.5 ./configure --target=arm-linux --prefix=/opt/arm-linux-gdb/ -v make && make install cd /opt/arm-linux-gdb/-- 進入 ddb 安裝目次, 查看路徑 :
[img]http://img.blog.csdn.net/20150103194754203
-- 設(shè)備情況變量 : 將 /etc/profile 中的情況變量刪除, 只在 ~/.bashrc 中設(shè)備;
export PATH=$PATH:/opt/arm-linux-gdb/bin/ export PATH=$PATH:/usr/local/arm/4.3.2/bin/-- 情況變量次序 : 留意前面的情況變量覆蓋后面的, 交叉對象鏈中也有 arm-linu-gdb, 然則 /opt 下面的先設(shè)備, 是以事這個師長教師效;
-- 默認的 arm-linu-gdb : 是 7.5 版本的;
[img]http://img.blog.csdn.net/20150103195042855
-- 交叉對象鏈中的 gdb : 6.8版本的, 無法進行 在線調(diào)試;
[img]http://img.blog.csdn.net/20150103195150887
(4) 安裝 JLink
安裝流程 :
-- 解壓文件 : JLink_Linux_V434a.tgz;
-- 進入cd JLink_Linux_V434a 目次, 拷貝文件 : 拷貝 libjlinkarm.so.4 和 libjlinkarm.so.4.34.1 到 /usr/lib 目次下 敕令 cp -d libjlinkarm.so* /usr/lib -f, 拷貝 45-jlink.rules 到 /etc/udev/rules.d/ 下 敕令 cp 45-jlink.rules /etc/udev/rules.d/;
[root@localhost ARM-tools]# tar -xvzf JLink_Linux_V434a.tgz JLink_Linux_V434a/ JLink_Linux_V434a/JLinkExe JLink_Linux_V434a/libjlinkarm.so.4 JLink_Linux_V434a/start JLink_Linux_V434a/JLinkGDBServer JLink_Linux_V434a/libjlinkarm.so.4.34.1 JLink_Linux_V434a/README JLink_Linux_V434a/45-jlink.rules [root@localhost ARM-tools]# ls arm-linux-gcc-4.3.2.tgz dnw_usb.ko arm-linux-gdb-7.5 eclipse-cpp-helios-SR2-linux-gtk.tar.gz arm-linux-gdb-7.5.tar.gz JLink_Linux_V434a dnw JLink_Linux_V434a.tgz [root@localhost ARM-tools]# cd JLink_Linux_V434a [root@localhost JLink_Linux_V434a]# ls 45-jlink.rules JLinkGDBServer libjlinkarm.so.4.34.1 start JLinkExe libjlinkarm.so.4 README [root@localhost JLink_Linux_V434a]# cp -d libjlinkarm.so* /usr/lib -f [root@localhost JLink_Linux_V434a]# cp 45-jlink.rules /etc/udev/rules.d/[img]http://img.blog.csdn.net/20150103200045796
履行 JLinkGDBServer :
[root@localhost JLink_Linux_V434a]# ./JLinkGDBServer SEGGER J-Link GDB Server V4.34a JLinkARM.dll V4.34a (DLL compiled Aug 31 2011 11:51:40) Listening on TCP/IP port 2331 J-Link connected Firmware: J-Link ARM V8 compiled Aug 24 2011 17:23:32 Hardware: V8.00 S/N: 17935099 Feature(s): RDI,FlashDL,FlashBP,JFlash J-Link found 2 JTAG devices, Total IRLen = 5 JTAG ID: 0x07B76F0F (ARM11)
[img]http://img.blog.csdn.net/20150105012834328
(5) 安裝 eclipse
安裝流程 :
-- 撤消 默認 eclipse : 紅帽6.3中默認安裝了eclipse, 進入 /usr/bin 目次, 將 eclipse 快捷方法改為 eclipse.bak, 如不雅須要應(yīng)用這個 eclipse, 履行 eclipse.bak即可;
[root@localhost ~]# cd /usr/bin/ [root@localhost bin]# mv eclipse eclipse.bak-- 開端啟動時會掉足 : 不消管, 在此啟動 eclipse 就會啟動成功;
[root@localhost eclipse]# ./eclipse # # A fatal error has been detected by the Java Runtime Environment: # # SIGSEGV (0xb) at pc=0x00b8f8c1, pid=11165, tid=3077863104 # # JRE version: 6.0_24-b24 # Java VM: OpenJDK Client VM (20.0-b12 mixed mode linux-x86 ) # Derivative: IcedTea6 1.11.1 # Distribution: Red Hat Enterprise Linux Server release 6.2 (Santiago), package rhel-1.45.1.11.1.el6-i386 # Problematic frame: # C [UTF-16.so+0x8c1] gconv+0x3c1 # # An error report file with more information is saved as: # /root/arm/ARM-tools/eclipse/hs_err_pid11165.log # # If you would like to submit a bug report, please include # instructions how to reproduce the bug and visit: # http://icedtea.classpath.org/bugzilla # The crash happened outside the Java Virtual Machine in native code. # See problematic frame for where to report the bug. # 已放棄 (core dumped)-- 安裝 CDT 插件 : 地址 http://opensource.zylin.com/zylincdt , 留意 三個都選擇;
[img]http://img.blog.csdn.net/20150103201817066
(6) 工程設(shè)備
設(shè)備工程 :
-- 導(dǎo)入工程 : 選擇 菜單 "File" --> "New" --> "Makefile Project with Existing Code"
[img]http://img.blog.csdn.net/20150103220456229
-- 撤消主動編譯 : 菜單 "Project" --> "Build Automatically" 選項;
-- 清除編譯文件 : 選擇 "Project" --> "Clean ...", 就會清除 .o .elf .bin 文件;
-- 編譯文件 : "Project" --> "Build All" 選項, 同時 Console 中會有敕令行輸出;
[img]http://img.blog.csdn.net/20150103220830765
(7) Debug設(shè)備
Debug 設(shè)備 :
-- 設(shè)置Main 選項卡 : 雙擊 Zylin Embedded debug (Native), 創(chuàng)建 Degug, 設(shè)置工程名, 設(shè)置調(diào)試法度榜樣, 留意選擇 elf 格局的文件;
[img]http://img.blog.csdn.net/20150103221537640
-- 設(shè)置 Debugger 選項卡 : 撤消 Stop on startup at : main 選項, GDB debugger 法度榜樣選擇為 arm-linux-gdb;
[img]http://img.blog.csdn.net/20150103221606765
-- 設(shè)置初始化腳本 : 在 Commands 選項卡中設(shè)置 初始化腳本 , 留意下面的腳本是 ok6410 開辟板的腳本, 其它開辟板無法應(yīng)用;
# tiny6410_config # connect to the J-Link gdb server target remote localhost:2331 # Set JTAG speed to 30 kHz monitor endian little monitor speed 30 # Reset the target monitor reset monitor sleep 10 # # CPU core initialization (to be done by user) # # Set the processor mode monitor reg cpsr = 0xd3 #config MMU #flush v3/v4 cache monitor cp15 7, 7, 0, 0 = 0x0 #/* flush v4 TLB */ monitor cp15 8, 7, 0, 0 = 0x0 #disable MMU stuff and caches monitor cp15 1, 0, 0, 0 =0x1002 #Peri port setup monitor cp15 15, 2, 0, 4 = 0x70000013 #disable watchdog monitor MemU32 0x7e004000 = 0x00000000 monitor sleep 10 #disable interrupt monitor MemU32 0x71200014 = 0x00000000 monitor MemU32 0x71300014 = 0x00000000 monitor MemU32 0x7120000C = 0x00000000 monitor MemU32 0x7130000C = 0x00000000 monitor MemU32 0x71200F00 = 0x00000000 monitor MemU32 0x71300F00 = 0x00000000 #set clock monitor MemU32 0x7e00f900 = 0x0000801e monitor MemU32 0x7e00f000 = 0x0000ffff monitor MemU32 0x7e00f004 = 0x0000ffff monitor MemU32 0x7e00f020 = 0x01043310 monitor MemU32 0x7e00f00C = 0xc2150601 monitor MemU32 0x7e00f010 = 0xc2150601 monitor MemU32 0x7e00f024 = 0x00000003 monitor MemU32 0x7e00f014 = 0x00200102 monitor MemU32 0x7e00f018 = 0x00000000 monitor MemU32 0x7e00f01C = 0x14000007 #config sdram monitor MemU32 0x7e00f120 = 0x00000008 monitor MemU32 0x7e001004 = 0x00000004 monitor MemU32 0x7e001010 = 0x0000040f monitor MemU32 0x7e001014 = 0x00000006 monitor MemU32 0x7e001018 = 0x00000001 monitor MemU32 0x7e00101c = 0x00000002 monitor MemU32 0x7e001020 = 0x00000006 monitor MemU32 0x7e001024 = 0x0000000a monitor MemU32 0x7e001028 = 0x0000000c monitor MemU32 0x7e00102c = 0x0000018f monitor MemU32 0x7e001030 = 0x0000000c monitor MemU32 0x7e001034 = 0x00000002 monitor MemU32 0x7e001038 = 0x00000002 monitor MemU32 0x7e00103c = 0x00000002 monitor MemU32 0x7e001040 = 0x00000002 monitor MemU32 0x7e001044 = 0x00000013 monitor MemU32 0x7e001048 = 0x00000013 monitor MemU32 0x7e00100C = 0x00010012 monitor MemU32 0x7e00104C = 0x00000b45 monitor MemU32 0x7e001200 = 0x000150f8 monitor MemU32 0x7e001304 = 0x00000000 monitor MemU32 0x7e001008 = 0x000c0000 monitor MemU32 0x7e001008 = 0x00000000 monitor MemU32 0x7e001008 = 0x00040000 monitor MemU32 0x7e001008 = 0x00040000 monitor MemU32 0x7e001008 = 0x000a0000 monitor MemU32 0x7e001008 = 0x00080032 monitor MemU32 0x7e001004 = 0x00000000 # Setup GDB for faster downloads #set remote memory-write-packet-size 1024 set remote memory-write-packet-size 4096 set remote memory-write-packet-size fixed monitor speed 12000 break _start load
[img]http://img.blog.csdn.net/20150103221647496
-- Debug 調(diào)試 : 履行 debug 調(diào)試, 再彈出的對話框中點擊 yes;
[img]http://img.blog.csdn.net/20150105013125152 [img]http://img.blog.csdn.net/20150105013258315
-- 此時可以單步調(diào)試 :
[img]http://img.blog.csdn.net/20150105013247796
.
作者 : 韓曙亮
博客地址 : http://blog.csdn.net/shulianghan/article/details/42239705
參考博客 : 【嵌入式開辟】嵌入式 開辟情況 (長途登錄 | 文件共享 | NFS TFTP 辦事器 | 串口連接 | Win8.1 + RedHat Enterprise 6.3 + Vmware11)
相關(guān)案例查看更多
相關(guān)閱讀
- 云南網(wǎng)絡(luò)推廣
- 網(wǎng)站建設(shè)公司網(wǎng)站
- 人口普查小程序
- 麗江小程序開發(fā)
- 云南網(wǎng)站建設(shè)價格
- typescript
- 小程序開發(fā)
- 云南小程序商城
- 云南etc微信小程序
- 云南網(wǎng)站建設(shè)哪家好
- 云南網(wǎng)站建設(shè)高手
- 軟件定制
- 云南網(wǎng)站制作哪家好
- 云南網(wǎng)站建設(shè)
- 網(wǎng)站搭建
- 云南電商網(wǎng)站建設(shè)
- 大理網(wǎng)站建設(shè)公司
- 河南小程序制作
- 昆明做網(wǎng)站建設(shè)的公司排名
- 開發(fā)框架
- 小程序設(shè)計
- 云南小程序開發(fā)推薦
- 云南做軟件
- 云南網(wǎng)站建設(shè)靠譜公司
- 小程序技術(shù)
- 手機網(wǎng)站建設(shè)
- 做網(wǎng)站
- 云南省城鄉(xiāng)建設(shè)廳網(wǎng)站
- 云南小程序開發(fā)制作公司
- 網(wǎng)站建設(shè)費用