[root@bogon gcc-arm-embedded]# yum install gcc-arm-linux-gnu Loaded plugins: fastestmirror, langpacks Repository epel is listed more than once in the configuration Repository epel-debuginfo is listed more than once in the configuration Repository epel-source is listed more than once in the configuration Loading mirror speeds from cached hostfile * centos-qemu-ev: mirror-hk.koddos.net * epel: mirror.sjtu.edu.cn Resolving Dependencies --> Running transaction check ---> Package gcc-arm-linux-gnu.aarch64 0:4.8.5-16.el7.1 will be installed --> Processing Dependency: cross-gcc-common = 4.8.5-16.el7.1 for package: gcc-arm-linux-gnu-4.8.5-16.el7.1.aarch64 --> Processing Dependency: binutils-arm-linux-gnu >= 2.25-1 for package: gcc-arm-linux-gnu-4.8.5-16.el7.1.aarch64 --> Running transaction check ---> Package binutils-arm-linux-gnu.aarch64 0:2.27-9.el7.1 will be installed --> Processing Dependency: cross-binutils-common = 2.27-9.el7.1 for package: binutils-arm-linux-gnu-2.27-9.el7.1.aarch64 ---> Package cross-gcc-common.noarch 0:4.8.5-16.el7.1 will be installed --> Running transaction check ---> Package cross-binutils-common.noarch 0:2.27-9.el7.1 will be installed --> Finished Dependency Resolution Dependencies Resolved ============================================================ Package Arch Version Repository Size ============================================================ Installing: gcc-arm-linux-gnu aarch64 4.8.5-16.el7.1 epel 8.8 M Installing for dependencies: binutils-arm-linux-gnu aarch64 2.27-9.el7.1 epel 1.9 M cross-binutils-common noarch 2.27-9.el7.1 epel 1.7 M cross-gcc-common noarch 4.8.5-16.el7.1 epel 1.9 M Transaction Summary ============================================================ Install 1 Package (+3 Dependent packages) Total download size: 14 M Installed size: 62 M Is this ok [y/d/N]: y Downloading packages: (1/4): cross-gcc-common-4.8.5-16.el7.1 | 1.9 MB 00:05 (2/4): cross-binutils-common-2.27-9.el | 1.7 MB 00:06 (3/4): binutils-arm-linux-gnu-2.27-9.e | 1.9 MB 00:07 (4/4): gcc-arm-linux-gnu-4.8.5-16.el7. | 8.8 MB 00:09 ------------------------------------------------------------ Total 1.5 MB/s | 14 MB 00:09 Running transaction check Running transaction test Transaction test succeeded Running transaction Installing : cross-binutils-common-2.27-9.el7.1.noa 1/4 Installing : binutils-arm-linux-gnu-2.27-9.el7.1.aa 2/4 Installing : cross-gcc-common-4.8.5-16.el7.1.noarch 3/4 Installing : gcc-arm-linux-gnu-4.8.5-16.el7.1.aarch 4/4 Verifying : cross-gcc-common-4.8.5-16.el7.1.noarch 1/4 Verifying : gcc-arm-linux-gnu-4.8.5-16.el7.1.aarch 2/4 Verifying : binutils-arm-linux-gnu-2.27-9.el7.1.aa 3/4 Verifying : cross-binutils-common-2.27-9.el7.1.noa 4/4 Installed: gcc-arm-linux-gnu.aarch64 0:4.8.5-16.el7.1 Dependency Installed: binutils-arm-linux-gnu.aarch64 0:2.27-9.el7.1 cross-binutils-common.noarch 0:2.27-9.el7.1 cross-gcc-common.noarch 0:4.8.5-16.el7.1 Complete! [root@bogon gcc-arm-embedded]# arm-none-eabi-gcc -v bash: arm-none-eabi-gcc: command not found... [root@bogon gcc-arm-embedded]# gcc gcc gcc-ar gcc-nm gcc-ranlib [root@bogon gcc-arm-embedded]# gcc-arm bash: gcc-arm: command not found... Similar command is: 'gcc-ar' [root@bogon gcc-arm-embedded]# gcc- gcc-ar gcc-nm gcc-ranlib [root@bogon gcc-arm-embedded]# gcc- gcc-ar gcc-nm gcc-ranlib [root@bogon gcc-arm-embedded]# gcc- gcc-ar gcc-nm gcc-ranlib [root@bogon gcc-arm-embedded]# arm-linux-gnu- arm-linux-gnu-addr2line arm-linux-gnu-ld.bfd arm-linux-gnu-ar arm-linux-gnu-nm arm-linux-gnu-as arm-linux-gnu-objcopy arm-linux-gnu-c++filt arm-linux-gnu-objdump arm-linux-gnu-cpp arm-linux-gnu-ranlib arm-linux-gnu-elfedit arm-linux-gnu-readelf arm-linux-gnu-gcc arm-linux-gnu-size arm-linux-gnu-gcov arm-linux-gnu-strings arm-linux-gnu-gprof arm-linux-gnu-strip arm-linux-gnu-ld [root@bogon gcc-arm-embedded]# arm-linux-gnu-
arm-none-eabi-
下载链接 https://developer.arm.com/tools-and-software/open-source-software/developer-tools/gnu-toolchain/gnu-a/downloads
[root@bogon gcc-arm-embedded]# wget https://developer.arm.com/-/media/Files/downloads/gnu-a/10.3-2021.07/binrel/gcc-arm-10.3-2021.07-aarch64-arm-none-eabi.tar.xz --2022-02-15 16:22:30-- https://developer.arm.com/-/media/Files/downloads/gnu-a/10.3-2021.07/binrel/gcc-arm-10.3-2021.07-aarch64-arm-none-eabi.tar.xz Resolving developer.arm.com (developer.arm.com)... 23.76.74.223 Connecting to developer.arm.com (developer.arm.com)|23.76.74.223|:443... connected. HTTP request sent, awaiting response... 302 Moved Temporarily Location: https://armkeil.blob.core.windows.net/developer/Files/downloads/gnu-a/10.3-2021.07/binrel/gcc-arm-10.3-2021.07-aarch64-arm-none-eabi.tar.xz [following] --2022-02-15 16:22:35-- https://armkeil.blob.core.windows.net/developer/Files/downloads/gnu-a/10.3-2021.07/binrel/gcc-arm-10.3-2021.07-aarch64-arm-none-eabi.tar.xz
[root@bogon gcc-arm-embedded]# find ./ -name '*gcc' ./gcc-arm-10.3-2021.07-aarch64-arm-none-eabi/share/doc/gcc ./gcc-arm-10.3-2021.07-aarch64-arm-none-eabi/bin/arm-none-eabi-gcc ./gcc-arm-10.3-2021.07-aarch64-arm-none-eabi/lib/gcc ./gcc-arm-10.3-2021.07-aarch64-arm-none-eabi/libexec/gcc [root@bogon gcc-arm-embedded]# ./gcc-arm-10.3-2021.07-aarch64-arm-none-eabi/bin/arm-none-eabi-gcc -v Using built-in specs. COLLECT_GCC=./gcc-arm-10.3-2021.07-aarch64-arm-none-eabi/bin/arm-none-eabi-gcc COLLECT_LTO_WRAPPER=/data1/gcc-arm-embedded/gcc-arm-10.3-2021.07-aarch64-arm-none-eabi/bin/../libexec/gcc/arm-none-eabi/10.3.1/lto-wrapper Target: arm-none-eabi Configured with: /data/jenkins/workspace/GNU-toolchain/arm-10/src/gcc/configure --target=arm-none-eabi --prefix=/data/jenkins/workspace/GNU-toolchain/arm-10/build-arm-none-eabi/install// --with-gmp=/data/jenkins/workspace/GNU-toolchain/arm-10/build-arm-none-eabi/host-tools --with-mpfr=/data/jenkins/workspace/GNU-toolchain/arm-10/build-arm-none-eabi/host-tools --with-mpc=/data/jenkins/workspace/GNU-toolchain/arm-10/build-arm-none-eabi/host-tools --with-isl=/data/jenkins/workspace/GNU-toolchain/arm-10/build-arm-none-eabi/host-tools --disable-shared --disable-nls --disable-threads --disable-tls --enable-checking=release --enable-languages=c,c++,fortran --with-newlib --with-multilib-list=aprofile --with-pkgversion='GNU Toolchain for the A-profile Architecture 10.3-2021.07 (arm-10.29)' --with-bugurl=https://bugs.linaro.org/ Thread model: single Supported LTO compression algorithms: zlib gcc version 10.3.1 20210621 (GNU Toolchain for the A-profile Architecture 10.3-2021.07 (arm-10.29)) [root@bogon gcc-arm-embedded]#
export PATH="/data1/gcc-arm-embedded/gcc-arm-10.3-2021.07-aarch64-arm-none-eabi/bin:$PATH"
arm-none-eabi-ld -v
arm-none-eabi-ld: /lib64/libc.so.6: version `GLIBC_2.27' not found (required by arm-none-eabi-ld)
strings /lib64/libc.so.6 | grep GLIBC GLIBC_2.17 GLIBC_2.18 GLIBC_PRIVATE
uname -a Linux centos7 4.14.0-115.el7a.0.1.aarch64 #1 SMP Sun Nov 25 20:54:21 UTC 2018 aarch64 aarch64 aarch64 GNU/Linux
下载glibc
wget https://ftp.gnu.org/gnu/glibc/glibc-2.27.tar.xz
1035 cd glibc-2.27 1036 mkdir build 1037 cd build/ 1038 ../configure --prefix=/usr --disable-profile --enable-add-ons --with-headers=/usr/include --with-binutils=/usr/bin
checking if gcc -B/usr/bin/ is sufficient to build libc... no checking for nm... nm checking for python3... python3 configure: error: *** These critical programs are missing or too old: compiler *** Check the INSTALL file for required versions.
arm社区
https://developer.arm.com/tools-and-software/open-source-software/developer-tools/gnu-toolchain/gnu-rm/downloads
ubuntu
uname -a Linux ubuntu 5.0.0-23-generic #24~18.04.1-Ubuntu SMP Mon Jul 29 16:10:24 UTC 2019 aarch64 aarch64 aarch64 GNU/Linux
ldd --version ldd (Ubuntu GLIBC 2.27-3ubuntu1) 2.27 Copyright (C) 2018 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Written by Roland McGrath and Ulrich Drepper.
gcc -v Using built-in specs. COLLECT_GCC=gcc COLLECT_LTO_WRAPPER=/usr/lib/gcc/aarch64-linux-gnu/5/lto-wrapper Target: aarch64-linux-gnu Configured with: ../src/configure -v --with-pkgversion='Ubuntu/Linaro 5.5.0-12ubuntu1' --with-bugurl=file:///usr/share/doc/gcc-5/README.Bugs --enable-languages=c,ada,c++,go,d,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-5 --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-libquadmath --enable-plugin --enable-default-pie --with-system-zlib --enable-multiarch --enable-fix-cortex-a53-843419 --disable-werror --enable-checking=release --build=aarch64-linux-gnu --host=aarch64-linux-gnu --target=aarch64-linux-gnu Thread model: posix gcc version 5.5.0 20171010 (Ubuntu/Linaro 5.5.0-12ubuntu1)
apt-get install gcc-arm-none-eabi
root@ubuntu:~# apt-get install gcc-arm-none-eabi Reading package lists... Done Building dependency tree Reading state information... Done The following packages were automatically installed and are no longer required: adwaita-icon-theme at-spi2-core augeas-lenses cmake-data db-util db5.3-util dconf-gsettings-backend dconf-service exfat-fuse exfat-utils fontconfig fonts-droid-fallback fonts-noto-mono genisoimage ghostscript gir1.2-appindicator3-0.1 gir1.2-atk-1.0 gir1.2-freedesktop gir1.2-gdkpixbuf-2.0 gir1.2-gtk-3.0 gir1.2-gtk-vnc-2.0 gir1.2-libosinfo-1.0 gir1.2-pango-1.0 gir1.2-spiceclientglib-2.0 gir1.2-spiceclientgtk-3.0 gir1.2-vte-2.91 glib-networking glib-networking-common glib-networking-services golang-1.10-go golang-1.10-src golang-src gsettings-desktop-schemas gsfonts gstreamer1.0-plugins-base gtk-update-icon-cache hfsplus hicolor-icon-theme humanity-icon-theme icoutils ipxe-qemu-256k-compat-efi-roms ldmtool libappindicator3-1 libarchive13 libasound2 libasound2-data libasyncns0 libatk-bridge2.0-0 libatk1.0-0 libatk1.0-data libatspi2.0-0 libaugeas0 libauthen-sasl-perl libavahi-client3 libavahi-common-data libavahi-common3 libbfio1 libbluetooth3 libbrlapi0.6 libcaca0 libcacard0 libcdparanoia0 libcolord2 libconfig9 libcroco3 libcups2 libcupsfilters1 libcupsimage2 libdata-dump-perl libdate-manip-perl libdatrie1 libdbusmenu-glib4 libdbusmenu-gtk3-4 libdconf1 libencode-locale-perl libepoxy0 libewf2 libfile-listing-perl libflac8 libfont-afm-perl libgdk-pixbuf2.0-0 libgdk-pixbuf2.0-bin libgdk-pixbuf2.0-common libgovirt-common libgovirt2 libgs9 libgs9-common libgstreamer-plugins-base1.0-0 libgstreamer1.0-0 libgtk-3-0 libgtk-3-bin libgtk-3-common libgtk-vnc-2.0-0 libgvnc-1.0-0 libhfsp0 libhivex0 libhtml-form-perl libhtml-format-perl libhtml-parser-perl libhtml-tagset-perl libhtml-tree-perl libhttp-cookies-perl libhttp-daemon-perl libhttp-date-perl libhttp-message-perl libhttp-negotiate-perl libijs-0.35 libindicator3-7 libintl-perl libintl-xs-perl libio-html-perl libio-socket-ssl-perl libiscsi7 libjbig2dec0 libjson-glib-1.0-0 libjson-glib-1.0-common libjsoncpp1 liblcms2-2 libldm-1.0-0 liblwp-mediatypes-perl liblwp-protocol-https-perl libmailtools-perl libnet-http-perl libnet-smtp-ssl-perl libnet-ssleay-perl libnetcf1 libnetpbm10 libogg0 libopus0 liborc-0.4-0 libosinfo-1.0-0 libpango-1.0-0 libpangocairo-1.0-0 libpangoft2-1.0-0 libpangoxft-1.0-0 libpaper-utils libpaper1 libphodav-2.0-0 libphodav-2.0-common libproxy1v5 libpulse-mainloop-glib0 libpulse0 librdmacm1 librest-0.7-0 librhash0 librsvg2-2 librsvg2-common libsdl1.2debian libsndfile1 libsoup-gnome2.4-1 libsoup2.4-1 libspice-client-glib-2.0-8 libspice-client-gtk-3.0-5 libstring-shellquote-perl libthai-data libthai0 libtheora0 libtimedate-perl libtry-tiny-perl liburi-perl libusbredirhost1 libusbredirparser1 libvisual-0.4-0 libvorbis0a libvorbisenc2 libvte-2.91-0 libvte-2.91-common libwin-hivex-perl libwww-perl libwww-robotrules-perl libxcomposite1 libxcursor1 libxen-4.9 libxenstore3.0 libxft2 libxi6 libxinerama1 libxkbcommon0 libxml-parser-perl libxml-xpath-perl libxml2-utils libxrandr2 libxtst6 libyajl2 lzop mtools netpbm osinfo-db perl-openssl-defaults poppler-data python-certifi python-chardet python-ipaddr python-libxml2 python-openssl python-requests python-urllib3 reiserfsprogs scrub sharutils spice-client-glib-usb-acl-helper supermin ubuntu-mono x11-common zerofree Use 'apt autoremove' to remove them. The following additional packages will be installed: binutils-arm-none-eabi libnewlib-arm-none-eabi libnewlib-dev libstdc++-arm-none-eabi-newlib Suggested packages: libnewlib-doc The following NEW packages will be installed: binutils-arm-none-eabi gcc-arm-none-eabi libnewlib-arm-none-eabi libnewlib-dev libstdc++-arm-none-eabi-newlib 0 upgraded, 5 newly installed, 0 to remove and 296 not upgraded. Need to get 119 MB of archives. After this operation, 1,123 MB of additional disk space will be used. Do you want to continue? [Y/n] y Get:1 http://hk.ports.ubuntu.com/ubuntu-ports bionic/universe arm64 binutils-arm-none-eabi arm64 2.27-9ubuntu1+9 [1,873 kB] Get:2 http://hk.ports.ubuntu.com/ubuntu-ports bionic/universe arm64 gcc-arm-none-eabi arm64 15:6.3.1+svn253039-1build1 [23.2 MB] Get:3 http://hk.ports.ubuntu.com/ubuntu-ports bionic-updates/universe arm64 libnewlib-dev all 2.4.0.20160527-3ubuntu0.1 [108 kB] Get:4 http://hk.ports.ubuntu.com/ubuntu-ports bionic-updates/universe arm64 libnewlib-arm-none-eabi all 2.4.0.20160527-3ubuntu0.1 [19.1 MB] Get:5 http://hk.ports.ubuntu.com/ubuntu-ports bionic/universe arm64 libstdc++-arm-none-eabi-newlib all 15:6.3.1+svn253039-1+10 [74.8 MB] Fetched 119 MB in 35s (3,415 kB/s) Selecting previously unselected package binutils-arm-none-eabi. (Reading database ... 146910 files and directories currently installed.) Preparing to unpack .../binutils-arm-none-eabi_2.27-9ubuntu1+9_arm64.deb ... Unpacking binutils-arm-none-eabi (2.27-9ubuntu1+9) ... Selecting previously unselected package gcc-arm-none-eabi. Preparing to unpack .../gcc-arm-none-eabi_15%3a6.3.1+svn253039-1build1_arm64.deb ... Unpacking gcc-arm-none-eabi (15:6.3.1+svn253039-1build1) ... Selecting previously unselected package libnewlib-dev. Preparing to unpack .../libnewlib-dev_2.4.0.20160527-3ubuntu0.1_all.deb ... Unpacking libnewlib-dev (2.4.0.20160527-3ubuntu0.1) ... Selecting previously unselected package libnewlib-arm-none-eabi. Preparing to unpack .../libnewlib-arm-none-eabi_2.4.0.20160527-3ubuntu0.1_all.deb ... Unpacking libnewlib-arm-none-eabi (2.4.0.20160527-3ubuntu0.1) ... Selecting previously unselected package libstdc++-arm-none-eabi-newlib. Preparing to unpack .../libstdc++-arm-none-eabi-newlib_15%3a6.3.1+svn253039-1+10_all.deb ... Unpacking libstdc++-arm-none-eabi-newlib (15:6.3.1+svn253039-1+10) ... Processing triggers for libc-bin (2.27-3ubuntu1) ... Setting up libnewlib-dev (2.4.0.20160527-3ubuntu0.1) ... Setting up binutils-arm-none-eabi (2.27-9ubuntu1+9) ... Processing triggers for man-db (2.8.3-2ubuntu0.1) ... Setting up libnewlib-arm-none-eabi (2.4.0.20160527-3ubuntu0.1) ... Setting up libstdc++-arm-none-eabi-newlib (15:6.3.1+svn253039-1+10) ... Setting up gcc-arm-none-eabi (15:6.3.1+svn253039-1build1) ... Processing triggers for libc-bin (2.27-3ubuntu1) ... root@ubuntu:~# arm-none-eabi-gcc -v Using built-in specs. COLLECT_GCC=arm-none-eabi-gcc COLLECT_LTO_WRAPPER=/usr/lib/gcc/arm-none-eabi/6.3.1/lto-wrapper Target: arm-none-eabi Configured with: ../src/configure --build=aarch64-linux-gnu --prefix=/usr --includedir='/usr/lib/include' --mandir='/usr/lib/share/man' --infodir='/usr/lib/share/info' --sysconfdir=/etc --localstatedir=/var --disable-silent-rules --libdir='/usr/lib/lib/aarch64-linux-gnu' --libexecdir='/usr/lib/lib/aarch64-linux-gnu' --disable-maintainer-mode --disable-dependency-tracking --mandir=/usr/share/man --enable-languages=c,c++,lto --enable-multilib --disable-decimal-float --disable-libffi --disable-libgomp --disable-libmudflap --disable-libquadmath --disable-libssp --disable-libstdcxx-pch --disable-nls --disable-shared --disable-threads --disable-tls --build=aarch64-linux-gnu --target=arm-none-eabi --with-system-zlib --with-gnu-as --with-gnu-ld --with-pkgversion=15:6.3.1+svn253039-1build1 --without-included-gettext --prefix=/usr/lib --infodir=/usr/share/doc/gcc-arm-none-eabi/info --htmldir=/usr/share/doc/gcc-arm-none-eabi/html --pdfdir=/usr/share/doc/gcc-arm-none-eabi/pdf --bindir=/usr/bin --libexecdir=/usr/lib --libdir=/usr/lib --disable-libstdc++-v3 --host=aarch64-linux-gnu --with-headers=no --without-newlib --with-multilib-list=rmprofile CFLAGS='-g -O2 -fdebug-prefix-map=/build/gcc-arm-none-eabi-lUs__4/gcc-arm-none-eabi-6.3.1+svn253039=. -fstack-protector-strong' CPPFLAGS='-Wdate-time -D_FORTIFY_SOURCE=2' CXXFLAGS='-g -O2 -fdebug-prefix-map=/build/gcc-arm-none-eabi-lUs__4/gcc-arm-none-eabi-6.3.1+svn253039=. -fstack-protector-strong' FCFLAGS='-g -O2 -fdebug-prefix-map=/build/gcc-arm-none-eabi-lUs__4/gcc-arm-none-eabi-6.3.1+svn253039=. -fstack-protector-strong' FFLAGS='-g -O2 -fdebug-prefix-map=/build/gcc-arm-none-eabi-lUs__4/gcc-arm-none-eabi-6.3.1+svn253039=. -fstack-protector-strong' GCJFLAGS='-g -O2 -fdebug-prefix-map=/build/gcc-arm-none-eabi-lUs__4/gcc-arm-none-eabi-6.3.1+svn253039=. -fstack-protector-strong' LDFLAGS='-Wl,-Bsymbolic-functions -Wl,-z,relro' OBJCFLAGS='-g -O2 -fdebug-prefix-map=/build/gcc-arm-none-eabi-lUs__4/gcc-arm-none-eabi-6.3.1+svn253039=. -fstack-protector-strong' OBJCXXFLAGS='-g -O2 -fdebug-prefix-map=/build/gcc-arm-none-eabi-lUs__4/gcc-arm-none-eabi-6.3.1+svn253039=. -fstack-protector-strong' INHIBIT_LIBC_CFLAGS=-DUSE_TM_CLONE_REGISTRY=0 AR_FOR_TARGET=arm-none-eabi-ar AS_FOR_TARGET=arm-none-eabi-as LD_FOR_TARGET=arm-none-eabi-ld NM_FOR_TARGET=arm-none-eabi-nm OBJDUMP_FOR_TARGET=arm-none-eabi-objdump RANLIB_FOR_TARGET=arm-none-eabi-ranlib READELF_FOR_TARGET=arm-none-eabi-readelf STRIP_FOR_TARGET=arm-none-eabi-strip Thread model: single gcc version 6.3.1 20170620 (15:6.3.1+svn253039-1build1) root@ubuntu:~# arm-none-eabi-ld -v GNU ld (2.27-9ubuntu1+9) 2.27 root@ubuntu:~# uname -a Linux ubuntu 5.0.0-23-generic #24~18.04.1-Ubuntu SMP Mon Jul 29 16:10:24 UTC 2019 aarch64 aarch64 aarch64 GNU/Linux root@ubuntu:~#
一个例子
cat include/cm3.h #ifndef CM3_H #define CM3_H #include <stdint.h> #define SCS_BASE (0xE000E000) /*System Control Space Base Address */ #define SYSTICK_BASE (SCS_BASE + 0x0010) /*SysTick Base Address*/ #define SCB_BASE (SCS_BASE + 0x0D00) #define HSI_CLK 12000000UL #define SYSTICK_PRIO_REG (0xE000ED23) typedef struct systick_tag { volatile uint32_t ctrl; volatile uint32_t load; volatile uint32_t val; volatile uint32_t calrb; }systick_t; extern uint32_t get_psp(void); extern uint32_t get_msp(void); extern uint32_t get_control_reg(void); extern void init_systick(void); #endif /*CM3_H*/
root@ubuntu:~/arm/rtos/02_cm3# cat cm3_s.s .text .code 16 .global main .global reset_handler .global _p_stack_top .global get_psp .global get_msp .global get_control_reg reset_handler: /*Set the stack as process stack*/ mov r0, #33 mrs r0, CONTROL mov r1, #2 orr r0, r1 msr CONTROL, r0 ldr r0, =_p_stack_top mov sp, r0 ldr r0, =main blx r0 b . get_psp: mrs r0, PSP blx lr get_msp: mrs r0, MSP blx lr get_control_reg: mrs r0, CONTROL blx lr
root@ubuntu:~/arm/rtos/02_cm3# cat main.c #include "os_stdio.h" #include <stdint.h> #include "cm3.h" extern uint32_t _bss; extern uint32_t _ebss; static inline void clear_bss(void) { uint8_t *start = (uint8_t *)_bss; while ((uint32_t)start < _ebss) { *start = 0; start++; } } void systick_handler(void) { DEBUG("systick_handler\n"); } int main() { systick_t *systick_p = (systick_t *)SYSTICK_BASE; clear_bss(); DEBUG("Hello RTOS\n"); DEBUG("psp:0x%x\n", get_psp()); DEBUG("msp:0x%x\n", get_msp()); init_systick(); while(1) { } return 0; }
qemu-system-arm -M lm3s6965evb --kernel rtos.bin -nographic Hello RTOS psp:0x20007ff0 msp:0x2000c000 systick_handler systick_handler systick_handler systick_handler systick_handler systick_handler systick_handler systick_handler systick_handler systick_handler
启动分析
root@ubuntu:~/arm/rtos/02_cm3# objdump -s -j .text rtos.elf rtos.elf: file format elf32-littlearm Contents of section .text: 0000 00c00020 b90c0000 6d020000 73020000 ... ....m...s... 0010 79020000 79020000 79020000 00000000 y...y...y....... 0020 00000000 00000000 00000000 79020000 ............y... 0030 79020000 00000000 79020000 c1020000 y.......y....... 0040 79020000 79020000 79020000 79020000 y...y...y...y... 0050 79020000 79020000 79020000 79020000 y...y...y...y... 0060 79020000 79020000 79020000 79020000 y...y...y...y... 0070 79020000 79020000 79020000 79020000 y...y...y...y... 0080 79020000 79020000 79020000 79020000 y...y...y...y... 0090 79020000 79020000 79020000 79020000 y...y...y...y... 00a0 79020000 79020000 79020000 79020000 y...y...y...y... 00b0 79020000 79020000 79020000 79020000 y...y...y...y... 00c0 79020000 79020000 79020000 79020000 y...y...y...y... 00d0 79020000 79020000 79020000 79020000 y...y...y...y... 00e0 79020000 79020000 79020000 79020000 y...y...y...y... 00f0 79020000 79020000 79020000 79020000 y...y...y...y... 0100 79020000 79020000 79020000 79020000 y...y...y...y... 0110 79020000 79020000 79020000 79020000 y...y...y...y... 0120 79020000 79020000 79020000 79020000 y...y...y...y... 0130 79020000 79020000 79020000 79020000 y...y...y...y... 0140 00000000 00000000 00000000 00000000 ................ 0150 79020000 79020000 79020000 79020000 y...y...y...y...
root@ubuntu:~/arm/rtos/02_cm3# arm-none-eabi-objdump -h rtos.elf | head rtos.elf: file format elf32-littlearm Sections: Idx Name Size VMA LMA File off Algn 0 .text 00000d80 00000000 00000000 00010000 2**2 CONTENTS, ALLOC, LOAD, READONLY, CODE 1 .debug_info 00000bd3 00000000 00000000 00010d80 2**0 CONTENTS, READONLY, DEBUGGING 2 .debug_abbrev 0000037a 00000000 00000000 00011953 2**0 root@ubuntu:~/arm/rtos/02_cm3# arm-none-eabi-objdump -h rtos.elf rtos.elf: file format elf32-littlearm Sections: Idx Name Size VMA LMA File off Algn 0 .text 00000d80 00000000 00000000 00010000 2**2 CONTENTS, ALLOC, LOAD, READONLY, CODE 1 .debug_info 00000bd3 00000000 00000000 00010d80 2**0 CONTENTS, READONLY, DEBUGGING 2 .debug_abbrev 0000037a 00000000 00000000 00011953 2**0 CONTENTS, READONLY, DEBUGGING 3 .debug_loc 00000894 00000000 00000000 00011ccd 2**0 CONTENTS, READONLY, DEBUGGING 4 .debug_aranges 000000a0 00000000 00000000 00012568 2**3 CONTENTS, READONLY, DEBUGGING 5 .debug_line 000003e8 00000000 00000000 00012608 2**0 CONTENTS, READONLY, DEBUGGING 6 .debug_str 0000032e 00000000 00000000 000129f0 2**0 CONTENTS, READONLY, DEBUGGING 7 .comment 00000031 00000000 00000000 00012d1e 2**0 CONTENTS, READONLY 8 .ARM.attributes 00000031 00000000 00000000 00012d4f 2**0 CONTENTS, READONLY 9 .debug_frame 00000440 00000000 00000000 00012d80 2**2 CONTENTS, READONLY, DEBUGGING
root@ubuntu:~/arm/rtos/02_cm3# arm-none-eabi-objdump -S rtos.elf | head rtos.elf: file format elf32-littlearm Disassembly of section .text: 00000000 <_text>: 0: 2000c000 .word 0x2000c000 4: 00000cb9 .word 0x00000cb9 8: 0000026d .word 0x0000026d
Cortex-M4也是从0x0000_0000开始执行的,中断向量表也是从这里起始,中断向量标的第一个地址是sp(Stack Top),第二个地址是Reset_Handler(复位中断),上电之后先赋值sp,然后跳转的Reset_Handler
简单的启动代码
从NXP官方的示例中截取了一部分汇编码 因为我们只需要做到最简单的启动,所以只需要前两个中断向量
- 向量表部分代码
.section .isr_vector, "a" /*单独定义一个.isr_vector段,在ld script中设定向量表的内存位置*/ .align 2 .globl __isr_vector __isr_vector: .long __StackTop /*Top Stack定义在ld script中, 之后会说到*/ .long Reset_Handler /* Reset Handler */
等效于
typedef void (*vector_handler)(void); extern void Reset_Handler(); extern char __StackTop[]; // __StackTop在ld script中需要声明 __attribute__((section(".isr_vector"))) // 将VectroTable放入.isr_vector段中 vector_handler VectorTable[] = { (vector_handler)__StackTop, Reset_Handler };
//.FlashConfig段也不可忽略,汇编中并没有写出来
__attribute__((section(".FlashConfig"))) long FlashConfig[] = { 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFE };
- Reset_Handler 部分代码
.text .thumb .thumb_func .global Reset_Handler .align 2 .weak Reset_Handler .type Reset_Handler, %function Reset_Handler: cpsid i /*关闭全局中断*/ BL start /*跳转的C语言start函数*/ B .
等效于
void Reset_Handler() { __asm__("cpsid i"); start(); while(1); }
qemu
./configure --target-list=arm-softmmu,arm-linux-user