100字范文,内容丰富有趣,生活中的好帮手!
100字范文 > 在 windows 7 和 MinGW 下编译 OpenOCD 过程

在 windows 7 和 MinGW 下编译 OpenOCD 过程

时间:2022-08-17 02:05:11

相关推荐

在 windows 7 和 MinGW 下编译 OpenOCD 过程

先说一下我的软硬件环境:

硬件:

一块评估板Atmel SAMD21 xplained pro 没有普通的 Jtag 口, 它提供了 EDBG USB 口, 支持 CMSIS-DAP, OpenOCD 又支持 CMSIS-DAP 接口.

开发软件:

VS +VisualGDB+OpenOCD, VisualGDB 自带的 OpenOCD 不支持 SAMD21,最新的 OpenOCD 支持;

以前图省事经常从网上下载最新的 OpenOCD 执行文件,这两天估计这个原因中招了.

操作系统: Win7 x64

痛定思痛,决心从源代码编译 OpenOCD ,不想用 Cygwin 因为带一堆动态库,采用 MinGW 编译成单个执行文件,这里记录下整个过程,方便有需要的人.

1.预先安装 git for windows 1.9.4 /msysgit/msysg ... preview0815.exe

2.下载 MinGW 安装程序

mingw-get-setup.exe/projects/ ... wnload?source=files

运行 mingw-get-setup.exe 选择一个安装目录, 比如 F:/MinGW

注意只选择 Basic Setup 的 msys-base 环境,不要安装 mingw 的 gcc 开发工具.

然后在 All packages 选择:

msys-autoconf

msys-autogen

msys-automake

msys-libtool

msys-rxvt

msys-unzip

msys-wget

msys-vim

的 bin doc lic

最后在 install 菜单选择 Apply change 在对话框中选择 apply 等待安装完成

安装完成后,应该有 F:/MinGW/msys/1.0/msys.bat 文件,

在桌面创建快捷方式 msys,目标: F:\MingW\msys\1.0\msys.bat --rxvt 起始位置:F:\MinGW\msys\1.0\bin

这个快捷方式有两个优点,

a:在 msys 环境中鼠标选择的内容自动复制到粘贴板,

b:支持 shfit+ins 粘贴

运行这个快捷方式应该出现如下界面:

3.安装 mingw gcc 工具链和开发环境,参考网址:http://win-/1.4.0/msys-cygwin.html

运行第二步创建的快捷方式,进入 mingw 环境,以后除指明,均在 msys 环境下:

$wgethttp://win-/1.4.0/yypkg-1.4.0.exe

如下:

---09-01 21:46:17--http://win-/1.4.0/yypkg-1.4.0.exe

Resolving win-... 91.121.71.147

Connecting to win-|91.121.71.147|:80... connected.

HTTP request sent, awaiting response... 200 OK

Length: 2348046 (2.2M) [application/x-msdos-program]

Saving to: `yypkg-1.4.0.exe'

100%[=====================================>] 2,348,046 6.63K/s in 2m 2s =

-09-01 21:48:51 (18.8 KB/s) - `yypkg-1.4.0.exe' saved [2348046/2348046]

运行:

$ ./yypkg-1.4.0.exe --deploy --host msys

会有三个问题,

第一个问题,是否安装 i686(win32) 版本gcc, 输入: yes

第二个问题, 是否安装 x64 版本gcc,我们用不着, 输入: no

第三个问题, 无法自动确定 MinGW 安装位置, 要求输入 MinGW 安装位置全路径, 我的是 F:/MinGW/msys/1.0 ,要根据你自己的位置选择, 输入:F:/MinGW/msys/1.0

Using mirror "http://win-/1.4.0".

Do you want to install for i686?

Chose one of yes, no (case-insensitive).

yes

Do you want to install for x86_64?

Chose one of yes, no (case-insensitive).

no

Couldn't automatically find the MSYS installation path.

Please provide it in full as a Windows path with forward-slashes.

For example C:/MinGW/msys/1.0; toolchain will be put in C:/MSYS/opt/windows_32.

(environment variables of the form ${FOO} are understood).

F:/MinGW/msys/1.0

Installing win-builds 32 in "F:/MinGW/msys/1.0\\/opt/windows_32" for "MSYS".

Press return to continue or Ctrl-C to abort.

按 回车 开始

安装好后切换到 win-builds 开发环境:

. /opt/windows_32/bin/win-builds-switch 32

也可以添加到 .profile 设置为默认开发环境

echo '. /opt/windows_32/bin/win-builds-switch 32' >> ~/.profile

顺便加上 ll 和 dir 命令

echo "alias dir='ls -la --color=auto'" >> ~/.profile

echo "alias ll='ls -la --color=auto'" >> ~/.profile

source .profile

切换到 win-builds 环境,输入 gcc --version 应该输出:

$ gcc --version

gcc.exe (GCC) 4.8.2

Copyright (C) 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.

4.安装 pkg-config 包管理系统,网上很多windos下编译 OpenOCD 出问题,很多和 pkg-config 管理系统有关

这里采用 上的 pkg-config lite 版本

$wget/projects/ ... wnload?source=files-O pkgcfglite.zip

$unzip pkgcfglite.zip -d ./pkgcfg

不要忘了复制 pkg-config m4 文件

$ cp ./pkgcfg/pkg-config-lite-0.28-1/share/aclocal/pkg.m4 /share/aclocal/

5. OpenOCD CMSIS-DAP 需要 libusb-1.0 HIDAPI 库

下载 hidapi:

$ cd ~

$ git clone/signal11/hidapi.git

$ cd hidapi

$ ./bootstrap

$ ./configure

whenundefined reference to `_spawnv'

./configure --disable-shared

This builds static libraries only, not DLLs.

$ make

$ make install

$ cd ~

会把 hidapi 库安装到 /usr/local/lib 目录下,

$ ll /usr/local/lib 应是这样:

$ ll /usr/local/lib

total 47

drwxr-xr-x 3 Home Administrators4096 Sep2 00:01 .

drwxr-xr-x 6 Home Administrators 0 Sep2 00:01 ..

-rw-r--r-- 1 Home Administrators 29134 Sep2 00:01 libhidapi.a

-rw-r--r-- 1 Home Administrators 12380 Sep2 00:00 libhidapi.dll.a

-rw-r--r-- 1 Home Administrators 917 Sep2 00:01 libhidapi.la

drwxr-xr-x 2 Home Administrators 0 Sep2 00:01 pkgconfig

下载 libusb-1.0

$ cd ~

$ wget/projects/ ... wnload?source=files-O libusb-1.0.19.tar.bz2

$ tar xf libusb-1.0.19.tar.bz2

$ cd libusb-1.0.19

$ ./configure

$ make

$ make install

同样的 make install 把 libusb-1.0 库安装到了 /usr/local/lib 中

$ ll /usr/local/lib

total 660

drwxr-xr-x 3 Home Administrators 4096 Sep2 00:10 .

drwxr-xr-x 6 Home Administrators 0 Sep2 00:01 ..

-rw-r--r-- 1 Home Administrators29134 Sep2 00:01 libhidapi.a

-rw-r--r-- 1 Home Administrators12380 Sep2 00:00 libhidapi.dll.a

-rw-r--r-- 1 Home Administrators 917 Sep2 00:01 libhidapi.la

-rw-r--r-- 1 Home Administrators 493218 Sep2 00:10 libusb-1.0.a

-rw-r--r-- 1 Home Administrators 132304 Sep2 00:10 libusb-1.0.dll.a

-rw-r--r-- 1 Home Administrators 911 Sep2 00:10 libusb-1.0.la

drwxr-xr-x 2 Home Administrators 0 Sep2 00:10 pkgconfig

OpenOCD 编译时默认连接 hidapi 和 libusb-1.0 的动态库,因此 把 静态库 覆盖 动态库

$ cp /usr/local/lib/libhidapi.a /usr/local/lib/libhidapi.dll.a

$ cp /usr/local/lib/libusb-1.0.a /usr/local/lib/libusb-1.0.dll.a

6.下载 OpenOCD

OponOCD 有几个源,我用的是这个

$ cd ~

$ git clone/p/openocd.git

$ cd openocd

$ ./bootstrap

$ ./configure PKG_CONFIG_PATH=/usr/local/lib/pkgconfig LDFLAGS="-Wl,-s"

$ make

然后就在 src 目录下出现了无dll依赖的 openocd.exe 大概 2M

退出 msys 环境, 在 win7 命令行模式下:

F:

cd F:/mingw/msys/1.0/home/Home/openocd/src

openocd.exe-s ../tcl -f interface/cmsis-dap.cfg -f board/atmel_samd21_xplained_pro.cfg

Open On-Chip Debugger 0.9.0-dev-00131-gbd0409a (-09-02-00:31)

Licensed under GNU GPL v2

For bug reports, read

/doc/doxygen/bugs.html

Info : only one transport option; autoselect 'cmsis-dap'

Warn : Interface already configured, ignoring

adapter speed: 500 kHz

adapter_nsrst_delay: 100

cortex_m reset_config sysresetreq

Info : CMSIS-DAP: SWDSupported

Info : CMSIS-DAP: Interface Initialised (SWD)

Info : CMSIS-DAP: FW Version = 01.1B.00FC

Info : SWCLK/TCK = 1 SWDIO/TMS = 1 TDI = 1 TDO = 1 nTRST = 0 nRESET = 1

Info : DAP_SWJ Sequence (reset: 50+ '1' followed by 0)

Info : CMSIS-DAP: Interface ready

Info : clock speed 500 kHz

Info : IDCODE 0x0bc11477

Info : at91samd21j18.cpu: hardware has 4 breakpoints, 2 watchpoints

至此 OpenOCD 编译完成.

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。