思想:先整体后局部
Pc与开发板连接方式
1、UART异步串行通信接口(串口)
2、USB串行通信接口
3、TCP/IP网络通信接口
4、Debug Jtag调试接口
PC:CentOS 7
Demoboard:Friendly arm nano pi neo4
WIKI:http://wiki.friendlyarm.com/wiki/index.php/NanoPi_NEO4
arm-none-linux-gnueabi- arm-linux-
arm-none-eabi-
arm-elf-
The GNU Toolchain for ARM Target HOWTO(官方手册)
目标机与主机CPU架构不同
通过交叉编译工具,我们就可以在CPU能力很强、存储控件足够的主机平台上(比如PC上)编译出针对其他平台的可执行程序。
简单地说,就是在一个平台上生成另一个平台上的可执行代码。
1、下载源码并解压
看我之前的文章:https://blog.csdn.net/zzq1824837536/article/details/94435217
2、添加环境变量
$ cd /opt/FriendlyARM/toolchain/6.4-aarch64/bin
$ ls -alF
total 36180
dr-xr-xr-x. 2 zhangzhiqiang zhangzhiqiang 8192 Jul 26 2017 ./
dr-xr-xr-x. 8 zhangzhiqiang zhangzhiqiang 106 Jul 26 2017 ../
-r-xr-xr-x. 1 zhangzhiqiang zhangzhiqiang 997064 Jul 26 2017 aarch64-cortexa53-linux-gnu-addr2line*
-r-xr-xr-x. 2 zhangzhiqiang zhangzhiqiang 1025648 Jul 26 2017 aarch64-cortexa53-linux-gnu-ar*
-r-xr-xr-x. 2 zhangzhiqiang zhangzhiqiang 1693240 Jul 26 2017 aarch64-cortexa53-linux-gnu-as*
-r-xr-xr-x. 2 zhangzhiqiang zhangzhiqiang 928128 Jul 26 2017 aarch64-cortexa53-linux-gnu-c++*
lrwxrwxrwx. 1 zhangzhiqiang zhangzhiqiang 31 Jul 26 2017 aarch64-cortexa53-linux-gnu-cc -> aarch64-cortexa53-linux-gnu-gcc*
-r-xr-xr-x. 1 zhangzhiqiang zhangzhiqiang 996648 Jul 26 2017 aarch64-cortexa53-linux-gnu-c++filt*
-r-xr-xr-x. 1 zhangzhiqiang zhangzhiqiang 928128 Jul 26 2017 aarch64-cortexa53-linux-gnu-cpp*
-r-xr-xr-x. 1 zhangzhiqiang zhangzhiqiang 2974048 Jul 26 2017 aarch64-cortexa53-linux-gnu-dwp*
-r-xr-xr-x. 1 zhangzhiqiang zhangzhiqiang 31512 Jul 26 2017 aarch64-cortexa53-linux-gnu-elfedit*
-r-xr-xr-x. 2 zhangzhiqiang zhangzhiqiang 928128 Jul 26 2017 aarch64-cortexa53-linux-gnu-g++*
-r-xr-xr-x. 2 zhangzhiqiang zhangzhiqiang 928128 Jul 26 2017 aarch64-cortexa53-linux-gnu-gcc*
-r-xr-xr-x. 2 zhangzhiqiang zhangzhiqiang 928128 Jul 26 2017 aarch64-cortexa53-linux-gnu-gcc-6.4.0*
-r-xr-xr-x. 1 zhangzhiqiang zhangzhiqiang 27104 Jul 26 2017 aarch64-cortexa53-linux-gnu-gcc-ar*
-r-xr-xr-x. 1 zhangzhiqiang zhangzhiqiang 27104 Jul 26 2017 aarch64-cortexa53-linux-gnu-gcc-nm*
-r-xr-xr-x. 1 zhangzhiqiang zhangzhiqiang 27104 Jul 26 2017 aarch64-cortexa53-linux-gnu-gcc-ranlib*
-r-xr-xr-x. 1 zhangzhiqiang zhangzhiqiang 511488 Jul 26 2017 aarch64-cortexa53-linux-gnu-gcov*
-r-xr-xr-x. 1 zhangzhiqiang zhangzhiqiang 449944 Jul 26 2017 aarch64-cortexa53-linux-gnu-gcov-dump*
-r-xr-xr-x. 1 zhangzhiqiang zhangzhiqiang 470520 Jul 26 2017 aarch64-cortexa53-linux-gnu-gcov-tool*
-r-xr-xr-x. 1 zhangzhiqiang zhangzhiqiang 5920064 Jul 26 2017 aarch64-cortexa53-linux-gnu-gdb*
-r-xr-xr-x. 1 zhangzhiqiang zhangzhiqiang 1067976 Jul 26 2017 aarch64-cortexa53-linux-gnu-gprof*
-r-xr-xr-x. 1 zhangzhiqiang zhangzhiqiang 143 Jul 26 2017 aarch64-cortexa53-linux-gnu-ld*
-r-xr-xr-x. 2 zhangzhiqiang zhangzhiqiang 2115640 Jul 26 2017 aarch64-cortexa53-linux-gnu-ld.bfd*
-r-xr-xr-x. 1 zhangzhiqiang zhangzhiqiang 15087 Jul 26 2017 aarch64-cortexa53-linux-gnu-ldd*
-r-xr-xr-x. 2 zhangzhiqiang zhangzhiqiang 5129664 Jul 26 2017 aarch64-cortexa53-linux-gnu-ld.gold*
-r-xr-xr-x. 2 zhangzhiqiang zhangzhiqiang 1010056 Jul 26 2017 aarch64-cortexa53-linux-gnu-nm*
-r-xr-xr-x. 2 zhangzhiqiang zhangzhiqiang 1193320 Jul 26 2017 aarch64-cortexa53-linux-gnu-objcopy*
-r-xr-xr-x. 2 zhangzhiqiang zhangzhiqiang 1895944 Jul 26 2017 aarch64-cortexa53-linux-gnu-objdump*
-r-xr-xr-x. 1 zhangzhiqiang zhangzhiqiang 10448 Jul 26 2017 aarch64-cortexa53-linux-gnu-populate*
-r-xr-xr-x. 2 zhangzhiqiang zhangzhiqiang 1025648 Jul 26 2017 aarch64-cortexa53-linux-gnu-ranlib*
-r-xr-xr-x. 2 zhangzhiqiang zhangzhiqiang 522136 Jul 26 2017 aarch64-cortexa53-linux-gnu-readelf*
-r-xr-xr-x. 1 zhangzhiqiang zhangzhiqiang 1001032 Jul 26 2017 aarch64-cortexa53-linux-gnu-size*
-r-xr-xr-x. 1 zhangzhiqiang zhangzhiqiang 997064 Jul 26 2017 aarch64-cortexa53-linux-gnu-strings*
-r-xr-xr-x. 2 zhangzhiqiang zhangzhiqiang 1193320 Jul 26 2017 aarch64-cortexa53-linux-gnu-strip*
lrwxrwxrwx. 1 zhangzhiqiang zhangzhiqiang 37 Jul 26 2017 aarch64-linux-addr2line -> aarch64-cortexa53-linux-gnu-addr2line*
lrwxrwxrwx. 1 zhangzhiqiang zhangzhiqiang 30 Jul 26 2017 aarch64-linux-ar -> aarch64-cortexa53-linux-gnu-ar*
lrwxrwxrwx. 1 zhangzhiqiang zhangzhiqiang 30 Jul 26 2017 aarch64-linux-as -> aarch64-cortexa53-linux-gnu-as*
lrwxrwxrwx. 1 zhangzhiqiang zhangzhiqiang 31 Jul 26 2017 aarch64-linux-c++ -> aarch64-cortexa53-linux-gnu-c++*
lrwxrwxrwx. 1 zhangzhiqiang zhangzhiqiang 30 Jul 26 2017 aarch64-linux-cc -> aarch64-cortexa53-linux-gnu-cc*
lrwxrwxrwx. 1 zhangzhiqiang zhangzhiqiang 35 Jul 26 2017 aarch64-linux-c++filt -> aarch64-cortexa53-linux-gnu-c++filt*
lrwxrwxrwx. 1 zhangzhiqiang zhangzhiqiang 31 Jul 26 2017 aarch64-linux-cpp -> aarch64-cortexa53-linux-gnu-cpp*
lrwxrwxrwx. 1 zhangzhiqiang zhangzhiqiang 31 Jul 26 2017 aarch64-linux-dwp -> aarch64-cortexa53-linux-gnu-dwp*
lrwxrwxrwx. 1 zhangzhiqiang zhangzhiqiang 35 Jul 26 2017 aarch64-linux-elfedit -> aarch64-cortexa53-linux-gnu-elfedit*
lrwxrwxrwx. 1 zhangzhiqiang zhangzhiqiang 31 Jul 26 2017 aarch64-linux-g++ -> aarch64-cortexa53-linux-gnu-g++*
lrwxrwxrwx. 1 zhangzhiqiang zhangzhiqiang 31 Jul 26 2017 aarch64-linux-gcc -> aarch64-cortexa53-linux-gnu-gcc*
lrwxrwxrwx. 1 zhangzhiqiang zhangzhiqiang 37 Jul 26 2017 aarch64-linux-gcc-6.4.0 -> aarch64-cortexa53-linux-gnu-gcc-6.4.0*
lrwxrwxrwx. 1 zhangzhiqiang zhangzhiqiang 34 Jul 26 2017 aarch64-linux-gcc-ar -> aarch64-cortexa53-linux-gnu-gcc-ar*
lrwxrwxrwx. 1 zhangzhiqiang zhangzhiqiang 34 Jul 26 2017 aarch64-linux-gcc-nm -> aarch64-cortexa53-linux-gnu-gcc-nm*
lrwxrwxrwx. 1 zhangzhiqiang zhangzhiqiang 38 Jul 26 2017 aarch64-linux-gcc-ranlib -> aarch64-cortexa53-linux-gnu-gcc-ranlib*
lrwxrwxrwx. 1 zhangzhiqiang zhangzhiqiang 32 Jul 26 2017 aarch64-linux-gcov -> aarch64-cortexa53-linux-gnu-gcov*
lrwxrwxrwx. 1 zhangzhiqiang zhangzhiqiang 37 Jul 26 2017 aarch64-linux-gcov-dump -> aarch64-cortexa53-linux-gnu-gcov-dump*
lrwxrwxrwx. 1 zhangzhiqiang zhangzhiqiang 37 Jul 26 2017 aarch64-linux-gcov-tool -> aarch64-cortexa53-linux-gnu-gcov-tool*
lrwxrwxrwx. 1 zhangzhiqiang zhangzhiqiang 31 Jul 26 2017 aarch64-linux-gdb -> aarch64-cortexa53-linux-gnu-gdb*
lrwxrwxrwx. 1 zhangzhiqiang zhangzhiqiang 37 Jul 26 2017 aarch64-linux-gnu-addr2line -> aarch64-cortexa53-linux-gnu-addr2line*
lrwxrwxrwx. 1 zhangzhiqiang zhangzhiqiang 30 Jul 26 2017 aarch64-linux-gnu-ar -> aarch64-cortexa53-linux-gnu-ar*
lrwxrwxrwx. 1 zhangzhiqiang zhangzhiqiang 30 Jul 26 2017 aarch64-linux-gnu-as -> aarch64-cortexa53-linux-gnu-as*
lrwxrwxrwx. 1 zhangzhiqiang zhangzhiqiang 31 Jul 26 2017 aarch64-linux-gnu-c++ -> aarch64-cortexa53-linux-gnu-c++*
lrwxrwxrwx. 1 zhangzhiqiang zhangzhiqiang 30 Jul 26 2017 aarch64-linux-gnu-cc -> aarch64-cortexa53-linux-gnu-cc*
lrwxrwxrwx. 1 zhangzhiqiang zhangzhiqiang 35 Jul 26 2017 aarch64-linux-gnu-c++filt -> aarch64-cortexa53-linux-gnu-c++filt*
lrwxrwxrwx. 1 zhangzhiqiang zhangzhiqiang 31 Jul 26 2017 aarch64-linux-gnu-cpp -> aarch64-cortexa53-linux-gnu-cpp*
lrwxrwxrwx. 1 zhangzhiqiang zhangzhiqiang 31 Jul 26 2017 aarch64-linux-gnu-dwp -> aarch64-cortexa53-linux-gnu-dwp*
lrwxrwxrwx. 1 zhangzhiqiang zhangzhiqiang 35 Jul 26 2017 aarch64-linux-gnu-elfedit -> aarch64-cortexa53-linux-gnu-elfedit*
lrwxrwxrwx. 1 zhangzhiqiang zhangzhiqiang 31 Jul 26 2017 aarch64-linux-gnu-g++ -> aarch64-cortexa53-linux-gnu-g++*
lrwxrwxrwx. 1 zhangzhiqiang zhangzhiqiang 31 Jul 26 2017 aarch64-linux-gnu-gcc -> aarch64-cortexa53-linux-gnu-gcc*
lrwxrwxrwx. 1 zhangzhiqiang zhangzhiqiang 37 Jul 26 2017 aarch64-linux-gnu-gcc-6.4.0 -> aarch64-cortexa53-linux-gnu-gcc-6.4.0*
lrwxrwxrwx. 1 zhangzhiqiang zhangzhiqiang 34 Jul 26 2017 aarch64-linux-gnu-gcc-ar -> aarch64-cortexa53-linux-gnu-gcc-ar*
lrwxrwxrwx. 1 zhangzhiqiang zhangzhiqiang 34 Jul 26 2017 aarch64-linux-gnu-gcc-nm -> aarch64-cortexa53-linux-gnu-gcc-nm*
lrwxrwxrwx. 1 zhangzhiqiang zhangzhiqiang 38 Jul 26 2017 aarch64-linux-gnu-gcc-ranlib -> aarch64-cortexa53-linux-gnu-gcc-ranlib*
lrwxrwxrwx. 1 zhangzhiqiang zhangzhiqiang 32 Jul 26 2017 aarch64-linux-gnu-gcov -> aarch64-cortexa53-linux-gnu-gcov*
lrwxrwxrwx. 1 zhangzhiqiang zhangzhiqiang 37 Jul 26 2017 aarch64-linux-gnu-gcov-dump -> aarch64-cortexa53-linux-gnu-gcov-dump*
lrwxrwxrwx. 1 zhangzhiqiang zhangzhiqiang 37 Jul 26 2017 aarch64-linux-gnu-gcov-tool -> aarch64-cortexa53-linux-gnu-gcov-tool*
lrwxrwxrwx. 1 zhangzhiqiang zhangzhiqiang 31 Jul 26 2017 aarch64-linux-gnu-gdb -> aarch64-cortexa53-linux-gnu-gdb*
lrwxrwxrwx. 1 zhangzhiqiang zhangzhiqiang 33 Jul 26 2017 aarch64-linux-gnu-gprof -> aarch64-cortexa53-linux-gnu-gprof*
lrwxrwxrwx. 1 zhangzhiqiang zhangzhiqiang 30 Jul 26 2017 aarch64-linux-gnu-ld -> aarch64-cortexa53-linux-gnu-ld*
lrwxrwxrwx. 1 zhangzhiqiang zhangzhiqiang 34 Jul 26 2017 aarch64-linux-gnu-ld.bfd -> aarch64-cortexa53-linux-gnu-ld.bfd*
lrwxrwxrwx. 1 zhangzhiqiang zhangzhiqiang 31 Jul 26 2017 aarch64-linux-gnu-ldd -> aarch64-cortexa53-linux-gnu-ldd*
lrwxrwxrwx. 1 zhangzhiqiang zhangzhiqiang 35 Jul 26 2017 aarch64-linux-gnu-ld.gold -> aarch64-cortexa53-linux-gnu-ld.gold*
lrwxrwxrwx. 1 zhangzhiqiang zhangzhiqiang 30 Jul 26 2017 aarch64-linux-gnu-nm -> aarch64-cortexa53-linux-gnu-nm*
lrwxrwxrwx. 1 zhangzhiqiang zhangzhiqiang 35 Jul 26 2017 aarch64-linux-gnu-objcopy -> aarch64-cortexa53-linux-gnu-objcopy*
lrwxrwxrwx. 1 zhangzhiqiang zhangzhiqiang 35 Jul 26 2017 aarch64-linux-gnu-objdump -> aarch64-cortexa53-linux-gnu-objdump*
lrwxrwxrwx. 1 zhangzhiqiang zhangzhiqiang 36 Jul 26 2017 aarch64-linux-gnu-populate -> aarch64-cortexa53-linux-gnu-populate*
lrwxrwxrwx. 1 zhangzhiqiang zhangzhiqiang 34 Jul 26 2017 aarch64-linux-gnu-ranlib -> aarch64-cortexa53-linux-gnu-ranlib*
lrwxrwxrwx. 1 zhangzhiqiang zhangzhiqiang 35 Jul 26 2017 aarch64-linux-gnu-readelf -> aarch64-cortexa53-linux-gnu-readelf*
lrwxrwxrwx. 1 zhangzhiqiang zhangzhiqiang 32 Jul 26 2017 aarch64-linux-gnu-size -> aarch64-cortexa53-linux-gnu-size*
lrwxrwxrwx. 1 zhangzhiqiang zhangzhiqiang 35 Jul 26 2017 aarch64-linux-gnu-strings -> aarch64-cortexa53-linux-gnu-strings*
lrwxrwxrwx. 1 zhangzhiqiang zhangzhiqiang 33 Jul 26 2017 aarch64-linux-gnu-strip -> aarch64-cortexa53-linux-gnu-strip*
lrwxrwxrwx. 1 zhangzhiqiang zhangzhiqiang 33 Jul 26 2017 aarch64-linux-gprof -> aarch64-cortexa53-linux-gnu-gprof*
lrwxrwxrwx. 1 zhangzhiqiang zhangzhiqiang 30 Jul 26 2017 aarch64-linux-ld -> aarch64-cortexa53-linux-gnu-ld*
lrwxrwxrwx. 1 zhangzhiqiang zhangzhiqiang 34 Jul 26 2017 aarch64-linux-ld.bfd -> aarch64-cortexa53-linux-gnu-ld.bfd*
lrwxrwxrwx. 1 zhangzhiqiang zhangzhiqiang 31 Jul 26 2017 aarch64-linux-ldd -> aarch64-cortexa53-linux-gnu-ldd*
lrwxrwxrwx. 1 zhangzhiqiang zhangzhiqiang 35 Jul 26 2017 aarch64-linux-ld.gold -> aarch64-cortexa53-linux-gnu-ld.gold*
lrwxrwxrwx. 1 zhangzhiqiang zhangzhiqiang 30 Jul 26 2017 aarch64-linux-nm -> aarch64-cortexa53-linux-gnu-nm*
lrwxrwxrwx. 1 zhangzhiqiang zhangzhiqiang 35 Jul 26 2017 aarch64-linux-objcopy -> aarch64-cortexa53-linux-gnu-objcopy*
lrwxrwxrwx. 1 zhangzhiqiang zhangzhiqiang 35 Jul 26 2017 aarch64-linux-objdump -> aarch64-cortexa53-linux-gnu-objdump*
lrwxrwxrwx. 1 zhangzhiqiang zhangzhiqiang 36 Jul 26 2017 aarch64-linux-populate -> aarch64-cortexa53-linux-gnu-populate*
lrwxrwxrwx. 1 zhangzhiqiang zhangzhiqiang 34 Jul 26 2017 aarch64-linux-ranlib -> aarch64-cortexa53-linux-gnu-ranlib*
lrwxrwxrwx. 1 zhangzhiqiang zhangzhiqiang 35 Jul 26 2017 aarch64-linux-readelf -> aarch64-cortexa53-linux-gnu-readelf*
lrwxrwxrwx. 1 zhangzhiqiang zhangzhiqiang 32 Jul 26 2017 aarch64-linux-size -> aarch64-cortexa53-linux-gnu-size*
lrwxrwxrwx. 1 zhangzhiqiang zhangzhiqiang 35 Jul 26 2017 aarch64-linux-strings -> aarch64-cortexa53-linux-gnu-strings*
lrwxrwxrwx. 1 zhangzhiqiang zhangzhiqiang 33 Jul 26 2017 aarch64-linux-strip -> aarch64-cortexa53-linux-gnu-strip*
-r--r--r--. 1 zhangzhiqiang zhangzhiqiang 3808 Jul 26 2017 .manifest.gee02be3.sig.xz
$ cd ~
$ vim hello.c
输入:
#include
int main()
{
printf("hello world\n");
return 0;
}
#生成可执行文件
$ gcc -o helloX86 hello.c
$ file helloX86
helloX86: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.32, BuildID[sha1]=59a2233483bf4d0756eb65bc8df5d3f22224d640, not stripped
$ aarch64-linux-gcc -o helloArm hello.c
$ file helloArm
helloArm: ELF 64-bit LSB executable, ARM aarch64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 3.10.61, BuildID[sha1]=4d9ece90f68c0f8a7fac17dd001f27f8331a105c, not stripped
出现无法运行错误
部分交叉编译工具链是在32bit os制作的,移到64bit缺少相应的库支持
解决:
ubuntu
$ sudo apt install libc6:i386
$ sudo apt install lib32z1
一般用于查看ELF格式的文件信息,常见的文件如在Linux上的可执行文件,动态库(*.so)或者静态库(*.a) 等包含ELF格式的文件。
linux:ELF
windows:PE
#输出文件头信息
$ readelf -h file
$ readelf -h helloX86
ELF Header:
Magic: 7f 45 4c 46 02 01 01 00 00 00 00 00 00 00 00 00
Class: ELF64
Data: 2's complement, little endian
Version: 1 (current)
OS/ABI: UNIX - System V
ABI Version: 0
Type: EXEC (Executable file)
Machine: Advanced Micro Devices X86-64
Version: 0x1
Entry point address: 0x400430 #程序入口地址
Start of program headers: 64 (bytes into file)
Start of section headers: 6456 (bytes into file)
Flags: 0x0
Size of this header: 64 (bytes)
Size of program headers: 56 (bytes)
Number of program headers: 9
Size of section headers: 64 (bytes)
Number of section headers: 31
Section header string table index: 30
===================================================================================
$ aarch64-linux-readelf -h helloArm
ELF Header:
Magic: 7f 45 4c 46 02 01 01 00 00 00 00 00 00 00 00 00
Class: ELF64
Data: 2's complement, little endian
Version: 1 (current)
OS/ABI: UNIX - System V
ABI Version: 0
Type: EXEC (Executable file)
Machine: AArch64
Version: 0x1
Entry point address: 0x400470 #程序入口地址
Start of program headers: 64 (bytes into file)
Start of section headers: 11480 (bytes into file)
Flags: 0x0
Size of this header: 64 (bytes)
Size of program headers: 56 (bytes)
Number of program headers: 8
Size of section headers: 64 (bytes)
Number of section headers: 37
Section header string table index: 36
读取可执行程序的每个段的大小信息
$ size helloArm
输出:
text data bss dec hex filename
1123 576 8 1707 6ab helloArm
$ aarch64-linux-size helloX86
输出:
text data bss dec hex filename
1194 540 4 1738 6ca helloX86
查看可执行程序的符号表
$ nm helloX86
000000000060102c B __bss_start
000000000060102c b completed.6355
0000000000601028 D __data_start
0000000000601028 W data_start
0000000000400460 t deregister_tm_clones
00000000004004d0 t __do_global_dtors_aux
0000000000600e18 t __do_global_dtors_aux_fini_array_entry
00000000004005c8 R __dso_handle
0000000000600e28 d _DYNAMIC
000000000060102c D _edata
0000000000601030 B _end
00000000004005b4 T _fini
00000000004004f0 t frame_dummy
0000000000600e10 t __frame_dummy_init_array_entry
0000000000400700 r __FRAME_END__
0000000000601000 d _GLOBAL_OFFSET_TABLE_
w __gmon_start__
00000000004005dc r __GNU_EH_FRAME_HDR
00000000004003c8 T _init
0000000000600e18 t __init_array_end
0000000000600e10 t __init_array_start
00000000004005c0 R _IO_stdin_used
0000000000600e20 d __JCR_END__
0000000000600e20 d __JCR_LIST__
00000000004005b0 T __libc_csu_fini
0000000000400540 T __libc_csu_init
U __libc_start_main@@GLIBC_2.2.5
000000000040051d T main
U puts@@GLIBC_2.2.5
0000000000400490 t register_tm_clones
0000000000400430 T _start
0000000000601030 D __TMC_END__
T:全局函数标签
D:全局变量区
d:静态变量
t:静态函数
剔除符号表
$ file helloX86
helloX86: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.32, BuildID[sha1]=59a2233483bf4d0756eb65bc8df5d3f22224d640, not stripped
#not stripped:未剔除符号表
$ strip helloX86
$ file helloX86
helloX86: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.32, BuildID[sha1]=59a2233483bf4d0756eb65bc8df5d3f22224d640, stripped
$ nm helloX86
nm: helloX86: no symbols
查看可执行程序中的常量字符串
$ string helloX86
/lib64/ld-linux-x86-64.so.2
libc.so.6
puts
__libc_start_main
__gmon_start__
GLIBC_2.2.5
UH-0
UH-0
=(
[]A\A]A^A_
hello world
;*3$"
GCC: (GNU) 4.8.5 20150623 (Red Hat 4.8.5-36)
.shstrtab
.interp
.note.ABI-tag
.note.gnu.build-id
.gnu.hash
.dynsym
.dynstr
.gnu.version
.gnu.version_r
.rela.dyn
.rela.plt
.init
.plt.got
.text
.fini
.rodata
.eh_frame_hdr
.eh_frame
.init_array
.fini_array
.jcr
.dynamic
.got.plt
.data
.bss
.comment
反汇编,它以一种可阅读的格式让你更多地了解二进制文件可能带有的附加信息
$ objdump -d helloX86
helloX86: file format elf64-x86-64
Disassembly of section .init:
00000000004003c8 <.init>:
4003c8: 48 83 ec 08 sub $0x8,%rsp
4003cc: 48 8b 05 25 0c 20 00 mov 0x200c25(%rip),%rax # 600ff8 <__libc_start_main@plt+0x200be8>
4003d3: 48 85 c0 test %rax,%rax
4003d6: 74 05 je 4003dd
4003d8: e8 43 00 00 00 callq 400420 <__libc_start_main@plt+0x10>
4003dd: 48 83 c4 08 add $0x8,%rsp
4003e1: c3 retq
Disassembly of section .plt:
00000000004003f0 :
4003f0: ff 35 12 0c 20 00 pushq 0x200c12(%rip) # 601008 <__libc_start_main@plt+0x200bf8>
4003f6: ff 25 14 0c 20 00 jmpq *0x200c14(%rip) # 601010 <__libc_start_main@plt+0x200c00>
4003fc: 0f 1f 40 00 nopl 0x0(%rax)
0000000000400400 :
400400: ff 25 12 0c 20 00 jmpq *0x200c12(%rip) # 601018 <__libc_start_main@plt+0x200c08>
400406: 68 00 00 00 00 pushq $0x0
40040b: e9 e0 ff ff ff jmpq 4003f0
0000000000400410 <__libc_start_main@plt>:
400410: ff 25 0a 0c 20 00 jmpq *0x200c0a(%rip) # 601020 <__libc_start_main@plt+0x200c10>
400416: 68 01 00 00 00 pushq $0x1
40041b: e9 d0 ff ff ff jmpq 4003f0
Disassembly of section .plt.got:
0000000000400420 <.plt.got>:
400420: ff 25 d2 0b 20 00 jmpq *0x200bd2(%rip) # 600ff8 <__libc_start_main@plt+0x200be8>
400426: 66 90 xchg %ax,%ax
Disassembly of section .text:
0000000000400430 <.text>:
400430: 31 ed xor %ebp,%ebp
400432: 49 89 d1 mov %rdx,%r9
400435: 5e pop %rsi
400436: 48 89 e2 mov %rsp,%rdx
400439: 48 83 e4 f0 and $0xfffffffffffffff0,%rsp
40043d: 50 push %rax
40043e: 54 push %rsp
40043f: 49 c7 c0 b0 05 40 00 mov $0x4005b0,%r8
400446: 48 c7 c1 40 05 40 00 mov $0x400540,%rcx
40044d: 48 c7 c7 1d 05 40 00 mov $0x40051d,%rdi
400454: e8 b7 ff ff ff callq 400410 <__libc_start_main@plt>
400459: f4 hlt
40045a: 66 0f 1f 44 00 00 nopw 0x0(%rax,%rax,1)
400460: b8 37 10 60 00 mov $0x601037,%eax
400465: 55 push %rbp
400466: 48 2d 30 10 60 00 sub $0x601030,%rax
40046c: 48 83 f8 0e cmp $0xe,%rax
400470: 48 89 e5 mov %rsp,%rbp
400473: 77 02 ja 400477 <__libc_start_main@plt+0x67>
400475: 5d pop %rbp
400476: c3 retq
400477: b8 00 00 00 00 mov $0x0,%eax
40047c: 48 85 c0 test %rax,%rax
40047f: 74 f4 je 400475 <__libc_start_main@plt+0x65>
400481: 5d pop %rbp
400482: bf 30 10 60 00 mov $0x601030,%edi
400487: ff e0 jmpq *%rax
400489: 0f 1f 80 00 00 00 00 nopl 0x0(%rax)
400490: b8 30 10 60 00 mov $0x601030,%eax
400495: 55 push %rbp
400496: 48 2d 30 10 60 00 sub $0x601030,%rax
40049c: 48 c1 f8 03 sar $0x3,%rax
4004a0: 48 89 e5 mov %rsp,%rbp
4004a3: 48 89 c2 mov %rax,%rdx
4004a6: 48 c1 ea 3f shr $0x3f,%rdx
4004aa: 48 01 d0 add %rdx,%rax
4004ad: 48 d1 f8 sar %rax
4004b0: 75 02 jne 4004b4 <__libc_start_main@plt+0xa4>
4004b2: 5d pop %rbp
4004b3: c3 retq
4004b4: ba 00 00 00 00 mov $0x0,%edx
4004b9: 48 85 d2 test %rdx,%rdx
4004bc: 74 f4 je 4004b2 <__libc_start_main@plt+0xa2>
4004be: 5d pop %rbp
4004bf: 48 89 c6 mov %rax,%rsi
4004c2: bf 30 10 60 00 mov $0x601030,%edi
4004c7: ff e2 jmpq *%rdx
4004c9: 0f 1f 80 00 00 00 00 nopl 0x0(%rax)
4004d0: 80 3d 55 0b 20 00 00 cmpb $0x0,0x200b55(%rip) # 60102c <__libc_start_main@plt+0x200c1c>
4004d7: 75 11 jne 4004ea <__libc_start_main@plt+0xda>
4004d9: 55 push %rbp
4004da: 48 89 e5 mov %rsp,%rbp
4004dd: e8 7e ff ff ff callq 400460 <__libc_start_main@plt+0x50>
4004e2: 5d pop %rbp
4004e3: c6 05 42 0b 20 00 01 movb $0x1,0x200b42(%rip) # 60102c <__libc_start_main@plt+0x200c1c>
4004ea: f3 c3 repz retq
4004ec: 0f 1f 40 00 nopl 0x0(%rax)
4004f0: 48 83 3d 28 09 20 00 cmpq $0x0,0x200928(%rip) # 600e20 <__libc_start_main@plt+0x200a10>
4004f7: 00
4004f8: 74 1e je 400518 <__libc_start_main@plt+0x108>
4004fa: b8 00 00 00 00 mov $0x0,%eax
4004ff: 48 85 c0 test %rax,%rax
400502: 74 14 je 400518 <__libc_start_main@plt+0x108>
400504: 55 push %rbp
400505: bf 20 0e 60 00 mov $0x600e20,%edi
40050a: 48 89 e5 mov %rsp,%rbp
40050d: ff d0 callq *%rax
40050f: 5d pop %rbp
400510: e9 7b ff ff ff jmpq 400490 <__libc_start_main@plt+0x80>
400515: 0f 1f 00 nopl (%rax)
400518: e9 73 ff ff ff jmpq 400490 <__libc_start_main@plt+0x80>
40051d: 55 push %rbp
40051e: 48 89 e5 mov %rsp,%rbp
400521: bf d0 05 40 00 mov $0x4005d0,%edi
400526: e8 d5 fe ff ff callq 400400
40052b: b8 00 00 00 00 mov $0x0,%eax
400530: 5d pop %rbp
400531: c3 retq
400532: 66 2e 0f 1f 84 00 00 nopw %cs:0x0(%rax,%rax,1)
400539: 00 00 00
40053c: 0f 1f 40 00 nopl 0x0(%rax)
400540: 41 57 push %r15
400542: 41 89 ff mov %edi,%r15d
400545: 41 56 push %r14
400547: 49 89 f6 mov %rsi,%r14
40054a: 41 55 push %r13
40054c: 49 89 d5 mov %rdx,%r13
40054f: 41 54 push %r12
400551: 4c 8d 25 b8 08 20 00 lea 0x2008b8(%rip),%r12 # 600e10 <__libc_start_main@plt+0x200a00>
400558: 55 push %rbp
400559: 48 8d 2d b8 08 20 00 lea 0x2008b8(%rip),%rbp # 600e18 <__libc_start_main@plt+0x200a08>
400560: 53 push %rbx
400561: 4c 29 e5 sub %r12,%rbp
400564: 31 db xor %ebx,%ebx
400566: 48 c1 fd 03 sar $0x3,%rbp
40056a: 48 83 ec 08 sub $0x8,%rsp
40056e: e8 55 fe ff ff callq 4003c8
400573: 48 85 ed test %rbp,%rbp
400576: 74 1e je 400596 <__libc_start_main@plt+0x186>
400578: 0f 1f 84 00 00 00 00 nopl 0x0(%rax,%rax,1)
40057f: 00
400580: 4c 89 ea mov %r13,%rdx
400583: 4c 89 f6 mov %r14,%rsi
400586: 44 89 ff mov %r15d,%edi
400589: 41 ff 14 dc callq *(%r12,%rbx,8)
40058d: 48 83 c3 01 add $0x1,%rbx
400591: 48 39 eb cmp %rbp,%rbx
400594: 75 ea jne 400580 <__libc_start_main@plt+0x170>
400596: 48 83 c4 08 add $0x8,%rsp
40059a: 5b pop %rbx
40059b: 5d pop %rbp
40059c: 41 5c pop %r12
40059e: 41 5d pop %r13
4005a0: 41 5e pop %r14
4005a2: 41 5f pop %r15
4005a4: c3 retq
4005a5: 90 nop
4005a6: 66 2e 0f 1f 84 00 00 nopw %cs:0x0(%rax,%rax,1)
4005ad: 00 00 00
4005b0: f3 c3 repz retq
Disassembly of section .fini:
00000000004005b4 <.fini>:
4005b4: 48 83 ec 08 sub $0x8,%rsp
4005b8: 48 83 c4 08 add $0x8,%rsp
4005bc: c3 retq
把某些代码段、数据段按照相应的格式拷贝出来
调试工具
print #查看uboot集成的环境变量
变量名=变量值
===================================================
setenv、saveenv #设置/保存变量
setenv 变量名 变量值
setenv 变量名 #删除变量
saveenv 把本次设置的环境变量写回存储器
UBoot中的网络层设置:
ipaddr变量值 开发板ping主机 验证 alive:通过
===================================================
nand
nand erase/write/read [动词] [内存地址] [内部地址] [搬移大小]
nand中5M空间读到内存21000000,1K
nand read 21000000 500000 1024
(5M=5*1M
1M:2^20 二进制:1000···000 十六进制:0x100000)
nand erase 500000 1024
nand write 21000000 500000 1024
===================================================
tftp
验证传输层
C(开发板)/S(PC)
C:
./client server_ip port XXXXX
通过设置serverip变量
port:tftp固定
XXX:输入参数
S:
Linux
===================================================
bootm 启动内核
===================================================
go
设置bootargs参数
root = 启动的根文件系统在哪个设备
设备信息 RAM NFS FLASH
init = 内核启动后,第一个可执行文件init进程从哪来 它对应/sbin/init。显然,这个应用程序就要读取配置文件,根据配置文件去启动用户程序(监控、手册界面、平板界面等等)。这个问题提示我们,文件系统的内容是有一些约定的,比如要有/sbin/init,要有配置文件
console = 内核启动时,使用哪个设备作为控制台
#设置启动参数
setenv bootargs root=/dev/mtdblock2 init=/linuxrc console=ttySAC0,115200
通过物理介质与操作系统进行衔接
文件系统的烧写
===================================================================================
NFS(network file system)实际开发
TCP/IP
服务端:
$ sudo apt install nfs-kernel-server
$ sudo vim /etc/exports
客户端:
#挂载initrd.img到当前目录下的swap文件夹
$ sudo mount -t ext2 initrd.img ./swap/
#将挂载内容拷贝到当前目录
$ mkdir rootnfs
$ sudo cp -a ../swap/* ./
设置bootargs
root = /dev/nfs
nfsroot=192.168.10.110:/../../rootnfs
ip = 192.168.10.121
init = /linuxrc
console=ttySAC0,115200
setenv bootargs root= nfsroot= ip = init = console=
tftp 2000 8000 uImage
bootm 2000 8000
===================================================================================
Ramdisk
root = /dev/ram
initrd = 0x2100 0000,8M
init = /linuxrc
console = ttySAC0
测试:
内存 0x2000 8000 uImage
0x21000 0000 initrd.img.gz
$ pri #查看环境变量
$ setenv bootargs root = /dev/ram initrd = 0x2100 0000,8M init = /linuxrc console = ttySAC0
$ bootm 2000 8000
1、版本选择
ftp://ftp.denx.de/pub/u-boot/
$ wget ftp://ftp.denx.de/pub/u-boot/u-boot-2019.04.tar.bz2
$ tar -xjf u-boot-2019.04.tar.bz2
$ cd u-boot-2019.04/arch/arm/cpu/armv7
$ ls -alF
total 216
drwxr-xr-x@ 33 zhangzhiqiang staff 1.0K Apr 9 09:40 ./
drwxr-xr-x@ 17 zhangzhiqiang staff 544B Apr 9 09:40 ../
-rw-r--r--@ 1 zhangzhiqiang staff 1.6K Apr 9 09:40 Kconfig
-rw-r--r--@ 1 zhangzhiqiang staff 1.2K Apr 9 09:40 Makefile
-rw-r--r--@ 1 zhangzhiqiang staff 994B Apr 9 09:40 arch_timer.c
drwxr-xr-x@ 10 zhangzhiqiang staff 320B Apr 9 09:40 bcm235xx/
drwxr-xr-x@ 11 zhangzhiqiang staff 352B Apr 9 09:40 bcm281xx/
drwxr-xr-x@ 4 zhangzhiqiang staff 128B Apr 9 09:40 bcmcygnus/
drwxr-xr-x@ 4 zhangzhiqiang staff 128B Apr 9 09:40 bcmnsp/
-rw-r--r--@ 1 zhangzhiqiang staff 4.8K Apr 9 09:40 cache_v7.c
-rw-r--r--@ 1 zhangzhiqiang staff 5.0K Apr 9 09:40 cache_v7_asm.S
-rw-r--r--@ 1 zhangzhiqiang staff 467B Apr 9 09:40 config.mk
-rw-r--r--@ 1 zhangzhiqiang staff 635B Apr 9 09:40 cp15.c
-rw-r--r--@ 1 zhangzhiqiang staff 1.8K Apr 9 09:40 cpu.c
-rw-r--r--@ 1 zhangzhiqiang staff 1.5K Apr 9 09:40 exception_level.c
drwxr-xr-x@ 6 zhangzhiqiang staff 192B Apr 9 09:40 iproc-common/
drwxr-xr-x@ 7 zhangzhiqiang staff 224B Apr 9 09:40 kona-common/
-rw-r--r--@ 1 zhangzhiqiang staff 1.5K Apr 9 09:40 lowlevel_init.S
drwxr-xr-x@ 17 zhangzhiqiang staff 544B Apr 9 09:40 ls102xa/
-rw-r--r--@ 1 zhangzhiqiang staff 2.6K Apr 9 09:40 mpu_v7r.c
-rw-r--r--@ 1 zhangzhiqiang staff 5.5K Apr 9 09:40 nonsec_virt.S
-rw-r--r--@ 1 zhangzhiqiang staff 1.2K Apr 9 09:40 psci-common.c
-rw-r--r--@ 1 zhangzhiqiang staff 8.9K Apr 9 09:40 psci.S
drwxr-xr-x@ 7 zhangzhiqiang staff 224B Apr 9 09:40 s5p-common/
-rw-r--r--@ 1 zhangzhiqiang staff 648B Apr 9 09:40 sctlr.S
-rw-r--r--@ 1 zhangzhiqiang staff 1.2K Apr 9 09:40 smccc-call.S
-rw-r--r--@ 1 zhangzhiqiang staff 10K Apr 9 09:40 start.S #U-boot的总入口
drwxr-xr-x@ 8 zhangzhiqiang staff 256B Apr 9 09:40 stv0991/
drwxr-xr-x@ 9 zhangzhiqiang staff 288B Apr 9 09:40 sunxi/
-rw-r--r--@ 1 zhangzhiqiang staff 1.2K Apr 9 09:40 syslib.c
drwxr-xr-x@ 6 zhangzhiqiang staff 192B Apr 9 09:40 vf610/
-rw-r--r--@ 1 zhangzhiqiang staff 2.1K Apr 9 09:40 virt-dt.c
-rw-r--r--@ 1 zhangzhiqiang staff 3.7K Apr 9 09:40 virt-v7.c
$ cd u-boot-2019.04/board/samsung
$ ls -alF
total 0
drwxr-xr-x@ 15 zhangzhiqiang staff 480B Apr 9 09:40 ./
drwxr-xr-x@ 196 zhangzhiqiang staff 6.1K Apr 9 09:40 ../
drwxr-xr-x@ 7 zhangzhiqiang staff 224B Apr 9 09:40 arndale/
drwxr-xr-x@ 11 zhangzhiqiang staff 352B Apr 9 09:40 common/
drwxr-xr-x@ 6 zhangzhiqiang staff 192B Apr 9 09:40 espresso7420/
drwxr-xr-x@ 8 zhangzhiqiang staff 256B Apr 9 09:40 goni/
drwxr-xr-x@ 7 zhangzhiqiang staff 224B Apr 9 09:40 odroid/
drwxr-xr-x@ 7 zhangzhiqiang staff 224B Apr 9 09:40 origen/
drwxr-xr-x@ 6 zhangzhiqiang staff 192B Apr 9 09:40 smdk5250/
drwxr-xr-x@ 6 zhangzhiqiang staff 192B Apr 9 09:40 smdk5420/
drwxr-xr-x@ 8 zhangzhiqiang staff 256B Apr 9 09:40 smdkc100/
drwxr-xr-x@ 7 zhangzhiqiang staff 224B Apr 9 09:40 smdkv310/
drwxr-xr-x@ 7 zhangzhiqiang staff 224B Apr 9 09:40 trats/
drwxr-xr-x@ 6 zhangzhiqiang staff 192B Apr 9 09:40 trats2/
drwxr-xr-x@ 7 zhangzhiqiang staff 224B Apr 9 09:40 universal_c210/
$ cd u-boot-2019.04/arch/arm/cpu/armv7
$ vim start.S
编译:预编译(Precompile)➡️ 编译(Compile)➡️ 汇编(Assemble)➡️ 链接(Link)➡️ 生成二进制文件(obidump).bin
#下载
$ wget https://cdn.kernel.org/pub/linux/kernel/v5.x/linux-5.2.tar.xz
#解压
$ tar -xvJf linux-5.2.tar.xz
$ cd linux-5.2
$ ls -alF
total 832
drwxrwxr-x. 24 zhangzhiqiang zhangzhiqiang 4096 Jul 8 06:41 ./
drwxrwxr-x. 3 zhangzhiqiang zhangzhiqiang 4096 Jul 10 09:52 ../
drwxrwxr-x. 27 zhangzhiqiang zhangzhiqiang 4096 Jul 8 06:41 arch/ #architecture
drwxrwxr-x. 3 zhangzhiqiang zhangzhiqiang 4096 Jul 8 06:41 block/
drwxrwxr-x. 2 zhangzhiqiang zhangzhiqiang 4096 Jul 8 06:41 certs/
-rw-rw-r--. 1 zhangzhiqiang zhangzhiqiang 14943 Jul 8 06:41 .clang-format
-rw-rw-r--. 1 zhangzhiqiang zhangzhiqiang 59 Jul 8 06:41 .cocciconfig
-rw-rw-r--. 1 zhangzhiqiang zhangzhiqiang 423 Jul 8 06:41 COPYING
-rw-rw-r--. 1 zhangzhiqiang zhangzhiqiang 99486 Jul 8 06:41 CREDITS
drwxrwxr-x. 4 zhangzhiqiang zhangzhiqiang 4096 Jul 8 06:41 crypto/
drwxrwxr-x. 122 zhangzhiqiang zhangzhiqiang 4096 Jul 8 06:41 Documentation/
drwxrwxr-x. 140 zhangzhiqiang zhangzhiqiang 4096 Jul 8 06:41 drivers/
drwxrwxr-x. 73 zhangzhiqiang zhangzhiqiang 4096 Jul 8 06:41 fs/ #fileSystem
-rw-rw-r--. 1 zhangzhiqiang zhangzhiqiang 71 Jul 8 06:41 .get_maintainer.ignore
-rw-rw-r--. 1 zhangzhiqiang zhangzhiqiang 30 Jul 8 06:41 .gitattributes
-rw-rw-r--. 1 zhangzhiqiang zhangzhiqiang 1658 Jul 8 06:41 .gitignore
drwxrwxr-x. 27 zhangzhiqiang zhangzhiqiang 4096 Jul 8 06:41 include/
drwxrwxr-x. 2 zhangzhiqiang zhangzhiqiang 4096 Jul 8 06:41 init/
drwxrwxr-x. 2 zhangzhiqiang zhangzhiqiang 4096 Jul 8 06:41 ipc/
-rw-rw-r--. 1 zhangzhiqiang zhangzhiqiang 1513 Jul 8 06:41 Kbuild
-rw-rw-r--. 1 zhangzhiqiang zhangzhiqiang 563 Jul 8 06:41 Kconfig
drwxrwxr-x. 18 zhangzhiqiang zhangzhiqiang 4096 Jul 8 06:41 kernel/
drwxrwxr-x. 15 zhangzhiqiang zhangzhiqiang 12288 Jul 8 06:41 lib/
drwxrwxr-x. 6 zhangzhiqiang zhangzhiqiang 4096 Jul 8 06:41 LICENSES/
-rw-rw-r--. 1 zhangzhiqiang zhangzhiqiang 12316 Jul 8 06:41 .mailmap
-rw-rw-r--. 1 zhangzhiqiang zhangzhiqiang 512407 Jul 8 06:41 MAINTAINERS
-rw-rw-r--. 1 zhangzhiqiang zhangzhiqiang 60201 Jul 8 06:41 Makefile
drwxrwxr-x. 3 zhangzhiqiang zhangzhiqiang 4096 Jul 8 06:41 mm/ #memoryManager
drwxrwxr-x. 70 zhangzhiqiang zhangzhiqiang 4096 Jul 8 06:41 net/
-rw-rw-r--. 1 zhangzhiqiang zhangzhiqiang 727 Jul 8 06:41 README
drwxrwxr-x. 29 zhangzhiqiang zhangzhiqiang 4096 Jul 8 06:41 samples/
drwxrwxr-x. 15 zhangzhiqiang zhangzhiqiang 4096 Jul 8 06:41 scripts/
drwxrwxr-x. 11 zhangzhiqiang zhangzhiqiang 4096 Jul 8 06:41 security/
drwxrwxr-x. 26 zhangzhiqiang zhangzhiqiang 4096 Jul 8 06:41 sound/
drwxrwxr-x. 36 zhangzhiqiang zhangzhiqiang 4096 Jul 8 06:41 tools/
drwxrwxr-x. 2 zhangzhiqiang zhangzhiqiang 4096 Jul 8 06:41 usr/
drwxrwxr-x. 4 zhangzhiqiang zhangzhiqiang 4096 Jul 8 06:41 virt/
#创建索引 ctags(Generate tag files for source code)
$ ctags -R .
#查看大小
$ du -sh tags
$ vim -t 函数名
$ make menuconfig
$ make
$ vim include/config/auto.conf --> ./.config
$ vim include/generated/autoconf.h