手机一键建站,制作电子商务网站页面,爱站网长尾关键词挖掘工具福利片,二级域名分发平台目录
1. 准备工作
2. 运行bootstrap
3. 运行Configure
4. 编译make
4.1 错误1
4.2 错误2
4.3 错误3
4.4 错误4
4.5 错误5
4.6 错误6
4.7 错误7
5. 安装 主要是使用NDK编译OpenOCD源码。最好先在Ubuntu中编译通过OpenOCD。
1. 准备工作
Ubuntu下下载NDK和OpenOCD在OpenOCD的源代码目录内新建文件envsetup.sh配置编译环境。
#!/bin/shexport NDK/home/pq/android-ndk-r17c
export TOOLCHAIN$NDK/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64
export TARGETarm-linux-androideabi
export API21
export AR$TOOLCHAIN/bin/$TARGET-ar
export CC$TOOLCHAIN/bin/$TARGET-gcc
export AS$CC
export CXX$TOOLCHAIN/bin/$TARGET-g
export LD$TOOLCHAIN/bin/$TARGET-ld
export RANLIB$TOOLCHAIN/bin/$TARGET-ranlib
export STRIP$TOOLCHAIN/bin/$TARGET-strip
export HOST$TARGET
export ANDROID_SYSROOT$NDK/platforms/android-$API/arch-arm
export CPPFLAGS--sysroot$ANDROID_SYSROOT -I$NDK/sysroot/usr/include -I$NDK/sysroot/usr/include/$TARGET -D__ANDROID_API__$API
export CFLAGS--sysroot$ANDROID_SYSROOT -I$NDK/sysroot/usr/include -I$NDK/sysroot/usr/include/$TARGET -D__ANDROID_API__$API
export CXXFLAGS--sysroot$ANDROID_SYSROOT -I$NDK/sysroot/usr/include -I$NDK/sysroot/usr/include/$TARGET -D__ANDROID_API__$APIecho NDK$NDK
echo TOOLCHAIN$TOOLCHAIN
echo TARGET$TARGET
echo API$API
echo AR$AR
echo CC$CC
echo AS$AS
echo CXX$CXX
echo RANLIB$RANLIB
echo STRIP$STRIP
echo ANDROID_SYSROOT$ANDROID_SYSROOT
2. 运行bootstrap
./bootstrap
如果有编译过OpenOCD这一步应该会通过。
3. 运行Configure
./configure --host $HOST
提示一个错误
configure: error: ./configure.gnu failed for jimtcl
看log可以看出是配置jimtcl出问题。修改命令
./configure --host$HOST
此时可以看到配置通过不过由于一部分库不存在会有一些功能不支持。如果不需要这部分设备支持可以不处理例如常见的FTDI设备ST-Link、CMSIS-DAPv2等设备都支持了。
OpenOCD configuration summary
--------------------------------------------------
MPSSE mode of FTDI based devices yes (auto)
ST-Link Programmer yes (auto)
TI ICDI JTAG Programmer yes (auto)
Keil ULINK JTAG Programmer yes (auto)
ANGIE Adapter yes (auto)
Altera USB-Blaster II Compatible yes (auto)
Bitbang mode of FT232R based devices yes (auto)
Versaloon-Link JTAG Programmer yes (auto)
TI XDS110 Debug Probe yes (auto)
CMSIS-DAP v2 Compliant Debugger yes (auto)
OSBDM (JTAG only) Programmer yes (auto)
eStick/opendous JTAG Programmer yes (auto)
Olimex ARM-JTAG-EW Programmer yes (auto)
Raisonance RLink JTAG Programmer yes (auto)
USBProg JTAG Programmer yes (auto)
Espressif JTAG Programmer yes (auto)
CMSIS-DAP Compliant Debugger no
Nu-Link Programmer no
Cypress KitProg Programmer no
Altera USB-Blaster Compatible no
ASIX Presto Adapter no
OpenJTAG Adapter no
Linux GPIO bitbang through libgpiod no
SEGGER J-Link Programmer no
Bus Pirate yes (auto)
Use Capstone disassembly framework no
如果需要支持这些设备可能是要尝试编译下面的库
checking for capstone... no
checking for hidapi... no
checking for hidapi-hidraw... no
checking for hidapi-libusb... no
checking for libftdi1... no
checking for libftdi... no
checking for libgpiod... no
checking for libjaylink 0.2... no
4. 编译make
运行编译代码
make
出现很多错误提示。
4.1 错误1 error: annotate attribute directive ignored [-Werrorattributes]
这个的错误可能是由于使用了GCC编译器的一个特定警告选项-Werrorattributes该选项会将所有属性相关的警告转换为错误。annotate是C17引入的一个属性它允许开发者为变量、函数等指定额外的元数据。如果代码中使用了这个属性但是编译器并不支持C17或者更新的版本那么就会看到这个错误。
在envsetup.sh中添加-Wno-attributes去掉这个选项
export CPPFLAGS--sysroot$ANDROID_SYSROOT -I$NDK/sysroot/usr/include -I$NDK/sysroot/usr/include/$TARGET -D__ANDROID_API__$API -Wno-attributes
export CFLAGS--sysroot$ANDROID_SYSROOT -I$NDK/sysroot/usr/include -I$NDK/sysroot/usr/include/$TARGET -D__ANDROID_API__$API -Wno-attributes
export CXXFLAGS--sysroot$ANDROID_SYSROOT -I$NDK/sysroot/usr/include -I$NDK/sysroot/usr/include/$TARGET -D__ANDROID_API__$API -Wno-attributes
改好后需要重新运行一下envsetup.sh和configure这个错误就没有了。
4.2 错误2
error: __swab32s defined but not used [-Werrorunused-function]
这个错误是和NDK编译环境有关没找到解决方法只能修改NDK里面这个定义在swab.h里面
static __always_inline void __swab32s(__u32 * p)
中的__always_inline改为inline
static inline void __swab32s(__u32 * p)
4.3 错误3
error: redundant redeclaration of __assert [-Werrorredundant-decls]
在envsetup.sh中添加-DNDEBUG去掉assert
export CPPFLAGS--sysroot$ANDROID_SYSROOT -I$NDK/sysroot/usr/include -I$NDK/sysroot/usr/include/$TARGET -D__ANDROID_API__$API -Wno-attributes -DNDEBUG
export CFLAGS--sysroot$ANDROID_SYSROOT -I$NDK/sysroot/usr/include -I$NDK/sysroot/usr/include/$TARGET -D__ANDROID_API__$API -Wno-attributes -DNDEBUG
export CXXFLAGS--sysroot$ANDROID_SYSROOT -I$NDK/sysroot/usr/include -I$NDK/sysroot/usr/include/$TARGET -D__ANDROID_API__$API -Wno-attributes -DNDEBUG
在ftdi.c中去掉include这个函数
//#include assert.h
在/openocd-code/src/target/riscv/riscv-011.c 去掉include assert.h
在/openocd-code/src/target/riscv/riscv-013.c 去掉include assert.h
在/openocd-code/src/target/riscv/riscv.c去掉include assert.h
在/openocd-code/src/target/xtensa/xtensa.h去掉include assert.h
发现无效最后是将所有的assert去掉求高手提供最佳的解法。
4.4 错误4
src/flash/nor/rsl10.c:159:21: error: unused variable chip [-Werrorunused-variable]
在envsetup.sh中CFLAGS添加-Wno-unused-variable
4.5 错误5
error: declaration of read shadows a global declaration [-Werrorshadow]
这个错误是变量read已经被申明为一个全局申明NDK里面已经有一个read了将这个变量改成其他名字sinkread
4.6 错误6
error: undefined reference to libusb_release_interface
在configure时可以看到libusb的库是yes
checking for libusb-1.0... yes
configure: libusb-1.0 header bug workaround: LIBUSB1_CFLAGS changed to -isystem /usr/include/libusb-1.0
需要编译NDK版本的libusb。
4.7 错误7
error: undefined reference to stdout
在对应的c文件添加#include stdio.h
5. 安装
编译通过后可以在src文件夹里面找到openocd的执行文件。