RISCV学习(2)玄铁C910处理器体验
笔者有幸参加了平头哥RISCV开发者大赛,体验了一下基于玄铁C910内核的矽速开发板。
1、开发板介绍
LicheePi 4A 是基于 Lichee Module 4A 核心板的 高性能 RISC-V Linux 开发板。
- TH1520 为主控核心(4xC910@1.85G, RV64GCV,4TOPS@int8 NPU, 50GFLOP GPU)
- 板载最大 16GB 64bit LPDDR4X,128GB eMMC,
- 支持 HDMI+MIPI 双4K 显示输出,
- 支持 4K 摄像头接入,
- 支持双千兆网口(其中一个支持POE供电)
- 4 个 USB3.0 接口,
- 多种音频输入输出(由专用 C906 核心处理)。-
2、GCC工具链使用
GCC的工具链安装,参考Licheepi GCC工具链安装。
- 查看gcc的工具链版本
root@lpi4a:~# gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/riscv64-linux-gnu/10/lto-wrapper
Target: riscv64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Debian 10.4.0-8revyos2.4' --with-bugurl=file:///usr/share/doc/gcc-10/README.Bugs --enable-languages=c,ada,c++,go,d,fortran,objc,obj-c++,m2 --prefix=/usr --with-gcc-major-version-only --program-suffix=-10 --program-prefix=riscv64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-libitm --disable-libsanitizer --disable-libquadmath --disable-libquadmath-support --enable-plugin --enable-default-pie --with-system-zlib --enable-libphobos-checking=release --with-target-system-zlib=auto --enable-objc-gc=auto --enable-multiarch --disable-werror --disable-multilib --with-arch=rv64gcv0p7_zfh_xtheadc --with-abi=lp64d --enable-checking=release --build=riscv64-linux-gnu --host=riscv64-linux-gnu --target=riscv64-linux-gnu
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 10.4.0 (Debian 10.4.0-8revyos2.4)
- 直接编译hello.c程序,提示需要设置xthreadc的版本,其实并不知道如何处理,经过查资料后发现,需要指明架构和二进制接口版本
gcc hello.c
Assembler messages:
Error: x ISA extension `xtheadc' must be set with the versions
- 然后根据提示指明了架构,发现对应的头文件找不到,怀疑工具链没安装对,重新安装了,但是依然没什么用,之后又重启了,还是不行,看来还得继续找问题。
gcc hello.c -march=rv64imc
In file included from /usr/include/features.h:513,from /usr/include/riscv64-linux-gnu/bits/libc-header-start.h:33,from /usr/include/stdio.h:27,from hello.c:1:
/usr/include/riscv64-linux-gnu/gnu/stubs.h:14:11: fatal error: gnu/stubs-lp64.h: No such file or directory14 | # include <gnu/stubs-lp64.h>
- 然后就看一下该文件的内容,以及去该目录下面搜索了有哪些文件
root@lpi4a:~# ls /usr/include/riscv64-linux-gnu/gnu/stubs.h
/usr/include/riscv64-linux-gnu/gnu/stubs.h
root@lpi4a:~# cat /usr/include/riscv64-linux-gnu/gnu/stubs.h
/* This file is automatically generated.This file selects the right generated file of `__stub_FUNCTION' macrosbased on the architecture being compiled for. */#include <bits/wordsize.h>#if __WORDSIZE == 32 && defined __riscv_float_abi_soft
# include <gnu/stubs-ilp32.h>
#endif
#if __WORDSIZE == 32 && defined __riscv_float_abi_double
# include <gnu/stubs-ilp32d.h>
#endif
#if __WORDSIZE == 64 && defined __riscv_float_abi_soft
# include <gnu/stubs-lp64.h>
#endif
#if __WORDSIZE == 64 && defined __riscv_float_abi_double
# include <gnu/stubs-lp64d.h>
#endif
ls /usr/include/riscv64-linux-gnu/gnu/
lib-names-lp64d.h lib-names.h libc-version.h stubs-lp64d.h stubs.h
- 看到这里就突然知道,需要指明对应的版本,不然相应的头文件找不到,果然和常规的GCC工具链使用还是有区别,增加了相应的abl版本后,发现march也需要版本,
gcc hello.c -march=rv64imc -mabi=lp64d
cc1: error: requested ABI requires '-march' to subsume the 'D' extension
- 在架构方面增加了d,发现还是不对,提示第一个指令集是e/i/g,还得修改
gcc hello.c -march=rv64dimc -mabi=lp64d
gcc: error: '-march=rv64dimc': first ISA subset must be 'e', 'i' or 'g'
- 然后修改了abl的,改成了e,发现abl的版本里面没有这个,必须是lp64d,所以又得改回去
gcc hello.c -march=rv64imc -mabi=lp64e
gcc: error: unrecognized argument in option '-mabi=lp64e'
gcc: note: valid arguments to '-mabi=' are: ilp32 ilp32d ilp32e ilp32f lp64 lp64d lp64dv lp64f lp64v; did you mean 'lp64'?
- 最后在march指令集的后面增加d,可以了,终于gcc工具链可以正常使用了。
root@lpi4a:~# gcc hello.c -march=rv64imafd -mabi=lp64d
root@lpi4a:~#
- readelf工具可以查看其out文件信息,RISC-V的machine的64位机器版本
root@lpi4a:~# readelf -a a.out
ELF Header:Magic: 7f 45 4c 46 02 01 01 00 00 00 00 00 00 00 00 00Class: ELF64Data: 2's complement, little endianVersion: 1 (current)OS/ABI: UNIX - System VABI Version: 0Type: DYN (Position-Independent Executable file)Machine: RISC-VVersion: 0x1Entry point address: 0x5b0Start of program headers: 64 (bytes into file)Start of section headers: 7168 (bytes into file)Flags: 0x5, RVC, double-float ABISize of this header: 64 (bytes)Size of program headers: 56 (bytes)Number of program headers: 10Size of section headers: 64 (bytes)Number of section headers: 28Section header string table index: 27
- 再看看其他Section、Segment等信息
Section Headers:[Nr] Name Type Address OffsetSize EntSize Flags Link Info Align[ 0] NULL 0000000000000000 000000000000000000000000 0000000000000000 0 0 0[ 1] .interp PROGBITS 0000000000000270 000002700000000000000021 0000000000000000 A 0 0 1[ 2] .note.gnu.bu[...] NOTE 0000000000000294 000002940000000000000024 0000000000000000 A 0 0 4[ 3] .note.ABI-tag NOTE 00000000000002b8 000002b80000000000000020 0000000000000000 A 0 0 4[ 4] .gnu.hash GNU_HASH 00000000000002d8 000002d80000000000000024 0000000000000000 A 5 0 8[ 5] .dynsym DYNSYM 0000000000000300 0000030000000000000000c0 0000000000000018 A 6 2 8[ 6] .dynstr STRTAB 00000000000003c0 000003c0000000000000007d 0000000000000000 A 0 0 1[ 7] .gnu.version VERSYM 000000000000043e 0000043e0000000000000010 0000000000000002 A 5 0 2[ 8] .gnu.version_r VERNEED 0000000000000450 000004500000000000000030 0000000000000000 A 6 1 8[ 9] .rela.dyn RELA 0000000000000480 0000048000000000000000c0 0000000000000018 A 5 0 8[10] .rela.plt RELA 0000000000000540 000005400000000000000030 0000000000000018 AI 5 21 8[11] .plt PROGBITS 0000000000000570 000005700000000000000040 0000000000000010 AX 0 0 16[12] .text PROGBITS 00000000000005b0 000005b00000000000000108 0000000000000000 AX 0 0 16[13] .rodata PROGBITS 00000000000006b8 000006b80000000000000015 0000000000000000 A 0 0 8[14] .eh_frame_hdr PROGBITS 00000000000006d0 000006d00000000000000014 0000000000000000 A 0 0 4[15] .eh_frame PROGBITS 00000000000006e8 000006e8000000000000002c 0000000000000000 A 0 0 8[16] .preinit_array PREINIT_ARRAY 0000000000001e08 00000e080000000000000008 0000000000000008 WA 0 0 1[17] .init_array INIT_ARRAY 0000000000001e10 00000e100000000000000008 0000000000000008 WA 0 0 8[18] .fini_array FINI_ARRAY 0000000000001e18 00000e180000000000000008 0000000000000008 WA 0 0 8[19] .dynamic DYNAMIC 0000000000001e20 00000e2000000000000001e0 0000000000000010 WA 6 0 8[20] .data PROGBITS 0000000000002000 000010000000000000000008 0000000000000000 WA 0 0 8[21] .got PROGBITS 0000000000002008 000010080000000000000048 0000000000000008 WA 0 0 8[22] .bss NOBITS 0000000000002050 000010500000000000000008 0000000000000000 WA 0 0 1[23] ment PROGBITS 0000000000000000 000010500000000000000027 0000000000000001 MS 0 0 1[24] .riscv.attributes RISCV_ATTRIBUTE 0000000000000000 000010770000000000000106 0000000000000000 0 0 1[25] .symtab SYMTAB 0000000000000000 000011800000000000000630 0000000000000018 26 47 8[26] .strtab STRTAB 0000000000000000 000017b0000000000000033c 0000000000000000 0 0 1[27] .shstrtab STRTAB 0000000000000000 00001aec000000000000010f 0000000000000000 0 0 1
Key to Flags:W (write), A (alloc), X (execute), M (merge), S (strings), I (info),L (link order), O (extra OS processing required), G (group), T (TLS),C (compressed), x (unknown), o (OS specific), E (exclude),D (mbind), p (processor specific)There are no section groups in this file.Program Headers:Type Offset VirtAddr PhysAddrFileSiz MemSiz Flags AlignPHDR 0x0000000000000040 0x0000000000000040 0x00000000000000400x0000000000000230 0x0000000000000230 R 0x8INTERP 0x0000000000000270 0x0000000000000270 0x00000000000002700x0000000000000021 0x0000000000000021 R 0x1[Requesting program interpreter: /lib/ld-linux-riscv64-lp64d.so.1]RISCV_ATTRIBUT 0x0000000000001077 0x0000000000000000 0x00000000000000000x0000000000000106 0x0000000000000000 R 0x1LOAD 0x0000000000000000 0x0000000000000000 0x00000000000000000x0000000000000714 0x0000000000000714 R E 0x1000LOAD 0x0000000000000e08 0x0000000000001e08 0x0000000000001e080x0000000000000248 0x0000000000000250 RW 0x1000DYNAMIC 0x0000000000000e20 0x0000000000001e20 0x0000000000001e200x00000000000001e0 0x00000000000001e0 RW 0x8NOTE 0x0000000000000294 0x0000000000000294 0x00000000000002940x0000000000000044 0x0000000000000044 R 0x4GNU_EH_FRAME 0x00000000000006d0 0x00000000000006d0 0x00000000000006d00x0000000000000014 0x0000000000000014 R 0x4GNU_STACK 0x0000000000000000 0x0000000000000000 0x00000000000000000x0000000000000000 0x0000000000000000 RW 0x10GNU_RELRO 0x0000000000000e08 0x0000000000001e08 0x0000000000001e080x00000000000001f8 0x00000000000001f8 R 0x1Section to Segment mapping:Segment Sections...0001 .interp02 .riscv.attributes03 .interp .note.gnu.build-id .note.ABI-tag .gnu.hash .dynsym .dynstr .gnu.version .gnu.version_r .rela.dyn .rela.plt .plt .text .rodata .eh_frame_hdr .eh_frame04 .preinit_array .init_array .fini_array .dynamic .data .got .bss05 .dynamic06 .note.gnu.build-id .note.ABI-tag07 .eh_frame_hdr0809 .preinit_array .init_array .fini_array .dynamicDynamic section at offset 0xe20 contains 26 entries:Tag Type Name/Value0x0000000000000001 (NEEDED) Shared library: [libc.so.6]0x0000000000000020 (PREINIT_ARRAY) 0x1e080x0000000000000021 (PREINIT_ARRAYSZ) 8 (bytes)0x0000000000000019 (INIT_ARRAY) 0x1e100x000000000000001b (INIT_ARRAYSZ) 8 (bytes)0x000000000000001a (FINI_ARRAY) 0x1e180x000000000000001c (FINI_ARRAYSZ) 8 (bytes)0x000000006ffffef5 (GNU_HASH) 0x2d80x0000000000000005 (STRTAB) 0x3c00x0000000000000006 (SYMTAB) 0x3000x000000000000000a (STRSZ) 125 (bytes)0x000000000000000b (SYMENT) 24 (bytes)0x0000000000000015 (DEBUG) 0x00x0000000000000003 (PLTGOT) 0x20080x0000000000000002 (PLTRELSZ) 48 (bytes)0x0000000000000014 (PLTREL) RELA0x0000000000000017 (JMPREL) 0x5400x0000000000000007 (RELA) 0x4800x0000000000000008 (RELASZ) 240 (bytes)0x0000000000000009 (RELAENT) 24 (bytes)0x000000006ffffffb (FLAGS_1) Flags: PIE0x000000006ffffffe (VERNEED) 0x4500x000000006fffffff (VERNEEDNUM) 10x000000006ffffff0 (VERSYM) 0x43e0x000000006ffffff9 (RELACOUNT) 50x0000000000000000 (NULL) 0x0Relocation section '.rela.dyn' at offset 0x480 contains 8 entries:Offset Info Type Sym. Value Sym. Name + Addend
000000001e08 000000000003 R_RISCV_RELATIVE 5d2
000000001e10 000000000003 R_RISCV_RELATIVE 680
000000001e18 000000000003 R_RISCV_RELATIVE 640
000000002000 000000000003 R_RISCV_RELATIVE 2000
000000002038 000000000003 R_RISCV_RELATIVE 684
000000002030 000300000002 R_RISCV_64 0000000000000000 _ITM_deregisterTM[...] + 0
000000002040 000500000002 R_RISCV_64 0000000000000000 __cxa_finalize@GLIBC_2.27 + 0
000000002048 000600000002 R_RISCV_64 0000000000000000 _ITM_registerTMCl[...] + 0Relocation section '.rela.plt' at offset 0x540 contains 2 entries:Offset Info Type Sym. Value Sym. Name + Addend
000000002018 000200000005 R_RISCV_JUMP_SLOT 0000000000000000 __libc_start_main@GLIBC_2.34 + 0
000000002020 000400000005 R_RISCV_JUMP_SLOT 0000000000000000 puts@GLIBC_2.27 + 0The decoding of unwind sections for machine type RISC-V is not currently supported.Symbol table '.dynsym' contains 8 entries:Num: Value Size Type Bind Vis Ndx Name0: 0000000000000000 0 NOTYPE LOCAL DEFAULT UND1: 00000000000005b0 0 SECTION LOCAL DEFAULT 12 .text2: 0000000000000000 0 FUNC GLOBAL DEFAULT UND _[...]@GLIBC_2.34 (2)3: 0000000000000000 0 NOTYPE WEAK DEFAULT UND _ITM_deregisterT[...]4: 0000000000000000 0 FUNC GLOBAL DEFAULT UND puts@GLIBC_2.27 (3)5: 0000000000000000 0 FUNC WEAK DEFAULT UND _[...]@GLIBC_2.27 (3)6: 0000000000000000 0 NOTYPE WEAK DEFAULT UND _ITM_registerTMC[...]7: 0000000000000684 52 FUNC GLOBAL DEFAULT 12 mainSymbol table '.symtab' contains 66 entries:Num: Value Size Type Bind Vis Ndx Name0: 0000000000000000 0 NOTYPE LOCAL DEFAULT UND1: 0000000000000270 0 SECTION LOCAL DEFAULT 1 .interp2: 0000000000000294 0 SECTION LOCAL DEFAULT 2 .note.gnu.build-id3: 00000000000002b8 0 SECTION LOCAL DEFAULT 3 .note.ABI-tag4: 00000000000002d8 0 SECTION LOCAL DEFAULT 4 .gnu.hash5: 0000000000000300 0 SECTION LOCAL DEFAULT 5 .dynsym6: 00000000000003c0 0 SECTION LOCAL DEFAULT 6 .dynstr7: 000000000000043e 0 SECTION LOCAL DEFAULT 7 .gnu.version8: 0000000000000450 0 SECTION LOCAL DEFAULT 8 .gnu.version_r9: 0000000000000480 0 SECTION LOCAL DEFAULT 9 .rela.dyn10: 0000000000000540 0 SECTION LOCAL DEFAULT 10 .rela.plt11: 0000000000000570 0 SECTION LOCAL DEFAULT 11 .plt12: 00000000000005b0 0 SECTION LOCAL DEFAULT 12 .text13: 00000000000006b8 0 SECTION LOCAL DEFAULT 13 .rodata14: 00000000000006d0 0 SECTION LOCAL DEFAULT 14 .eh_frame_hdr15: 00000000000006e8 0 SECTION LOCAL DEFAULT 15 .eh_frame16: 0000000000001e08 0 SECTION LOCAL DEFAULT 16 .preinit_array17: 0000000000001e10 0 SECTION LOCAL DEFAULT 17 .init_array18: 0000000000001e18 0 SECTION LOCAL DEFAULT 18 .fini_array19: 0000000000001e20 0 SECTION LOCAL DEFAULT 19 .dynamic20: 0000000000002000 0 SECTION LOCAL DEFAULT 20 .data21: 0000000000002008 0 SECTION LOCAL DEFAULT 21 .got22: 0000000000002050 0 SECTION LOCAL DEFAULT 22 .bss23: 0000000000000000 0 SECTION LOCAL DEFAULT 23 ment24: 0000000000000000 0 SECTION LOCAL DEFAULT 24 .riscv.attributes25: 0000000000000000 0 FILE LOCAL DEFAULT ABS Scrt1.o26: 00000000000002b8 32 OBJECT LOCAL DEFAULT 3 __abi_tag27: 00000000000005b0 0 NOTYPE LOCAL DEFAULT 12 $xrv64i2p0_m2p0_[...]28: 00000000000005d2 0 NOTYPE LOCAL DEFAULT 12 load_gp29: 0000000000000000 0 FILE LOCAL DEFAULT ABS crtstuff.c30: 00000000000005e0 0 NOTYPE LOCAL DEFAULT 12 $xrv64i2p0_m2p0_[...]31: 00000000000005e0 0 FUNC LOCAL DEFAULT 12 deregister_tm_clones32: 0000000000000610 0 FUNC LOCAL DEFAULT 12 register_tm_clones33: 0000000000000640 0 FUNC LOCAL DEFAULT 12 __do_global_dtors_aux34: 0000000000002050 1 OBJECT LOCAL DEFAULT 22 completed.035: 0000000000001e18 0 OBJECT LOCAL DEFAULT 18 __do_global_dtor[...]36: 0000000000000680 0 FUNC LOCAL DEFAULT 12 frame_dummy37: 0000000000001e10 0 OBJECT LOCAL DEFAULT 17 __frame_dummy_in[...]38: 0000000000000000 0 FILE LOCAL DEFAULT ABS hello.c39: 0000000000000684 0 NOTYPE LOCAL DEFAULT 12 $xrv64i2p0_m2p0_[...]40: 0000000000000000 0 FILE LOCAL DEFAULT ABS crtstuff.c41: 0000000000000710 0 OBJECT LOCAL DEFAULT 15 __FRAME_END__42: 0000000000000000 0 FILE LOCAL DEFAULT ABS43: 0000000000000570 0 OBJECT LOCAL DEFAULT ABS _PROCEDURE_LINKA[...]44: 0000000000001e20 0 OBJECT LOCAL DEFAULT ABS _DYNAMIC45: 00000000000006d0 0 NOTYPE LOCAL DEFAULT 14 __GNU_EH_FRAME_HDR46: 0000000000002028 0 OBJECT LOCAL DEFAULT ABS _GLOBAL_OFFSET_TABLE_47: 0000000000000000 0 FUNC GLOBAL DEFAULT UND __libc_start_mai[...]48: 0000000000000000 0 NOTYPE WEAK DEFAULT UND _ITM_deregisterT[...]49: 0000000000002000 0 NOTYPE WEAK DEFAULT 20 data_start50: 0000000000002058 0 NOTYPE GLOBAL DEFAULT 22 __BSS_END__51: 0000000000002050 0 NOTYPE GLOBAL DEFAULT 21 _edata52: 0000000000002050 0 NOTYPE GLOBAL DEFAULT 21 __SDATA_BEGIN__53: 0000000000002000 0 NOTYPE GLOBAL DEFAULT 20 __DATA_BEGIN__54: 0000000000002000 0 NOTYPE GLOBAL DEFAULT 20 __data_start55: 0000000000002000 0 OBJECT GLOBAL HIDDEN 20 __dso_handle56: 00000000000006b8 4 OBJECT GLOBAL DEFAULT 13 _IO_stdin_used57: 0000000000002058 0 NOTYPE GLOBAL DEFAULT 22 _end58: 00000000000005b0 34 FUNC GLOBAL DEFAULT 12 _start59: 0000000000002800 0 NOTYPE GLOBAL DEFAULT ABS __global_pointer$60: 0000000000000000 0 FUNC GLOBAL DEFAULT UND puts@GLIBC_2.2761: 0000000000002050 0 NOTYPE GLOBAL DEFAULT 22 __bss_start62: 0000000000000684 52 FUNC GLOBAL DEFAULT 12 main63: 0000000000000000 0 FUNC WEAK DEFAULT UND __cxa_finalize@G[...]64: 0000000000002008 0 OBJECT GLOBAL HIDDEN 21 __TMC_END__65: 0000000000000000 0 NOTYPE WEAK DEFAULT UND _ITM_registerTMC[...]Histogram for `.gnu.hash' bucket list length (total of 2 buckets):Length Number % of total Coverage0 1 ( 50.0%)1 1 ( 50.0%) 100.0%Version symbols section '.gnu.version' contains 8 entries:Addr: 0x000000000000043e Offset: 0x0000043e Link: 5 (.dynsym)000: 0 (*local*) 0 (*local*) 2 (GLIBC_2.34) 1 (*global*)004: 3 (GLIBC_2.27) 3 (GLIBC_2.27) 1 (*global*) 1 (*global*)Version needs section '.gnu.version_r' contains 1 entry:Addr: 0x0000000000000450 Offset: 0x00000450 Link: 6 (.dynstr)000000: Version: 1 File: libc.so.6 Cnt: 20x0010: Name: GLIBC_2.27 Flags: none Version: 30x0020: Name: GLIBC_2.34 Flags: none Version: 2Displaying notes found in: .note.gnu.build-idOwner Data size DescriptionGNU 0x00000014 NT_GNU_BUILD_ID (unique build ID bitstring)Build ID: 04af9f13e57b18e206a946570b7a6c8f6a078c86Displaying notes found in: .note.ABI-tagOwner Data size DescriptionGNU 0x00000010 NT_GNU_ABI_TAG (ABI version tag)OS: Linux, ABI: 4.15.0
Attribute Section: riscv
File Attributes
- 最后这个目标板的架构
Tag_RISCV_arch: "rv64i2p0_m2p0_a2p0_f2p0_d2p0_c2p0_v0p7_zmmul1p0_zfh1p0_zfhmin1p0_xtheadba1p0_xtheadbb1p0_xtheadbs1p0_xtheadc1p0_xtheadcmo1p0_xtheadcondmov1p0_xtheadfmemidx1p0_xtheadfmv1p0_xtheadint1p0_xtheadmac1p0_xtheadmemidx1p0_xtheadmempair1p0_xtheadsync1p0"
- 1
- 1
- 1
- 1
注意事项:
1、安装是需要后面添加参数 --fix-missing(根据提示)
2、安装时系统可能会卡死,这时候安装包可能损坏,需要修复这个问题,dpkg --configure -a,
3、继续安装的时候,又会发现没有依赖或者依赖关系不对,需要apt --fix-broken install
3、参考
LicheePi Wiki
RISCV学习(2)玄铁C910处理器体验
笔者有幸参加了平头哥RISCV开发者大赛,体验了一下基于玄铁C910内核的矽速开发板。
1、开发板介绍
LicheePi 4A 是基于 Lichee Module 4A 核心板的 高性能 RISC-V Linux 开发板。
- TH1520 为主控核心(4xC910@1.85G, RV64GCV,4TOPS@int8 NPU, 50GFLOP GPU)
- 板载最大 16GB 64bit LPDDR4X,128GB eMMC,
- 支持 HDMI+MIPI 双4K 显示输出,
- 支持 4K 摄像头接入,
- 支持双千兆网口(其中一个支持POE供电)
- 4 个 USB3.0 接口,
- 多种音频输入输出(由专用 C906 核心处理)。-
2、GCC工具链使用
GCC的工具链安装,参考Licheepi GCC工具链安装。
- 查看gcc的工具链版本
root@lpi4a:~# gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/riscv64-linux-gnu/10/lto-wrapper
Target: riscv64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Debian 10.4.0-8revyos2.4' --with-bugurl=file:///usr/share/doc/gcc-10/README.Bugs --enable-languages=c,ada,c++,go,d,fortran,objc,obj-c++,m2 --prefix=/usr --with-gcc-major-version-only --program-suffix=-10 --program-prefix=riscv64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-libitm --disable-libsanitizer --disable-libquadmath --disable-libquadmath-support --enable-plugin --enable-default-pie --with-system-zlib --enable-libphobos-checking=release --with-target-system-zlib=auto --enable-objc-gc=auto --enable-multiarch --disable-werror --disable-multilib --with-arch=rv64gcv0p7_zfh_xtheadc --with-abi=lp64d --enable-checking=release --build=riscv64-linux-gnu --host=riscv64-linux-gnu --target=riscv64-linux-gnu
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 10.4.0 (Debian 10.4.0-8revyos2.4)
- 直接编译hello.c程序,提示需要设置xthreadc的版本,其实并不知道如何处理,经过查资料后发现,需要指明架构和二进制接口版本
gcc hello.c
Assembler messages:
Error: x ISA extension `xtheadc' must be set with the versions
- 然后根据提示指明了架构,发现对应的头文件找不到,怀疑工具链没安装对,重新安装了,但是依然没什么用,之后又重启了,还是不行,看来还得继续找问题。
gcc hello.c -march=rv64imc
In file included from /usr/include/features.h:513,from /usr/include/riscv64-linux-gnu/bits/libc-header-start.h:33,from /usr/include/stdio.h:27,from hello.c:1:
/usr/include/riscv64-linux-gnu/gnu/stubs.h:14:11: fatal error: gnu/stubs-lp64.h: No such file or directory14 | # include <gnu/stubs-lp64.h>
- 然后就看一下该文件的内容,以及去该目录下面搜索了有哪些文件
root@lpi4a:~# ls /usr/include/riscv64-linux-gnu/gnu/stubs.h
/usr/include/riscv64-linux-gnu/gnu/stubs.h
root@lpi4a:~# cat /usr/include/riscv64-linux-gnu/gnu/stubs.h
/* This file is automatically generated.This file selects the right generated file of `__stub_FUNCTION' macrosbased on the architecture being compiled for. */#include <bits/wordsize.h>#if __WORDSIZE == 32 && defined __riscv_float_abi_soft
# include <gnu/stubs-ilp32.h>
#endif
#if __WORDSIZE == 32 && defined __riscv_float_abi_double
# include <gnu/stubs-ilp32d.h>
#endif
#if __WORDSIZE == 64 && defined __riscv_float_abi_soft
# include <gnu/stubs-lp64.h>
#endif
#if __WORDSIZE == 64 && defined __riscv_float_abi_double
# include <gnu/stubs-lp64d.h>
#endif
ls /usr/include/riscv64-linux-gnu/gnu/
lib-names-lp64d.h lib-names.h libc-version.h stubs-lp64d.h stubs.h
- 看到这里就突然知道,需要指明对应的版本,不然相应的头文件找不到,果然和常规的GCC工具链使用还是有区别,增加了相应的abl版本后,发现march也需要版本,
gcc hello.c -march=rv64imc -mabi=lp64d
cc1: error: requested ABI requires '-march' to subsume the 'D' extension
- 在架构方面增加了d,发现还是不对,提示第一个指令集是e/i/g,还得修改
gcc hello.c -march=rv64dimc -mabi=lp64d
gcc: error: '-march=rv64dimc': first ISA subset must be 'e', 'i' or 'g'
- 然后修改了abl的,改成了e,发现abl的版本里面没有这个,必须是lp64d,所以又得改回去
gcc hello.c -march=rv64imc -mabi=lp64e
gcc: error: unrecognized argument in option '-mabi=lp64e'
gcc: note: valid arguments to '-mabi=' are: ilp32 ilp32d ilp32e ilp32f lp64 lp64d lp64dv lp64f lp64v; did you mean 'lp64'?
- 最后在march指令集的后面增加d,可以了,终于gcc工具链可以正常使用了。
root@lpi4a:~# gcc hello.c -march=rv64imafd -mabi=lp64d
root@lpi4a:~#
- readelf工具可以查看其out文件信息,RISC-V的machine的64位机器版本
root@lpi4a:~# readelf -a a.out
ELF Header:Magic: 7f 45 4c 46 02 01 01 00 00 00 00 00 00 00 00 00Class: ELF64Data: 2's complement, little endianVersion: 1 (current)OS/ABI: UNIX - System VABI Version: 0Type: DYN (Position-Independent Executable file)Machine: RISC-VVersion: 0x1Entry point address: 0x5b0Start of program headers: 64 (bytes into file)Start of section headers: 7168 (bytes into file)Flags: 0x5, RVC, double-float ABISize of this header: 64 (bytes)Size of program headers: 56 (bytes)Number of program headers: 10Size of section headers: 64 (bytes)Number of section headers: 28Section header string table index: 27
- 再看看其他Section、Segment等信息
Section Headers:[Nr] Name Type Address OffsetSize EntSize Flags Link Info Align[ 0] NULL 0000000000000000 000000000000000000000000 0000000000000000 0 0 0[ 1] .interp PROGBITS 0000000000000270 000002700000000000000021 0000000000000000 A 0 0 1[ 2] .note.gnu.bu[...] NOTE 0000000000000294 000002940000000000000024 0000000000000000 A 0 0 4[ 3] .note.ABI-tag NOTE 00000000000002b8 000002b80000000000000020 0000000000000000 A 0 0 4[ 4] .gnu.hash GNU_HASH 00000000000002d8 000002d80000000000000024 0000000000000000 A 5 0 8[ 5] .dynsym DYNSYM 0000000000000300 0000030000000000000000c0 0000000000000018 A 6 2 8[ 6] .dynstr STRTAB 00000000000003c0 000003c0000000000000007d 0000000000000000 A 0 0 1[ 7] .gnu.version VERSYM 000000000000043e 0000043e0000000000000010 0000000000000002 A 5 0 2[ 8] .gnu.version_r VERNEED 0000000000000450 000004500000000000000030 0000000000000000 A 6 1 8[ 9] .rela.dyn RELA 0000000000000480 0000048000000000000000c0 0000000000000018 A 5 0 8[10] .rela.plt RELA 0000000000000540 000005400000000000000030 0000000000000018 AI 5 21 8[11] .plt PROGBITS 0000000000000570 000005700000000000000040 0000000000000010 AX 0 0 16[12] .text PROGBITS 00000000000005b0 000005b00000000000000108 0000000000000000 AX 0 0 16[13] .rodata PROGBITS 00000000000006b8 000006b80000000000000015 0000000000000000 A 0 0 8[14] .eh_frame_hdr PROGBITS 00000000000006d0 000006d00000000000000014 0000000000000000 A 0 0 4[15] .eh_frame PROGBITS 00000000000006e8 000006e8000000000000002c 0000000000000000 A 0 0 8[16] .preinit_array PREINIT_ARRAY 0000000000001e08 00000e080000000000000008 0000000000000008 WA 0 0 1[17] .init_array INIT_ARRAY 0000000000001e10 00000e100000000000000008 0000000000000008 WA 0 0 8[18] .fini_array FINI_ARRAY 0000000000001e18 00000e180000000000000008 0000000000000008 WA 0 0 8[19] .dynamic DYNAMIC 0000000000001e20 00000e2000000000000001e0 0000000000000010 WA 6 0 8[20] .data PROGBITS 0000000000002000 000010000000000000000008 0000000000000000 WA 0 0 8[21] .got PROGBITS 0000000000002008 000010080000000000000048 0000000000000008 WA 0 0 8[22] .bss NOBITS 0000000000002050 000010500000000000000008 0000000000000000 WA 0 0 1[23] ment PROGBITS 0000000000000000 000010500000000000000027 0000000000000001 MS 0 0 1[24] .riscv.attributes RISCV_ATTRIBUTE 0000000000000000 000010770000000000000106 0000000000000000 0 0 1[25] .symtab SYMTAB 0000000000000000 000011800000000000000630 0000000000000018 26 47 8[26] .strtab STRTAB 0000000000000000 000017b0000000000000033c 0000000000000000 0 0 1[27] .shstrtab STRTAB 0000000000000000 00001aec000000000000010f 0000000000000000 0 0 1
Key to Flags:W (write), A (alloc), X (execute), M (merge), S (strings), I (info),L (link order), O (extra OS processing required), G (group), T (TLS),C (compressed), x (unknown), o (OS specific), E (exclude),D (mbind), p (processor specific)There are no section groups in this file.Program Headers:Type Offset VirtAddr PhysAddrFileSiz MemSiz Flags AlignPHDR 0x0000000000000040 0x0000000000000040 0x00000000000000400x0000000000000230 0x0000000000000230 R 0x8INTERP 0x0000000000000270 0x0000000000000270 0x00000000000002700x0000000000000021 0x0000000000000021 R 0x1[Requesting program interpreter: /lib/ld-linux-riscv64-lp64d.so.1]RISCV_ATTRIBUT 0x0000000000001077 0x0000000000000000 0x00000000000000000x0000000000000106 0x0000000000000000 R 0x1LOAD 0x0000000000000000 0x0000000000000000 0x00000000000000000x0000000000000714 0x0000000000000714 R E 0x1000LOAD 0x0000000000000e08 0x0000000000001e08 0x0000000000001e080x0000000000000248 0x0000000000000250 RW 0x1000DYNAMIC 0x0000000000000e20 0x0000000000001e20 0x0000000000001e200x00000000000001e0 0x00000000000001e0 RW 0x8NOTE 0x0000000000000294 0x0000000000000294 0x00000000000002940x0000000000000044 0x0000000000000044 R 0x4GNU_EH_FRAME 0x00000000000006d0 0x00000000000006d0 0x00000000000006d00x0000000000000014 0x0000000000000014 R 0x4GNU_STACK 0x0000000000000000 0x0000000000000000 0x00000000000000000x0000000000000000 0x0000000000000000 RW 0x10GNU_RELRO 0x0000000000000e08 0x0000000000001e08 0x0000000000001e080x00000000000001f8 0x00000000000001f8 R 0x1Section to Segment mapping:Segment Sections...0001 .interp02 .riscv.attributes03 .interp .note.gnu.build-id .note.ABI-tag .gnu.hash .dynsym .dynstr .gnu.version .gnu.version_r .rela.dyn .rela.plt .plt .text .rodata .eh_frame_hdr .eh_frame04 .preinit_array .init_array .fini_array .dynamic .data .got .bss05 .dynamic06 .note.gnu.build-id .note.ABI-tag07 .eh_frame_hdr0809 .preinit_array .init_array .fini_array .dynamicDynamic section at offset 0xe20 contains 26 entries:Tag Type Name/Value0x0000000000000001 (NEEDED) Shared library: [libc.so.6]0x0000000000000020 (PREINIT_ARRAY) 0x1e080x0000000000000021 (PREINIT_ARRAYSZ) 8 (bytes)0x0000000000000019 (INIT_ARRAY) 0x1e100x000000000000001b (INIT_ARRAYSZ) 8 (bytes)0x000000000000001a (FINI_ARRAY) 0x1e180x000000000000001c (FINI_ARRAYSZ) 8 (bytes)0x000000006ffffef5 (GNU_HASH) 0x2d80x0000000000000005 (STRTAB) 0x3c00x0000000000000006 (SYMTAB) 0x3000x000000000000000a (STRSZ) 125 (bytes)0x000000000000000b (SYMENT) 24 (bytes)0x0000000000000015 (DEBUG) 0x00x0000000000000003 (PLTGOT) 0x20080x0000000000000002 (PLTRELSZ) 48 (bytes)0x0000000000000014 (PLTREL) RELA0x0000000000000017 (JMPREL) 0x5400x0000000000000007 (RELA) 0x4800x0000000000000008 (RELASZ) 240 (bytes)0x0000000000000009 (RELAENT) 24 (bytes)0x000000006ffffffb (FLAGS_1) Flags: PIE0x000000006ffffffe (VERNEED) 0x4500x000000006fffffff (VERNEEDNUM) 10x000000006ffffff0 (VERSYM) 0x43e0x000000006ffffff9 (RELACOUNT) 50x0000000000000000 (NULL) 0x0Relocation section '.rela.dyn' at offset 0x480 contains 8 entries:Offset Info Type Sym. Value Sym. Name + Addend
000000001e08 000000000003 R_RISCV_RELATIVE 5d2
000000001e10 000000000003 R_RISCV_RELATIVE 680
000000001e18 000000000003 R_RISCV_RELATIVE 640
000000002000 000000000003 R_RISCV_RELATIVE 2000
000000002038 000000000003 R_RISCV_RELATIVE 684
000000002030 000300000002 R_RISCV_64 0000000000000000 _ITM_deregisterTM[...] + 0
000000002040 000500000002 R_RISCV_64 0000000000000000 __cxa_finalize@GLIBC_2.27 + 0
000000002048 000600000002 R_RISCV_64 0000000000000000 _ITM_registerTMCl[...] + 0Relocation section '.rela.plt' at offset 0x540 contains 2 entries:Offset Info Type Sym. Value Sym. Name + Addend
000000002018 000200000005 R_RISCV_JUMP_SLOT 0000000000000000 __libc_start_main@GLIBC_2.34 + 0
000000002020 000400000005 R_RISCV_JUMP_SLOT 0000000000000000 puts@GLIBC_2.27 + 0The decoding of unwind sections for machine type RISC-V is not currently supported.Symbol table '.dynsym' contains 8 entries:Num: Value Size Type Bind Vis Ndx Name0: 0000000000000000 0 NOTYPE LOCAL DEFAULT UND1: 00000000000005b0 0 SECTION LOCAL DEFAULT 12 .text2: 0000000000000000 0 FUNC GLOBAL DEFAULT UND _[...]@GLIBC_2.34 (2)3: 0000000000000000 0 NOTYPE WEAK DEFAULT UND _ITM_deregisterT[...]4: 0000000000000000 0 FUNC GLOBAL DEFAULT UND puts@GLIBC_2.27 (3)5: 0000000000000000 0 FUNC WEAK DEFAULT UND _[...]@GLIBC_2.27 (3)6: 0000000000000000 0 NOTYPE WEAK DEFAULT UND _ITM_registerTMC[...]7: 0000000000000684 52 FUNC GLOBAL DEFAULT 12 mainSymbol table '.symtab' contains 66 entries:Num: Value Size Type Bind Vis Ndx Name0: 0000000000000000 0 NOTYPE LOCAL DEFAULT UND1: 0000000000000270 0 SECTION LOCAL DEFAULT 1 .interp2: 0000000000000294 0 SECTION LOCAL DEFAULT 2 .note.gnu.build-id3: 00000000000002b8 0 SECTION LOCAL DEFAULT 3 .note.ABI-tag4: 00000000000002d8 0 SECTION LOCAL DEFAULT 4 .gnu.hash5: 0000000000000300 0 SECTION LOCAL DEFAULT 5 .dynsym6: 00000000000003c0 0 SECTION LOCAL DEFAULT 6 .dynstr7: 000000000000043e 0 SECTION LOCAL DEFAULT 7 .gnu.version8: 0000000000000450 0 SECTION LOCAL DEFAULT 8 .gnu.version_r9: 0000000000000480 0 SECTION LOCAL DEFAULT 9 .rela.dyn10: 0000000000000540 0 SECTION LOCAL DEFAULT 10 .rela.plt11: 0000000000000570 0 SECTION LOCAL DEFAULT 11 .plt12: 00000000000005b0 0 SECTION LOCAL DEFAULT 12 .text13: 00000000000006b8 0 SECTION LOCAL DEFAULT 13 .rodata14: 00000000000006d0 0 SECTION LOCAL DEFAULT 14 .eh_frame_hdr15: 00000000000006e8 0 SECTION LOCAL DEFAULT 15 .eh_frame16: 0000000000001e08 0 SECTION LOCAL DEFAULT 16 .preinit_array17: 0000000000001e10 0 SECTION LOCAL DEFAULT 17 .init_array18: 0000000000001e18 0 SECTION LOCAL DEFAULT 18 .fini_array19: 0000000000001e20 0 SECTION LOCAL DEFAULT 19 .dynamic20: 0000000000002000 0 SECTION LOCAL DEFAULT 20 .data21: 0000000000002008 0 SECTION LOCAL DEFAULT 21 .got22: 0000000000002050 0 SECTION LOCAL DEFAULT 22 .bss23: 0000000000000000 0 SECTION LOCAL DEFAULT 23 ment24: 0000000000000000 0 SECTION LOCAL DEFAULT 24 .riscv.attributes25: 0000000000000000 0 FILE LOCAL DEFAULT ABS Scrt1.o26: 00000000000002b8 32 OBJECT LOCAL DEFAULT 3 __abi_tag27: 00000000000005b0 0 NOTYPE LOCAL DEFAULT 12 $xrv64i2p0_m2p0_[...]28: 00000000000005d2 0 NOTYPE LOCAL DEFAULT 12 load_gp29: 0000000000000000 0 FILE LOCAL DEFAULT ABS crtstuff.c30: 00000000000005e0 0 NOTYPE LOCAL DEFAULT 12 $xrv64i2p0_m2p0_[...]31: 00000000000005e0 0 FUNC LOCAL DEFAULT 12 deregister_tm_clones32: 0000000000000610 0 FUNC LOCAL DEFAULT 12 register_tm_clones33: 0000000000000640 0 FUNC LOCAL DEFAULT 12 __do_global_dtors_aux34: 0000000000002050 1 OBJECT LOCAL DEFAULT 22 completed.035: 0000000000001e18 0 OBJECT LOCAL DEFAULT 18 __do_global_dtor[...]36: 0000000000000680 0 FUNC LOCAL DEFAULT 12 frame_dummy37: 0000000000001e10 0 OBJECT LOCAL DEFAULT 17 __frame_dummy_in[...]38: 0000000000000000 0 FILE LOCAL DEFAULT ABS hello.c39: 0000000000000684 0 NOTYPE LOCAL DEFAULT 12 $xrv64i2p0_m2p0_[...]40: 0000000000000000 0 FILE LOCAL DEFAULT ABS crtstuff.c41: 0000000000000710 0 OBJECT LOCAL DEFAULT 15 __FRAME_END__42: 0000000000000000 0 FILE LOCAL DEFAULT ABS43: 0000000000000570 0 OBJECT LOCAL DEFAULT ABS _PROCEDURE_LINKA[...]44: 0000000000001e20 0 OBJECT LOCAL DEFAULT ABS _DYNAMIC45: 00000000000006d0 0 NOTYPE LOCAL DEFAULT 14 __GNU_EH_FRAME_HDR46: 0000000000002028 0 OBJECT LOCAL DEFAULT ABS _GLOBAL_OFFSET_TABLE_47: 0000000000000000 0 FUNC GLOBAL DEFAULT UND __libc_start_mai[...]48: 0000000000000000 0 NOTYPE WEAK DEFAULT UND _ITM_deregisterT[...]49: 0000000000002000 0 NOTYPE WEAK DEFAULT 20 data_start50: 0000000000002058 0 NOTYPE GLOBAL DEFAULT 22 __BSS_END__51: 0000000000002050 0 NOTYPE GLOBAL DEFAULT 21 _edata52: 0000000000002050 0 NOTYPE GLOBAL DEFAULT 21 __SDATA_BEGIN__53: 0000000000002000 0 NOTYPE GLOBAL DEFAULT 20 __DATA_BEGIN__54: 0000000000002000 0 NOTYPE GLOBAL DEFAULT 20 __data_start55: 0000000000002000 0 OBJECT GLOBAL HIDDEN 20 __dso_handle56: 00000000000006b8 4 OBJECT GLOBAL DEFAULT 13 _IO_stdin_used57: 0000000000002058 0 NOTYPE GLOBAL DEFAULT 22 _end58: 00000000000005b0 34 FUNC GLOBAL DEFAULT 12 _start59: 0000000000002800 0 NOTYPE GLOBAL DEFAULT ABS __global_pointer$60: 0000000000000000 0 FUNC GLOBAL DEFAULT UND puts@GLIBC_2.2761: 0000000000002050 0 NOTYPE GLOBAL DEFAULT 22 __bss_start62: 0000000000000684 52 FUNC GLOBAL DEFAULT 12 main63: 0000000000000000 0 FUNC WEAK DEFAULT UND __cxa_finalize@G[...]64: 0000000000002008 0 OBJECT GLOBAL HIDDEN 21 __TMC_END__65: 0000000000000000 0 NOTYPE WEAK DEFAULT UND _ITM_registerTMC[...]Histogram for `.gnu.hash' bucket list length (total of 2 buckets):Length Number % of total Coverage0 1 ( 50.0%)1 1 ( 50.0%) 100.0%Version symbols section '.gnu.version' contains 8 entries:Addr: 0x000000000000043e Offset: 0x0000043e Link: 5 (.dynsym)000: 0 (*local*) 0 (*local*) 2 (GLIBC_2.34) 1 (*global*)004: 3 (GLIBC_2.27) 3 (GLIBC_2.27) 1 (*global*) 1 (*global*)Version needs section '.gnu.version_r' contains 1 entry:Addr: 0x0000000000000450 Offset: 0x00000450 Link: 6 (.dynstr)000000: Version: 1 File: libc.so.6 Cnt: 20x0010: Name: GLIBC_2.27 Flags: none Version: 30x0020: Name: GLIBC_2.34 Flags: none Version: 2Displaying notes found in: .note.gnu.build-idOwner Data size DescriptionGNU 0x00000014 NT_GNU_BUILD_ID (unique build ID bitstring)Build ID: 04af9f13e57b18e206a946570b7a6c8f6a078c86Displaying notes found in: .note.ABI-tagOwner Data size DescriptionGNU 0x00000010 NT_GNU_ABI_TAG (ABI version tag)OS: Linux, ABI: 4.15.0
Attribute Section: riscv
File Attributes
- 最后这个目标板的架构
Tag_RISCV_arch: "rv64i2p0_m2p0_a2p0_f2p0_d2p0_c2p0_v0p7_zmmul1p0_zfh1p0_zfhmin1p0_xtheadba1p0_xtheadbb1p0_xtheadbs1p0_xtheadc1p0_xtheadcmo1p0_xtheadcondmov1p0_xtheadfmemidx1p0_xtheadfmv1p0_xtheadint1p0_xtheadmac1p0_xtheadmemidx1p0_xtheadmempair1p0_xtheadsync1p0"
- 1
- 1
- 1
- 1
注意事项:
1、安装是需要后面添加参数 --fix-missing(根据提示)
2、安装时系统可能会卡死,这时候安装包可能损坏,需要修复这个问题,dpkg --configure -a,
3、继续安装的时候,又会发现没有依赖或者依赖关系不对,需要apt --fix-broken install
3、参考
LicheePi Wiki
发布评论