Compare commits
No commits in common. "tinyriscv" and "riscv" have entirely different histories.
|
@ -99,5 +99,3 @@ TAGS
|
|||
|
||||
# ctags tag files
|
||||
tags
|
||||
|
||||
release/
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
[submodule "jimtcl"]
|
||||
path = jimtcl
|
||||
url = https://gitee.com/liangkangnan/jimtcl
|
||||
url = https://github.com/msteveb/jimtcl
|
||||
|
|
55
README.md
55
README.md
|
@ -1,55 +0,0 @@
|
|||
# 编译Windows版本
|
||||
|
||||
## 1.安装msys2
|
||||
|
||||
到[msys2官网](https://www.msys2.org/)下载安装最新的64位版本,安装完成后打开mingw-32bit窗口,执行以下命令安装依赖:
|
||||
|
||||
`pacman -S autoconf automake pkg-config libtool binutils gcc git make mingw-w64-i686-toolchain mingw-w64-i686-libusb mingw-w64-i686-hidapi mingw-w64-i686-libftdi`
|
||||
|
||||
## 2.下载源码
|
||||
|
||||
下载本项目的所有代码到msys2的某个目录下:
|
||||
|
||||
`git clone --recursive https://gitee.com/liangkangnan/tinyriscv-openocd.git`
|
||||
|
||||
## 3.编译源码
|
||||
|
||||
### 3.1第一次编译或者重新编译
|
||||
|
||||
在项目的根目录下,执行以下命令:
|
||||
|
||||
`./rebuild.sh`
|
||||
|
||||
### 3.2打包openocd.exe
|
||||
|
||||
编译完成后就可以打包了,执行以下命令进行打包:
|
||||
|
||||
`./release.sh`
|
||||
|
||||
打包后的文件在根目录下的release目录里,可以把整个release目录拷贝到电脑的其他目录下使用。
|
||||
|
||||
### 3.3修改源码后编译
|
||||
|
||||
修改源码后,只需要执行make命令即可编译。
|
||||
|
||||
`make`
|
||||
|
||||
编译完可以按照步骤3.2进行打包。
|
||||
|
||||
# 编译Linux版本
|
||||
|
||||
以ubuntu系统为例。
|
||||
|
||||
## 1.安装依赖
|
||||
|
||||
`sudo apt-get install autoconf automake pkg-config libtool libusb-dev libusb-1.0-0-dev libhidapi-dev`
|
||||
|
||||
## 2.编译
|
||||
|
||||
```
|
||||
./bootstrap
|
||||
./configure --enable-remote-bitbang --enable-cmsis-dap --enable-ftdi
|
||||
make
|
||||
```
|
||||
|
||||
编译完成后会在src/目录下生成openocd可执行文件。
|
|
@ -1,70 +0,0 @@
|
|||
/* Autogenerated with ./bin2char.sh */
|
||||
0x97,0x21,0x00,0x00,0x93,0x81,0x01,0x80,0x13,0x81,0x01,0xc0,0x17,0x05,0x00,0x00,
|
||||
0x13,0x05,0x45,0x44,0x97,0x15,0x00,0x00,0x93,0x85,0xc5,0xfe,0x17,0x16,0x00,0x00,
|
||||
0x13,0x06,0x46,0xfe,0x63,0xfc,0xc5,0x00,0x83,0x22,0x05,0x00,0x23,0xa0,0x55,0x00,
|
||||
0x13,0x05,0x45,0x00,0x93,0x85,0x45,0x00,0xe3,0xe8,0xc5,0xfe,0x17,0x15,0x00,0x00,
|
||||
0x13,0x05,0x45,0xfc,0x93,0x85,0x81,0x81,0x63,0x78,0xb5,0x00,0x23,0x20,0x05,0x00,
|
||||
0x13,0x05,0x45,0x00,0xe3,0x6c,0xb5,0xfe,0x13,0x05,0x00,0x00,0x93,0x05,0x00,0x00,
|
||||
0xef,0x00,0x80,0x00,0x6f,0x00,0x00,0x00,0x13,0x01,0x01,0xff,0x23,0x26,0x11,0x00,
|
||||
0x23,0x24,0x81,0x00,0x13,0x04,0x01,0x01,0xb7,0x17,0x00,0x20,0x37,0x17,0x00,0x20,
|
||||
0x13,0x07,0x07,0x50,0x23,0xa0,0xe7,0x00,0xb7,0x17,0x00,0x20,0x37,0x17,0x00,0x20,
|
||||
0x13,0x07,0xc7,0x40,0x23,0xa2,0xe7,0x00,0xb7,0x17,0x00,0x20,0x93,0x87,0x07,0x40,
|
||||
0x03,0xa7,0x07,0x00,0x23,0xa4,0xe1,0x80,0xb7,0x17,0x00,0x20,0x93,0x87,0x47,0x40,
|
||||
0x03,0xa7,0x07,0x00,0x23,0xa6,0xe1,0x80,0xb7,0x17,0x00,0x20,0x93,0x87,0x87,0x40,
|
||||
0x03,0xa7,0x07,0x00,0x23,0xa8,0xe1,0x80,0xb7,0x17,0x00,0x20,0x83,0xa7,0x47,0x00,
|
||||
0x23,0xa0,0x07,0x00,0xef,0x00,0x80,0x08,0x83,0xa7,0x01,0x81,0x63,0x80,0x07,0x02,
|
||||
0x83,0xa7,0xc1,0x80,0x13,0x85,0x07,0x00,0xef,0x00,0x00,0x2c,0x93,0x07,0x05,0x00,
|
||||
0x13,0x87,0x07,0x00,0x23,0x8a,0xe1,0x80,0x6f,0x00,0x00,0x03,0x03,0xa7,0xc1,0x80,
|
||||
0xb7,0x17,0x00,0x20,0x83,0xa6,0x07,0x00,0x83,0xa7,0x81,0x80,0x13,0x86,0x07,0x00,
|
||||
0x93,0x85,0x06,0x00,0x13,0x05,0x07,0x00,0xef,0x00,0x40,0x10,0x93,0x07,0x05,0x00,
|
||||
0x13,0x87,0x07,0x00,0x23,0x8a,0xe1,0x80,0xef,0x00,0x40,0x06,0x83,0xc7,0x41,0x81,
|
||||
0x63,0x8c,0x07,0x00,0xb7,0x17,0x00,0x20,0x83,0xa7,0x47,0x00,0x13,0x07,0x30,0x00,
|
||||
0x23,0xa0,0xe7,0x00,0x6f,0x00,0x40,0x01,0xb7,0x17,0x00,0x20,0x83,0xa7,0x47,0x00,
|
||||
0x13,0x07,0x10,0x00,0x23,0xa0,0xe7,0x00,0x6f,0x00,0x00,0x00,0x13,0x01,0x01,0xff,
|
||||
0x23,0x26,0x81,0x00,0x13,0x04,0x01,0x01,0xb7,0x07,0x00,0x0e,0x03,0xa7,0x07,0x00,
|
||||
0xb7,0x07,0x00,0x0e,0x13,0x67,0x87,0x00,0x23,0xa0,0xe7,0x00,0x13,0x00,0x00,0x00,
|
||||
0x03,0x24,0xc1,0x00,0x13,0x01,0x01,0x01,0x67,0x80,0x00,0x00,0x13,0x01,0x01,0xff,
|
||||
0x23,0x26,0x81,0x00,0x13,0x04,0x01,0x01,0xb7,0x07,0x00,0x0e,0x03,0xa7,0x07,0x00,
|
||||
0xb7,0x07,0x00,0x0e,0x13,0x77,0x77,0xff,0x23,0xa0,0xe7,0x00,0x13,0x00,0x00,0x00,
|
||||
0x03,0x24,0xc1,0x00,0x13,0x01,0x01,0x01,0x67,0x80,0x00,0x00,0x13,0x01,0x01,0xff,
|
||||
0x23,0x26,0x81,0x00,0x13,0x04,0x01,0x01,0xb7,0x07,0x00,0x0e,0x03,0xa7,0x07,0x00,
|
||||
0xb7,0x07,0x00,0x0e,0x13,0x67,0x07,0x01,0x23,0xa0,0xe7,0x00,0x13,0x00,0x00,0x00,
|
||||
0x03,0x24,0xc1,0x00,0x13,0x01,0x01,0x01,0x67,0x80,0x00,0x00,0x13,0x01,0x01,0xff,
|
||||
0x23,0x26,0x81,0x00,0x13,0x04,0x01,0x01,0xb7,0x07,0x00,0x0e,0x03,0xa7,0x07,0x00,
|
||||
0xb7,0x07,0x00,0x0e,0x13,0x77,0xf7,0xfe,0x23,0xa0,0xe7,0x00,0x13,0x00,0x00,0x00,
|
||||
0x03,0x24,0xc1,0x00,0x13,0x01,0x01,0x01,0x67,0x80,0x00,0x00,0x13,0x01,0x01,0xfd,
|
||||
0x23,0x26,0x11,0x02,0x23,0x24,0x81,0x02,0x13,0x04,0x01,0x03,0x23,0x2e,0xa4,0xfc,
|
||||
0x23,0x2c,0xb4,0xfc,0x23,0x2a,0xc4,0xfc,0xb7,0x07,0x00,0x0e,0x03,0xa7,0x07,0x00,
|
||||
0xb7,0x07,0x00,0x0e,0x13,0x77,0x97,0xff,0x23,0xa0,0xe7,0x00,0xb7,0x07,0x00,0x0e,
|
||||
0x03,0xa7,0x07,0x00,0xb7,0x07,0x00,0x0e,0x13,0x67,0x27,0x00,0x23,0xa0,0xe7,0x00,
|
||||
0xb7,0x07,0x00,0x0e,0x93,0x87,0x47,0x00,0x83,0x26,0xc4,0xfd,0x37,0x07,0x80,0x00,
|
||||
0x13,0x07,0xf7,0xff,0x33,0xf7,0xe6,0x00,0x23,0xa0,0xe7,0x00,0x03,0x27,0x44,0xfd,
|
||||
0x93,0x07,0x40,0x00,0x63,0xf4,0xe7,0x00,0xef,0xf0,0x5f,0xf3,0x83,0x27,0x44,0xfd,
|
||||
0x23,0x20,0xf4,0xfe,0x23,0x24,0x04,0xfe,0x6f,0x00,0x40,0x0b,0x03,0x27,0x04,0xfe,
|
||||
0x93,0x07,0x00,0x02,0x63,0xf8,0xe7,0x00,0x93,0x07,0x00,0x02,0x23,0x22,0xf4,0xfe,
|
||||
0x6f,0x00,0xc0,0x00,0x83,0x27,0x04,0xfe,0x23,0x22,0xf4,0xfe,0x03,0x27,0x04,0xfe,
|
||||
0x83,0x27,0x44,0xfe,0xb3,0x07,0xf7,0x40,0x23,0x20,0xf4,0xfe,0x83,0x27,0x44,0xfe,
|
||||
0x93,0xd7,0x27,0x00,0x23,0x22,0xf4,0xfe,0x23,0x26,0x04,0xfe,0x6f,0x00,0x40,0x06,
|
||||
0x83,0x27,0x84,0xfe,0x93,0x97,0x27,0x00,0x03,0x27,0x84,0xfd,0x33,0x07,0xf7,0x00,
|
||||
0xb7,0x07,0x00,0x0e,0x93,0x87,0x87,0x00,0x03,0x27,0x07,0x00,0x23,0xa0,0xe7,0x00,
|
||||
0xb7,0x07,0x00,0x0e,0x03,0xa7,0x07,0x00,0xb7,0x07,0x00,0x0e,0x13,0x67,0x17,0x00,
|
||||
0x23,0xa0,0xe7,0x00,0x13,0x00,0x00,0x00,0xb7,0x07,0x00,0x0e,0x83,0xa7,0x07,0x00,
|
||||
0x93,0xf7,0x17,0x00,0xe3,0x9a,0x07,0xfe,0x83,0x27,0x84,0xfe,0x93,0x87,0x17,0x00,
|
||||
0x23,0x24,0xf4,0xfe,0x83,0x27,0xc4,0xfe,0x93,0x87,0x17,0x00,0x23,0x26,0xf4,0xfe,
|
||||
0x03,0x27,0xc4,0xfe,0x83,0x27,0x44,0xfe,0xe3,0x6c,0xf7,0xf8,0x83,0x27,0x04,0xfe,
|
||||
0xe3,0x96,0x07,0xf4,0x03,0x27,0x44,0xfd,0x93,0x07,0x40,0x00,0x63,0xfe,0xe7,0x00,
|
||||
0xef,0xf0,0xdf,0xe8,0x13,0x00,0x00,0x00,0xb7,0x07,0x00,0x0e,0x83,0xa7,0x07,0x00,
|
||||
0x93,0xf7,0x17,0x00,0xe3,0x9a,0x07,0xfe,0xb7,0x07,0x00,0x0e,0x83,0xa7,0x07,0x00,
|
||||
0x93,0xf7,0x07,0x02,0x63,0x86,0x07,0x00,0x93,0x07,0x00,0x00,0x6f,0x00,0x80,0x00,
|
||||
0x93,0x07,0x10,0x00,0x13,0x85,0x07,0x00,0x83,0x20,0xc1,0x02,0x03,0x24,0x81,0x02,
|
||||
0x13,0x01,0x01,0x03,0x67,0x80,0x00,0x00,0x13,0x01,0x01,0xfe,0x23,0x2e,0x81,0x00,
|
||||
0x13,0x04,0x01,0x02,0x23,0x26,0xa4,0xfe,0xb7,0x07,0x00,0x0e,0x03,0xa7,0x07,0x00,
|
||||
0xb7,0x07,0x00,0x0e,0x13,0x77,0x97,0xff,0x23,0xa0,0xe7,0x00,0xb7,0x07,0x00,0x0e,
|
||||
0x03,0xa7,0x07,0x00,0xb7,0x07,0x00,0x0e,0x13,0x67,0x47,0x00,0x23,0xa0,0xe7,0x00,
|
||||
0xb7,0x07,0x00,0x0e,0x93,0x87,0x47,0x00,0x83,0x26,0xc4,0xfe,0x37,0x07,0x80,0x00,
|
||||
0x13,0x07,0xf7,0xff,0x33,0xf7,0xe6,0x00,0x23,0xa0,0xe7,0x00,0xb7,0x07,0x00,0x0e,
|
||||
0x03,0xa7,0x07,0x00,0xb7,0x07,0x00,0x0e,0x13,0x67,0x17,0x00,0x23,0xa0,0xe7,0x00,
|
||||
0x13,0x00,0x00,0x00,0xb7,0x07,0x00,0x0e,0x83,0xa7,0x07,0x00,0x93,0xf7,0x17,0x00,
|
||||
0xe3,0x9a,0x07,0xfe,0xb7,0x07,0x00,0x0e,0x83,0xa7,0x07,0x00,0x93,0xf7,0x07,0x02,
|
||||
0x63,0x86,0x07,0x00,0x93,0x07,0x00,0x00,0x6f,0x00,0x80,0x00,0x93,0x07,0x10,0x00,
|
||||
0x13,0x85,0x07,0x00,0x03,0x24,0xc1,0x01,0x13,0x01,0x01,0x02,0x67,0x80,0x00,0x00,
|
19
rebuild.sh
19
rebuild.sh
|
@ -1,19 +0,0 @@
|
|||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
|
||||
BASE=`pwd`
|
||||
|
||||
NPROC=${NPROC:-$((`nproc`*2))}
|
||||
PARALLEL=${PARALLEL:--j${NPROC}}
|
||||
|
||||
echo "building openocd......"
|
||||
|
||||
./bootstrap
|
||||
./configure --build=i686-w64-mingw32 --host=i686-w64-mingw32 --disable-gccwarnings CFLAGS="-O2"
|
||||
|
||||
sed -i '$d' ./src/jtag/drivers/libjaylink/config.h
|
||||
sed -i '$d' ./src/jtag/drivers/libjaylink/config.h
|
||||
sed -i '$d' ./src/jtag/drivers/libjaylink/config.h
|
||||
|
||||
make ${PARALLEL}
|
25
release.sh
25
release.sh
|
@ -1,25 +0,0 @@
|
|||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
|
||||
BASE=`pwd`
|
||||
|
||||
NPROC=${NPROC:-$((`nproc`*2))}
|
||||
PARALLEL=${PARALLEL:--j${NPROC}}
|
||||
|
||||
echo "relase openocd......"
|
||||
|
||||
rm -rf release
|
||||
mkdir -p release
|
||||
|
||||
cp ./src/openocd.exe ./release
|
||||
cp /mingw32/bin/libconfuse-2.dll ./release
|
||||
cp /mingw32/bin/libftdi1.dll ./release
|
||||
cp /mingw32/bin/libftdipp1.dll ./release
|
||||
cp /mingw32/bin/libgcc_s_dw2-1.dll ./release
|
||||
cp /mingw32/bin/libhidapi-0.dll ./release
|
||||
cp /mingw32/bin/libiconv-2.dll ./release
|
||||
cp /mingw32/bin/libintl-8.dll ./release
|
||||
cp /mingw32/bin/libstdc++-6.dll ./release
|
||||
cp /mingw32/bin/libusb-1.0.dll ./release
|
||||
cp /mingw32/bin/libwinpthread-1.dll ./release
|
|
@ -1309,7 +1309,7 @@
|
|||
[10][0x34 - 1] = "Xiamen Kingblaze Technology Co Ltd",
|
||||
[10][0x35 - 1] = "Shenzhen Lomica Technology Co Ltd",
|
||||
[10][0x36 - 1] = "Nuclei System Technology Co Ltd",
|
||||
[10][0x37 - 1] = "LiangKangNan",
|
||||
[10][0x37 - 1] = "Wuhan Xun Zhan Electronic Technology",
|
||||
[10][0x38 - 1] = "Shenzhen Ingacom Semiconductor Ltd",
|
||||
[10][0x39 - 1] = "Zotac Technology Ltd",
|
||||
[10][0x3a - 1] = "Foxline",
|
||||
|
|
|
@ -41,9 +41,7 @@
|
|||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <sys/time.h>
|
||||
#include <helper/time_support.h>
|
||||
#include <helper/fileio.h>
|
||||
#include <jtag/jtag.h>
|
||||
#include <flash/nor/core.h>
|
||||
|
||||
|
@ -76,7 +74,6 @@ static int target_gdb_fileio_end_default(struct target *target, int retcode,
|
|||
int fileio_errno, bool ctrl_c);
|
||||
static int target_profiling_default(struct target *target, uint32_t *samples,
|
||||
uint32_t max_num_samples, uint32_t *num_samples, uint32_t seconds);
|
||||
static int halt_mcu(struct target *target);
|
||||
|
||||
/* targets */
|
||||
extern struct target_type arm7tdmi_target;
|
||||
|
@ -2856,12 +2853,6 @@ COMMAND_HANDLER(handle_reg_command)
|
|||
|
||||
target = get_current_target(CMD_CTX);
|
||||
|
||||
if (target->state != TARGET_HALTED) {
|
||||
LOG_INFO("Please halt the target first");
|
||||
retval = !ERROR_OK;
|
||||
return retval;
|
||||
}
|
||||
|
||||
/* list all available registers for the current target */
|
||||
if (CMD_ARGC == 0) {
|
||||
struct reg_cache *cache = target->reg_cache;
|
||||
|
@ -3136,10 +3127,6 @@ COMMAND_HANDLER(handle_resume_command)
|
|||
|
||||
struct target *target = get_current_target(CMD_CTX);
|
||||
|
||||
if (target->state != TARGET_HALTED) {
|
||||
halt_mcu(target);
|
||||
}
|
||||
|
||||
/* with no CMD_ARGV, resume from current pc, addr = 0,
|
||||
* with one arguments, addr = CMD_ARGV[0],
|
||||
* handle breakpoints, not debugging */
|
||||
|
@ -6194,385 +6181,6 @@ nextw:
|
|||
return retval;
|
||||
}
|
||||
|
||||
COMMAND_HANDLER(handle_load_bin_command)
|
||||
{
|
||||
struct image image;
|
||||
target_addr_t addr;
|
||||
int retval;
|
||||
int i;
|
||||
uint8_t *write_buffer = NULL;
|
||||
uint8_t *read_buffer = NULL;
|
||||
size_t buf_cnt;
|
||||
uint32_t image_size;
|
||||
|
||||
if (CMD_ARGC != 3)
|
||||
return ERROR_COMMAND_SYNTAX_ERROR;
|
||||
|
||||
COMMAND_PARSE_ADDRESS(CMD_ARGV[1], addr);
|
||||
|
||||
unsigned verify = 1;
|
||||
COMMAND_PARSE_NUMBER(uint, CMD_ARGV[2], verify);
|
||||
|
||||
image.base_address = addr;
|
||||
image.base_address_set = 1;
|
||||
image.start_address_set = 0;
|
||||
if (image_open(&image, CMD_ARGV[0], "bin") != ERROR_OK)
|
||||
return ERROR_FAIL;
|
||||
|
||||
retval = ERROR_OK;
|
||||
image_size = 0;
|
||||
|
||||
struct target *target = get_current_target(CMD_CTX);
|
||||
|
||||
struct duration bench;
|
||||
duration_start(&bench);
|
||||
|
||||
for (i = 0; i < image.num_sections; i++) {
|
||||
write_buffer = malloc(image.sections[i].size);
|
||||
if (write_buffer == NULL) {
|
||||
command_print(CMD,
|
||||
"error allocating write buffer for section (%d bytes)",
|
||||
(int)(image.sections[i].size));
|
||||
retval = ERROR_FAIL;
|
||||
break;
|
||||
}
|
||||
|
||||
if (verify) {
|
||||
read_buffer = malloc(image.sections[i].size);
|
||||
if (read_buffer == NULL) {
|
||||
command_print(CMD,
|
||||
"error allocating read buffer for section (%d bytes)",
|
||||
(int)(image.sections[i].size));
|
||||
retval = ERROR_FAIL;
|
||||
free(write_buffer);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
retval = image_read_section(&image, i, 0x0, image.sections[i].size, write_buffer, &buf_cnt);
|
||||
if (retval != ERROR_OK) {
|
||||
free(write_buffer);
|
||||
break;
|
||||
}
|
||||
|
||||
retval = target_write_buffer(target, image.sections[i].base_address, buf_cnt, write_buffer);
|
||||
if (retval != ERROR_OK) {
|
||||
free(write_buffer);
|
||||
break;
|
||||
}
|
||||
|
||||
if (verify) {
|
||||
retval = target_read_buffer(target, image.sections[i].base_address, buf_cnt, read_buffer);
|
||||
if (retval != ERROR_OK) {
|
||||
free(write_buffer);
|
||||
if (read_buffer != NULL)
|
||||
free(read_buffer);
|
||||
break;
|
||||
}
|
||||
|
||||
size_t k;
|
||||
for (k = 0; k < buf_cnt; k++) {
|
||||
if (write_buffer[k] != read_buffer[k]) {
|
||||
command_print(CMD, "write failed at address " TARGET_ADDR_FMT "",
|
||||
image.sections[i].base_address);
|
||||
free(write_buffer);
|
||||
if (read_buffer != NULL)
|
||||
free(read_buffer);
|
||||
retval = ERROR_FAIL;
|
||||
goto end;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
image_size += buf_cnt;
|
||||
command_print(CMD, "%u bytes written at address " TARGET_ADDR_FMT "",
|
||||
(unsigned int)buf_cnt,
|
||||
image.sections[i].base_address);
|
||||
|
||||
free(write_buffer);
|
||||
if (verify && (read_buffer != NULL))
|
||||
free(read_buffer);
|
||||
}
|
||||
|
||||
if ((ERROR_OK == retval) && (duration_measure(&bench) == ERROR_OK)) {
|
||||
command_print(CMD, "downloaded %" PRIu32 " bytes "
|
||||
"in %fs (%0.3f KiB/s)", image_size,
|
||||
duration_elapsed(&bench), duration_kbps(&bench, image_size));
|
||||
}
|
||||
|
||||
end:
|
||||
image_close(&image);
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
||||
// 烧写数据地址:4K + 1K + 256
|
||||
#define DATA_ADDR (0x20001500)
|
||||
|
||||
// 烧写数据长度
|
||||
#define DATA_LEN (0x20001400)
|
||||
|
||||
// 烧写(擦除)地址
|
||||
#define PROGRAM_ADDR (0x20001404)
|
||||
|
||||
// 擦除标志
|
||||
// 0: 不擦除,1:擦除
|
||||
#define ERASE_FLAG (0x20001408)
|
||||
|
||||
// 烧写状态标志
|
||||
// bit0为烧写结束标志,0:未烧写完成,1:烧写完成。
|
||||
// bit1为烧写结果标志,0:烧写失败,1:烧写成功
|
||||
#define RESULT_FLAG (0x2000140C)
|
||||
|
||||
// loader地址
|
||||
#define LOADER_ADDR (0x20000000)
|
||||
|
||||
// 每次烧写最大长度
|
||||
#define EACH_BURN_LEN (256)
|
||||
|
||||
// 扇区大小
|
||||
#define FLASH_SECTOR_SIZE (4096)
|
||||
|
||||
static int program_result(struct target *target)
|
||||
{
|
||||
int retval;
|
||||
int data;
|
||||
int timeout = 0;
|
||||
|
||||
wait:
|
||||
usleep(200000);
|
||||
|
||||
// 读烧写结束标记
|
||||
retval = target_read_buffer(target, RESULT_FLAG, 4, (uint8_t *)(&data));
|
||||
if (retval != ERROR_OK) {
|
||||
goto end;
|
||||
}
|
||||
|
||||
// 烧写结束
|
||||
if (data & 0x1) {
|
||||
// 烧写失败
|
||||
if (!(data & 0x2)) {
|
||||
retval = !ERROR_OK;
|
||||
// 烧写成功
|
||||
} else {
|
||||
retval = ERROR_OK;
|
||||
}
|
||||
// 还没烧写结束
|
||||
} else {
|
||||
timeout++;
|
||||
if (timeout >= 20) {
|
||||
retval = !ERROR_OK;
|
||||
goto end;
|
||||
}
|
||||
goto wait;
|
||||
}
|
||||
|
||||
end:
|
||||
return retval;
|
||||
}
|
||||
|
||||
static int halt_mcu(struct target *target)
|
||||
{
|
||||
int retval;
|
||||
|
||||
target->verbose_halt_msg = true;
|
||||
|
||||
// halt住MCU
|
||||
retval = target_halt(target);
|
||||
if (retval != ERROR_OK) {
|
||||
return retval;
|
||||
}
|
||||
|
||||
// 等待halt成功
|
||||
retval = target_wait_state(target, TARGET_HALTED, DEFAULT_HALT_TIMEOUT);
|
||||
if (retval != ERROR_OK) {
|
||||
return retval;
|
||||
}
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
COMMAND_HANDLER(handle_tinyriscv_program_command)
|
||||
{
|
||||
struct fileio *file;
|
||||
target_addr_t addr;
|
||||
int retval;
|
||||
size_t i;
|
||||
uint8_t *data_buffer;
|
||||
size_t count;
|
||||
size_t file_size;
|
||||
size_t num;
|
||||
int data;
|
||||
struct target *target;
|
||||
|
||||
static const uint8_t tinyriscv_flash_write_code[] = {
|
||||
#include "../../contrib/loaders/flash/tinyriscv/tinyriscv.inc"
|
||||
};
|
||||
|
||||
target = get_current_target(CMD_CTX);
|
||||
|
||||
// 参数检查
|
||||
if (CMD_ARGC != 2)
|
||||
return ERROR_COMMAND_SYNTAX_ERROR;
|
||||
|
||||
// 烧写地址
|
||||
COMMAND_PARSE_ADDRESS(CMD_ARGV[1], addr);
|
||||
|
||||
struct duration bench;
|
||||
duration_start(&bench);
|
||||
|
||||
// halt住MCU
|
||||
retval = halt_mcu(target);
|
||||
if (retval != ERROR_OK) {
|
||||
goto end2;
|
||||
}
|
||||
|
||||
LOG_INFO("flash loader downloading...");
|
||||
|
||||
// 先下载loader到内存
|
||||
retval = target_write_buffer(target, LOADER_ADDR, sizeof(tinyriscv_flash_write_code),
|
||||
tinyriscv_flash_write_code);
|
||||
if (retval != ERROR_OK) {
|
||||
LOG_ERROR("Failed to download flash loader into ram");
|
||||
goto end2;
|
||||
}
|
||||
|
||||
// 打开要烧写的文件
|
||||
if (fileio_open(&file, CMD_ARGV[0], FILEIO_READ, FILEIO_BINARY) != ERROR_OK) {
|
||||
LOG_ERROR("fail to open %s", CMD_ARGV[0]);
|
||||
retval = ERROR_FAIL;
|
||||
goto end2;
|
||||
}
|
||||
|
||||
// 文件大小
|
||||
fileio_size(file, &file_size);
|
||||
//LOG_INFO("bin file size: %d(bytes)", (int)(file_size));
|
||||
|
||||
LOG_INFO("erasing...");
|
||||
|
||||
// 要擦除多少个扇区
|
||||
num = (file_size / FLASH_SECTOR_SIZE) + 1;
|
||||
for (i = 0; i < num; i++) {
|
||||
data = 0x1;
|
||||
// 擦除标记
|
||||
retval = target_write_buffer(target, ERASE_FLAG, 4, (uint8_t *)(&data));
|
||||
if (retval != ERROR_OK) {
|
||||
LOG_ERROR("write erase_flag failed!!!");
|
||||
goto end1;
|
||||
}
|
||||
data = addr + (i * FLASH_SECTOR_SIZE);
|
||||
LOG_INFO("erase addr: 0x%x", data);
|
||||
// 擦除地址
|
||||
retval = target_write_buffer(target, PROGRAM_ADDR, 4, (uint8_t *)(&data));
|
||||
if (retval != ERROR_OK) {
|
||||
LOG_ERROR("write erase_addr failed!!!");
|
||||
goto end1;
|
||||
}
|
||||
// halt住MCU
|
||||
retval = halt_mcu(target);
|
||||
if (retval != ERROR_OK) {
|
||||
goto end1;
|
||||
}
|
||||
// 开始烧写
|
||||
retval = target_resume(target, 0, LOADER_ADDR, 1, 0);
|
||||
if (retval != ERROR_OK) {
|
||||
LOG_ERROR("resume failed!!!");
|
||||
goto end1;
|
||||
}
|
||||
// 获取烧写结果
|
||||
retval = program_result(target);
|
||||
if (retval != ERROR_OK) {
|
||||
LOG_ERROR("erase failed!!!");
|
||||
goto end1;
|
||||
}
|
||||
}
|
||||
|
||||
// 清擦除标志
|
||||
data = 0;
|
||||
retval = target_write_buffer(target, ERASE_FLAG, 4, (uint8_t *)(&data));
|
||||
if (retval != ERROR_OK) {
|
||||
goto end1;
|
||||
}
|
||||
|
||||
// 分配内存
|
||||
data_buffer = malloc(EACH_BURN_LEN);
|
||||
if (data_buffer == NULL) {
|
||||
LOG_ERROR("error allocating data buffer (%d bytes)",
|
||||
EACH_BURN_LEN);
|
||||
retval = ERROR_FAIL;
|
||||
goto end1;
|
||||
}
|
||||
|
||||
retval = ERROR_OK;
|
||||
|
||||
LOG_INFO("programming...");
|
||||
|
||||
num = file_size;
|
||||
while (num > 0) {
|
||||
fileio_read(file, EACH_BURN_LEN, data_buffer, &count);
|
||||
if (count > 0) {
|
||||
// 下载数据
|
||||
retval = target_write_buffer(target, DATA_ADDR, count, data_buffer);
|
||||
if (retval != ERROR_OK) {
|
||||
LOG_ERROR("write data failed!!!");
|
||||
break;
|
||||
}
|
||||
data = addr;
|
||||
LOG_INFO("program addr: 0x%x", data);
|
||||
// 烧写地址
|
||||
retval = target_write_buffer(target, PROGRAM_ADDR, 4, (uint8_t *)(&data));
|
||||
if (retval != ERROR_OK) {
|
||||
LOG_ERROR("write program addr failed!!!");
|
||||
break;
|
||||
}
|
||||
data = count;
|
||||
// 烧写长度
|
||||
retval = target_write_buffer(target, DATA_LEN, 4, (uint8_t *)(&data));
|
||||
if (retval != ERROR_OK) {
|
||||
LOG_ERROR("write data len failed!!!");
|
||||
break;
|
||||
}
|
||||
// halt住MCU
|
||||
retval = halt_mcu(target);
|
||||
if (retval != ERROR_OK) {
|
||||
goto end1;
|
||||
}
|
||||
// 开始烧写
|
||||
retval = target_resume(target, 0, LOADER_ADDR, 1, 0);
|
||||
if (retval != ERROR_OK) {
|
||||
LOG_ERROR("resume failed!!!");
|
||||
break;
|
||||
}
|
||||
// 获取烧写结果
|
||||
retval = program_result(target);
|
||||
if (retval != ERROR_OK) {
|
||||
LOG_ERROR("program failed!!!");
|
||||
break;
|
||||
}
|
||||
addr += count;
|
||||
}
|
||||
num -= count;
|
||||
}
|
||||
|
||||
if ((ERROR_OK == retval) && (duration_measure(&bench) == ERROR_OK)) {
|
||||
LOG_INFO("program %" PRIu32 " bytes "
|
||||
"in %fs (%0.3f KiB/s)", (uint32_t)(file_size),
|
||||
duration_elapsed(&bench), duration_kbps(&bench, file_size));
|
||||
}
|
||||
|
||||
free(data_buffer);
|
||||
end1:
|
||||
fileio_close(file);
|
||||
end2:
|
||||
if (retval == ERROR_OK) {
|
||||
LOG_INFO("End, program succ");
|
||||
} else {
|
||||
LOG_ERROR("End, program failed!!!");
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
||||
static const struct command_registration target_exec_command_handlers[] = {
|
||||
{
|
||||
.name = "fast_load_image",
|
||||
|
@ -6819,20 +6427,6 @@ static const struct command_registration target_exec_command_handlers[] = {
|
|||
.help = "Test the target's memory access functions",
|
||||
.usage = "size",
|
||||
},
|
||||
{
|
||||
.name = "load_bin",
|
||||
.handler = handle_load_bin_command,
|
||||
.mode = COMMAND_EXEC,
|
||||
.help = "Download bin file into memory and verify it",
|
||||
.usage = "filename address verify",
|
||||
},
|
||||
{
|
||||
.name = "tinyriscv_program",
|
||||
.handler = handle_tinyriscv_program_command,
|
||||
.mode = COMMAND_EXEC,
|
||||
.help = "Program file into external flash",
|
||||
.usage = "filename address",
|
||||
},
|
||||
|
||||
COMMAND_REGISTRATION_DONE
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue