Android下使用OpenOCD

目录

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/sh
 
export NDK=/home/pq/android-ndk-r17c
export TOOLCHAIN=$NDK/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64
export TARGET=arm-linux-androideabi
export API=21
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__=$API"
 
echo "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 [-Werror=attributes]

这个的错误可能是由于使用了GCC编译器的一个特定警告选项(-Werror=attributes),该选项会将所有属性相关的警告转换为错误。'annotate'是C++17引入的一个属性,它允许开发者为变量、函数等指定额外的元数据。如果代码中使用了这个属性,但是编译器并不支持C++17或者更新的版本,那么就会看到这个错误。

在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 [-Werror=unused-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' [-Werror=redundant-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' [-Werror=unused-variable]

在envsetup.sh中CFLAGS添加-Wno-unused-variable

4.5 错误5

error: declaration of 'read' shadows a global declaration [-Werror=shadow]

这个错误是变量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的执行文件。

相关推荐

  1. Android使用OpenOCD

    2024-03-11 01:40:03       19 阅读
  2. Android】Glide的简单使用

    2024-03-11 01:40:03       36 阅读
  3. Makefile+OpenOCD开发STM32

    2024-03-11 01:40:03       20 阅读
  4. Android】WebView 基本使用

    2024-03-11 01:40:03       28 阅读

最近更新

  1. TCP协议是安全的吗?

    2024-03-11 01:40:03       18 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-03-11 01:40:03       19 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-03-11 01:40:03       18 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-03-11 01:40:03       20 阅读

热门阅读

  1. AJAX-查询参数

    2024-03-11 01:40:03       18 阅读
  2. springboot集成 mongodb以及mongodb简单工具类

    2024-03-11 01:40:03       17 阅读
  3. python xml 解析

    2024-03-11 01:40:03       22 阅读
  4. 设计模式: 模板方法模式

    2024-03-11 01:40:03       23 阅读
  5. Linux命令

    2024-03-11 01:40:03       21 阅读
  6. 如何利用python实现自己的modbus-tcp库

    2024-03-11 01:40:03       23 阅读
  7. 《TCP/IP详解 卷一》第14章 TCP超时与重传

    2024-03-11 01:40:03       18 阅读
  8. Android学习笔记 Dialog

    2024-03-11 01:40:03       20 阅读