From 738626e67eae7177bae1923c785e79b9403404f7 Mon Sep 17 00:00:00 2001 From: Marek Kraus Date: Thu, 10 Nov 2022 21:36:00 +0100 Subject: [PATCH] Initial support for BL808 Not working yet --- CMakeLists.txt | 3 ++- include/blisp_chip.h | 4 +++- lib/blisp.c | 12 +++++++++--- lib/chip/blisp_chip_bl808.c | 8 ++++++++ tools/blisp/src/cmd/write.c | 15 ++++++++++++++- 5 files changed, 36 insertions(+), 6 deletions(-) create mode 100644 lib/chip/blisp_chip_bl808.c diff --git a/CMakeLists.txt b/CMakeLists.txt index 124c4a1..a4b2ea1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,7 +8,8 @@ option(BLISP_BUILD_CLI "Build CLI Tool" OFF) add_library(libblisp_obj OBJECT lib/blisp.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/) diff --git a/include/blisp_chip.h b/include/blisp_chip.h index c3d44f1..56801da 100644 --- a/include/blisp_chip.h +++ b/include/blisp_chip.h @@ -6,7 +6,8 @@ enum blisp_chip_type { BLISP_CHIP_BL60X, - BLISP_CHIP_BL70X + BLISP_CHIP_BL70X, + BLISP_CHIP_BL808 }; 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_bl70x; +extern struct blisp_chip blisp_chip_bl808; #endif \ No newline at end of file diff --git a/lib/blisp.c b/lib/blisp.c index a4a5e38..90f3db3 100644 --- a/lib/blisp.c +++ b/lib/blisp.c @@ -158,7 +158,7 @@ blisp_device_handshake(struct blisp_device* device, bool in_ef_loader) { if (!in_ef_loader) { if (device->is_usb) { sp_blocking_write(serial_port, "BOUFFALOLAB5555RESET\0\0", 22, - 100); + 100); // TODO: Error handling } } 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) { 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); if (ret >= 2) { 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; 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); } - // TODO: BL60X + // TODO: BL60X, BL808 return 0; } diff --git a/lib/chip/blisp_chip_bl808.c b/lib/chip/blisp_chip_bl808.c new file mode 100644 index 0000000..46e20a1 --- /dev/null +++ b/lib/chip/blisp_chip_bl808.c @@ -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, +}; diff --git a/tools/blisp/src/cmd/write.c b/tools/blisp/src/cmd/write.c index 98ee249..7a139fc 100644 --- a/tools/blisp/src/cmd/write.c +++ b/tools/blisp/src/cmd/write.c @@ -196,6 +196,8 @@ void blisp_flash_firmware() { chip = &blisp_chip_bl70x; } else if (strcmp(chip_type->sval[0], "bl60x") == 0) { chip = &blisp_chip_bl60x; + } else if (strcmp(chip_type->sval[0], "bl808") == 0) { + chip = &blisp_chip_bl808; } else { fprintf(stderr, "Chip type is invalid.\n"); return; @@ -249,6 +251,11 @@ void blisp_flash_firmware() { boot_info.chip_id[6], 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 eflash_loader_path[PATH_MAX]; get_binary_folder(exe_path, PATH_MAX); // TODO: Error handling @@ -325,7 +332,13 @@ void blisp_flash_firmware() { } 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"); if (firmware_file == NULL) { fprintf(stderr,"Failed to open firmware file \"%s\".\n", binary_to_write->filename[0]);