mirror of
https://github.com/pine64/blisp.git
synced 2026-09-20 15:01:29 +00:00
Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
738626e67e |
@@ -75,4 +75,3 @@ fabric.properties
|
|||||||
|
|
||||||
# Android studio 3.1+ serialized cache file
|
# Android studio 3.1+ serialized cache file
|
||||||
.idea/caches/build_file_checksums.ser
|
.idea/caches/build_file_checksums.ser
|
||||||
build/
|
|
||||||
|
|||||||
+2
-1
@@ -8,7 +8,8 @@ option(BLISP_BUILD_CLI "Build CLI Tool" OFF)
|
|||||||
add_library(libblisp_obj OBJECT
|
add_library(libblisp_obj OBJECT
|
||||||
lib/blisp.c
|
lib/blisp.c
|
||||||
lib/chip/blisp_chip_bl60x.c
|
lib/chip/blisp_chip_bl60x.c
|
||||||
lib/chip/blisp_chip_bl70x.c)
|
lib/chip/blisp_chip_bl70x.c
|
||||||
|
lib/chip/blisp_chip_bl808.c)
|
||||||
|
|
||||||
target_include_directories(libblisp_obj PRIVATE ${CMAKE_SOURCE_DIR}/include/)
|
target_include_directories(libblisp_obj PRIVATE ${CMAKE_SOURCE_DIR}/include/)
|
||||||
|
|
||||||
|
|||||||
@@ -6,25 +6,14 @@ Tool and library for flashing their RISC-V MCUs.
|
|||||||
|
|
||||||
# Supported MCUs
|
# Supported MCUs
|
||||||
|
|
||||||
- [x] `bl60x` - BL602 / BL604
|
- [X] `bl60x` - BL602 / BL604
|
||||||
- [x] `bl70x` - BL702 / BL704 / BL706
|
- [X] `bl70x` - BL702 / BL704 / BL706
|
||||||
- [ ] `bl606p` - BL606P
|
- [ ] `bl606p` - BL606P
|
||||||
- [ ] `bl61x` - BL616 / BL618
|
- [ ] `bl61x` - BL616 / BL618
|
||||||
- [ ] `bl808` - BL808
|
- [ ] `bl808` - BL808
|
||||||
|
|
||||||
# Building
|
# Building
|
||||||
|
|
||||||
## Clone repository
|
|
||||||
|
|
||||||
If you have not cloned this repository locally; check out the git repository locally by running
|
|
||||||
|
|
||||||
```bash
|
|
||||||
git clone --recursive https://github.com/pine64/blisp.git
|
|
||||||
cd blisp
|
|
||||||
```
|
|
||||||
|
|
||||||
## Build the library and command line utility
|
|
||||||
|
|
||||||
For building `blisp` command line tool, use following commands:
|
For building `blisp` command line tool, use following commands:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
|
|||||||
@@ -6,7 +6,8 @@
|
|||||||
|
|
||||||
enum blisp_chip_type {
|
enum blisp_chip_type {
|
||||||
BLISP_CHIP_BL60X,
|
BLISP_CHIP_BL60X,
|
||||||
BLISP_CHIP_BL70X
|
BLISP_CHIP_BL70X,
|
||||||
|
BLISP_CHIP_BL808
|
||||||
};
|
};
|
||||||
|
|
||||||
struct blisp_chip { // TODO: Move elsewhere?
|
struct blisp_chip { // TODO: Move elsewhere?
|
||||||
@@ -19,5 +20,6 @@ struct blisp_chip { // TODO: Move elsewhere?
|
|||||||
|
|
||||||
extern struct blisp_chip blisp_chip_bl60x;
|
extern struct blisp_chip blisp_chip_bl60x;
|
||||||
extern struct blisp_chip blisp_chip_bl70x;
|
extern struct blisp_chip blisp_chip_bl70x;
|
||||||
|
extern struct blisp_chip blisp_chip_bl808;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
+10
-4
@@ -106,7 +106,7 @@ int32_t blisp_receive_response(struct blisp_device* device, bool expect_payload)
|
|||||||
// TODO: Check checksum
|
// TODO: Check checksum
|
||||||
int ret;
|
int ret;
|
||||||
struct sp_port* serial_port = device->serial_port;
|
struct sp_port* serial_port = device->serial_port;
|
||||||
ret = sp_blocking_read(serial_port, &device->rx_buffer[0], 2, 1000);
|
ret = sp_blocking_read(serial_port, &device->rx_buffer[0], 2, 500);
|
||||||
if (ret < 2) {
|
if (ret < 2) {
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
fprintf(stderr, "Failed to receive response. (ret = %d)\n", ret);
|
fprintf(stderr, "Failed to receive response. (ret = %d)\n", ret);
|
||||||
@@ -158,7 +158,7 @@ blisp_device_handshake(struct blisp_device* device, bool in_ef_loader) {
|
|||||||
if (!in_ef_loader) {
|
if (!in_ef_loader) {
|
||||||
if (device->is_usb) {
|
if (device->is_usb) {
|
||||||
sp_blocking_write(serial_port, "BOUFFALOLAB5555RESET\0\0", 22,
|
sp_blocking_write(serial_port, "BOUFFALOLAB5555RESET\0\0", 22,
|
||||||
100);
|
100); // TODO: Error handling
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ret = sp_blocking_write(serial_port, handshake_buffer, bytes_count,
|
ret = sp_blocking_write(serial_port, handshake_buffer, bytes_count,
|
||||||
@@ -166,6 +166,12 @@ blisp_device_handshake(struct blisp_device* device, bool in_ef_loader) {
|
|||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (device->chip->type == BLISP_CHIP_BL808) {
|
||||||
|
sleep_ms(300);
|
||||||
|
const uint8_t second_handshake[] = { 0x50, 0x00, 0x08, 0x00, 0x38, 0xF0, 0x00, 0x20, 0x00, 0x00, 0x00, 0x18 };
|
||||||
|
sp_blocking_write(serial_port, second_handshake, sizeof(second_handshake), 300); // TODO: Error handling
|
||||||
|
}
|
||||||
ret = sp_blocking_read(serial_port, device->rx_buffer, 20, 50);
|
ret = sp_blocking_read(serial_port, device->rx_buffer, 20, 50);
|
||||||
if (ret >= 2) {
|
if (ret >= 2) {
|
||||||
for (uint8_t j = 0; j < (ret - 1); j++) {
|
for (uint8_t j = 0; j < (ret - 1); j++) {
|
||||||
@@ -189,10 +195,10 @@ int32_t blisp_device_get_boot_info(struct blisp_device* device, struct blisp_boo
|
|||||||
if (ret < 0) return ret;
|
if (ret < 0) return ret;
|
||||||
|
|
||||||
memcpy(boot_info->boot_rom_version, &device->rx_buffer[0], 4); // TODO: Endianess
|
memcpy(boot_info->boot_rom_version, &device->rx_buffer[0], 4); // TODO: Endianess
|
||||||
if (device->chip->type == BLISP_CHIP_BL70X) {
|
if (device->chip->type == BLISP_CHIP_BL70X || device->chip->type == BLISP_CHIP_BL808) { // TODO: This is only 70X related
|
||||||
memcpy(boot_info->chip_id, &device->rx_buffer[16], 8);
|
memcpy(boot_info->chip_id, &device->rx_buffer[16], 8);
|
||||||
}
|
}
|
||||||
// TODO: BL60X
|
// TODO: BL60X, BL808
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
#include "blisp.h"
|
||||||
|
|
||||||
|
struct blisp_chip blisp_chip_bl808 = {
|
||||||
|
.type = BLISP_CHIP_BL808,
|
||||||
|
.type_str = "bl808",
|
||||||
|
.usb_isp_available = true,
|
||||||
|
.handshake_byte_multiplier = 0.006f,
|
||||||
|
};
|
||||||
+22
-29
@@ -28,14 +28,10 @@ static void* cmd_write_argtable[6];
|
|||||||
ssize_t
|
ssize_t
|
||||||
get_binary_folder(char* buffer, uint32_t buffer_size) {
|
get_binary_folder(char* buffer, uint32_t buffer_size) {
|
||||||
#ifdef __linux__
|
#ifdef __linux__
|
||||||
if (readlink("/proc/self/exe", buffer, buffer_size) <= 0) {
|
readlink("/proc/self/exe", buffer, buffer_size); // TODO: Error handling
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
char* pos = strrchr(buffer, '/');
|
char* pos = strrchr(buffer, '/');
|
||||||
#else
|
#else
|
||||||
if (GetModuleFileName(NULL, buffer, buffer_size) <= 0) {
|
GetModuleFileName(NULL, buffer, buffer_size);
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
char* pos = strrchr(buffer, '\\');
|
char* pos = strrchr(buffer, '\\');
|
||||||
#endif
|
#endif
|
||||||
pos[0] = '\0';
|
pos[0] = '\0';
|
||||||
@@ -200,6 +196,8 @@ void blisp_flash_firmware() {
|
|||||||
chip = &blisp_chip_bl70x;
|
chip = &blisp_chip_bl70x;
|
||||||
} else if (strcmp(chip_type->sval[0], "bl60x") == 0) {
|
} else if (strcmp(chip_type->sval[0], "bl60x") == 0) {
|
||||||
chip = &blisp_chip_bl60x;
|
chip = &blisp_chip_bl60x;
|
||||||
|
} else if (strcmp(chip_type->sval[0], "bl808") == 0) {
|
||||||
|
chip = &blisp_chip_bl808;
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr, "Chip type is invalid.\n");
|
fprintf(stderr, "Chip type is invalid.\n");
|
||||||
return;
|
return;
|
||||||
@@ -253,30 +251,19 @@ void blisp_flash_firmware() {
|
|||||||
boot_info.chip_id[6],
|
boot_info.chip_id[6],
|
||||||
boot_info.chip_id[7]);
|
boot_info.chip_id[7]);
|
||||||
|
|
||||||
|
if (device.chip->type == BLISP_CHIP_BL808) {
|
||||||
|
// Since eflash_loader is not needed in BL808, we can jump to flashing.
|
||||||
|
goto eflash_loader; // TODO: Rework
|
||||||
|
}
|
||||||
|
|
||||||
char exe_path[PATH_MAX];
|
char exe_path[PATH_MAX];
|
||||||
char eflash_loader_path[PATH_MAX];
|
char eflash_loader_path[PATH_MAX];
|
||||||
if (get_binary_folder(exe_path, PATH_MAX) <= 0) {
|
get_binary_folder(exe_path, PATH_MAX); // TODO: Error handling
|
||||||
fprintf(stderr, "Failed to find executable path to search for the "
|
snprintf(eflash_loader_path, PATH_MAX, "%s/data/%s/eflash_loader_%s.bin", exe_path, device.chip->type_str, device.chip->default_eflash_loader_xtal);
|
||||||
"eflash loader\n");
|
|
||||||
goto exit1;
|
eflash_loader_file = fopen(eflash_loader_path, "rb"); // TODO: Error handling
|
||||||
}
|
uint8_t eflash_loader_header[176]; // TODO: Remap it to the boot header struct
|
||||||
snprintf(eflash_loader_path, PATH_MAX, "%s/data/%s/eflash_loader_%s.bin",
|
fread(eflash_loader_header, 176, 1, eflash_loader_file); // TODO: Error handling
|
||||||
exe_path, device.chip->type_str,
|
|
||||||
device.chip->default_eflash_loader_xtal);
|
|
||||||
printf("Loading the eflash loader file from disk\n");
|
|
||||||
eflash_loader_file
|
|
||||||
= fopen(eflash_loader_path, "rb"); // TODO: Error handling
|
|
||||||
if (eflash_loader_file == NULL) {
|
|
||||||
fprintf(stderr,
|
|
||||||
"Could not open the eflash loader file from disk.\n"
|
|
||||||
"Does \"%s\" exist?\n",
|
|
||||||
eflash_loader_path);
|
|
||||||
goto exit1;
|
|
||||||
}
|
|
||||||
uint8_t
|
|
||||||
eflash_loader_header[176]; // TODO: Remap it to the boot header struct
|
|
||||||
fread(eflash_loader_header, 176, 1,
|
|
||||||
eflash_loader_file); // TODO: Error handling
|
|
||||||
|
|
||||||
printf("Loading eflash_loader...\n");
|
printf("Loading eflash_loader...\n");
|
||||||
ret = blisp_device_load_boot_header(&device, eflash_loader_header);
|
ret = blisp_device_load_boot_header(&device, eflash_loader_header);
|
||||||
@@ -345,7 +332,13 @@ void blisp_flash_firmware() {
|
|||||||
}
|
}
|
||||||
printf(" OK\n");
|
printf(" OK\n");
|
||||||
|
|
||||||
eflash_loader:;
|
eflash_loader:
|
||||||
|
if (device.chip->type == BLISP_CHIP_BL808) {
|
||||||
|
// Setting CLK configuration
|
||||||
|
// Setting Flash Config
|
||||||
|
// Setting Flash Parameter
|
||||||
|
}
|
||||||
|
|
||||||
FILE* firmware_file = fopen(binary_to_write->filename[0], "rb");
|
FILE* firmware_file = fopen(binary_to_write->filename[0], "rb");
|
||||||
if (firmware_file == NULL) {
|
if (firmware_file == NULL) {
|
||||||
fprintf(stderr,"Failed to open firmware file \"%s\".\n", binary_to_write->filename[0]);
|
fprintf(stderr,"Failed to open firmware file \"%s\".\n", binary_to_write->filename[0]);
|
||||||
|
|||||||
Reference in New Issue
Block a user