Compare commits

...

5 Commits

Author SHA1 Message Date
Pavel Zakopaylo
9230727a3a
Merge aa79ad360186feef5e486838610280c55e9dec5a into 7a85414eced71d3208d0cbffa1a9e7a6a0b5fcc1 2023-12-01 07:21:00 +00:00
Pavel Zakopaylo
aa79ad3601
Added error-number printing to common.c 2023-12-01 18:19:57 +11:00
Pavel Zakopaylo
04916cf5a4
Fixed bug in reading chip ID 2023-12-01 15:56:44 +11:00
Pavel Zakopaylo
80a0854f2c
Refactored struct in bl808_load_flash_para to use initializer
Compatability isues in older compilers are possible as a result
of this change.
2023-12-01 15:20:49 +11:00
Pavel Zakopaylo
dddb316d91
Small changes for PR 2023-12-01 15:15:29 +11:00
3 changed files with 146 additions and 112 deletions

View File

@ -20,6 +20,14 @@ static void blisp_dlog(const char* format, ...)
fputc('\n', stderr);
}
static void blisp_dlog_no_nl(const char* format, ...) {
fflush(stdout);
va_list args;
va_start(args, format);
vfprintf(stderr, format, args);
va_end(args);
}
static void sleep_ms(int milliseconds) {
#ifdef WIN32
@ -95,4 +103,4 @@ static uint32_t crc32_calculate(const void *data, size_t data_len)
}
#endif
#endif

View File

@ -234,7 +234,7 @@ blisp_return_t blisp_device_handshake(struct blisp_device* device,
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 };
const static uint8_t second_handshake[] = { 0x50, 0x00, 0x08, 0x00, 0x38, 0xF0, 0x00, 0x20, 0x00, 0x00, 0x00, 0x18 };
ret = sp_blocking_write(serial_port, second_handshake, sizeof(second_handshake), 300);
if (ret < 0) {
blisp_dlog("Second handshake write failed, ret %d", ret);
@ -250,8 +250,16 @@ blisp_return_t blisp_device_handshake(struct blisp_device* device,
}
}
}
if (!ok) {
blisp_dlog("Received no response from chip.");
blisp_dlog("Received incorrect handshake response from chip.");
blisp_dlog_no_nl("Could not find 0x%02X 0x%02X ('O', 'K') in: ", 'O', 'K');
if (ret) {
for (uint8_t j=0; j <= ret; j++) {
blisp_dlog_no_nl("0x%02X ", device->rx_buffer[j]);
}
}
blisp_dlog("");
return BLISP_ERR_NO_RESPONSE;
}
@ -271,13 +279,16 @@ blisp_return_t blisp_device_get_boot_info(struct blisp_device* device,
if (ret < 0)
return ret;
memcpy(boot_info->boot_rom_version, &device->rx_buffer[0],
4); // TODO: Endianess; this may break on big endian machines
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, BL808
return BLISP_OK;
// TODO: Endianess; this may break on big endian machines
memcpy(boot_info->boot_rom_version, &device->rx_buffer[0], 4);
if (device->chip->type == BLISP_CHIP_BL70X) {
memcpy(boot_info->chip_id, &device->rx_buffer[16], 8);
} else {
memcpy(boot_info->chip_id, &device->rx_buffer[12], 6);
}
return BLISP_OK;
}
// TODO: Use struct instead of uint8_t*
@ -473,91 +484,92 @@ blisp_return_t bl808_load_flash_para(struct blisp_device* device) {
// TODO: I don't understand why these parameters are the way they are,
// but at least they are labeled. Also, flash_io_mode and flash_clk_delay
// seem to be duplicated in the main spi_flash_cfg_t struct?
uint8_t flash_pin = 0x4;
uint8_t flash_clk_cfg = 0x41;
uint8_t flash_io_mode = 0x01;
uint8_t flash_clk_delay = 0;
const uint8_t flash_pin = 0x4;
const uint8_t flash_clk_cfg = 0x41;
const uint8_t flash_io_mode = 0x01;
const uint8_t flash_clk_delay = 0;
// Yes, these values are (slightly) different to the ones in blisp_chip_bl808.c
struct bl808_spi_flash_cfg_t cfg = {0};
cfg.ioMode = 0x04;
cfg.cReadSupport = 0x01;
cfg.clkDelay = 0;
cfg.clkInvert = 0;
cfg.resetEnCmd = 0x66;
cfg.resetCmd = 0x99;
cfg.resetCreadCmd = 0xff;
cfg.resetCreadCmdSize = 0x03;
cfg.jedecIdCmd = 0x9f;
cfg.jedecIdCmdDmyClk = 0;
cfg.enter32BitsAddrCmd = 0xb7;
cfg.exit32BitsAddrCmd = 0xe9;
cfg.sectorSize = 0x04;
cfg.mid = 0xef;
cfg.pageSize = 0x100;
cfg.chipEraseCmd = 0xc7;
cfg.sectorEraseCmd = 0x20;
cfg.blk32EraseCmd = 0x52;
cfg.blk64EraseCmd = 0xd8;
cfg.writeEnableCmd = 0x06;
cfg.pageProgramCmd = 0x02;
cfg.qpageProgramCmd = 0x32;
cfg.qppAddrMode = 0;
cfg.fastReadCmd = 0x0b;
cfg.frDmyClk = 0x01;
cfg.qpiFastReadCmd = 0x0b;
cfg.qpiFrDmyClk = 0x01;
cfg.fastReadDoCmd = 0x3b;
cfg.frDoDmyClk = 0x01;
cfg.fastReadDioCmd = 0xbb;
cfg.frDioDmyClk = 0;
cfg.fastReadQoCmd = 0x6b;
cfg.frQoDmyClk = 0x01;
cfg.fastReadQioCmd = 0xeb;
cfg.frQioDmyClk = 0x02;
cfg.qpiFastReadQioCmd = 0xeb;
cfg.qpiFrQioDmyClk = 0x02;
cfg.qpiPageProgramCmd = 0x02;
cfg.writeVregEnableCmd = 0x50;
cfg.wrEnableIndex = 0;
cfg.qeIndex = 0x01;
cfg.busyIndex = 0;
cfg.wrEnableBit = 0x01;
cfg.qeBit = 0x01;
cfg.busyBit = 0;
cfg.wrEnableWriteRegLen = 0x02;
cfg.wrEnableReadRegLen = 0x01;
cfg.qeWriteRegLen = 0x01;
cfg.qeReadRegLen = 0x01;
cfg.releasePowerDown = 0xab;
cfg.busyReadRegLen = 0x01;
cfg.readRegCmd[0] = 0x05;
cfg.readRegCmd[1] = 0x35;
cfg.readRegCmd[2] = 0;
cfg.readRegCmd[3] = 0;
cfg.writeRegCmd[0] = 0x01;
cfg.writeRegCmd[1] = 0x31;
cfg.writeRegCmd[2] = 0;
cfg.writeRegCmd[3] = 0;
cfg.enterQpi = 0x38;
cfg.exitQpi = 0xff;
cfg.cReadMode = 0xa0;
cfg.cRExit = 0xff;
cfg.burstWrapCmd = 0x77;
cfg.burstWrapCmdDmyClk = 0x03;
cfg.burstWrapDataMode = 0x02;
cfg.burstWrapData = 0x40;
cfg.deBurstWrapCmd = 0x77;
cfg.deBurstWrapCmdDmyClk = 0x03;
cfg.deBurstWrapDataMode = 0x02;
cfg.deBurstWrapData = 0xf0;
cfg.timeEsector = 0x12c;
cfg.timeE32k = 0x4b0;
cfg.timeE64k = 0x4b0;
cfg.timePagePgm = 0x05;
cfg.timeCe = 0x80e8;
cfg.pdDelay = 0x03;
cfg.qeData = 0;
const static struct bl808_spi_flash_cfg_t cfg = {
.ioMode = 0x04,
.cReadSupport = 0x01,
.clkDelay = 0,
.clkInvert = 0,
.resetEnCmd = 0x66,
.resetCmd = 0x99,
.resetCreadCmd = 0xff,
.resetCreadCmdSize = 0x03,
.jedecIdCmd = 0x9f,
.jedecIdCmdDmyClk = 0,
.enter32BitsAddrCmd = 0xb7,
.exit32BitsAddrCmd = 0xe9,
.sectorSize = 0x04,
.mid = 0xef,
.pageSize = 0x100,
.chipEraseCmd = 0xc7,
.sectorEraseCmd = 0x20,
.blk32EraseCmd = 0x52,
.blk64EraseCmd = 0xd8,
.writeEnableCmd = 0x06,
.pageProgramCmd = 0x02,
.qpageProgramCmd = 0x32,
.qppAddrMode = 0,
.fastReadCmd = 0x0b,
.frDmyClk = 0x01,
.qpiFastReadCmd = 0x0b,
.qpiFrDmyClk = 0x01,
.fastReadDoCmd = 0x3b,
.frDoDmyClk = 0x01,
.fastReadDioCmd = 0xbb,
.frDioDmyClk = 0,
.fastReadQoCmd = 0x6b,
.frQoDmyClk = 0x01,
.fastReadQioCmd = 0xeb,
.frQioDmyClk = 0x02,
.qpiFastReadQioCmd = 0xeb,
.qpiFrQioDmyClk = 0x02,
.qpiPageProgramCmd = 0x02,
.writeVregEnableCmd = 0x50,
.wrEnableIndex = 0,
.qeIndex = 0x01,
.busyIndex = 0,
.wrEnableBit = 0x01,
.qeBit = 0x01,
.busyBit = 0,
.wrEnableWriteRegLen = 0x02,
.wrEnableReadRegLen = 0x01,
.qeWriteRegLen = 0x01,
.qeReadRegLen = 0x01,
.releasePowerDown = 0xab,
.busyReadRegLen = 0x01,
.readRegCmd[0] = 0x05,
.readRegCmd[1] = 0x35,
.readRegCmd[2] = 0,
.readRegCmd[3] = 0,
.writeRegCmd[0] = 0x01,
.writeRegCmd[1] = 0x31,
.writeRegCmd[2] = 0,
.writeRegCmd[3] = 0,
.enterQpi = 0x38,
.exitQpi = 0xff,
.cReadMode = 0xa0,
.cRExit = 0xff,
.burstWrapCmd = 0x77,
.burstWrapCmdDmyClk = 0x03,
.burstWrapDataMode = 0x02,
.burstWrapData = 0x40,
.deBurstWrapCmd = 0x77,
.deBurstWrapCmdDmyClk = 0x03,
.deBurstWrapDataMode = 0x02,
.deBurstWrapData = 0xf0,
.timeEsector = 0x12c,
.timeE32k = 0x4b0,
.timeE64k = 0x4b0,
.timePagePgm = 0x05,
.timeCe = 0x80e8,
.pdDelay = 0x03,
.qeData = 0,
};
const uint32_t payload_size = 4 + sizeof(struct bl808_spi_flash_cfg_t);
uint8_t payload[payload_size] = {};

View File

@ -42,15 +42,17 @@ blisp_return_t blisp_common_init_device(struct blisp_device* device,
blisp_return_t ret;
ret = blisp_device_init(device, chip);
if (ret != BLISP_OK) {
fprintf(stderr, "Failed to init device.\n");
fprintf(stderr, "Failed to init device, ret: %d\n", ret);
return ret;
}
ret = blisp_device_open(device,
port_name->count == 1 ? port_name->sval[0] : NULL);
if (ret != BLISP_OK) {
fprintf(stderr, ret == BLISP_ERR_DEVICE_NOT_FOUND
? "Device not found\n"
: "Failed to open device.\n");
if (ret == BLISP_ERR_DEVICE_NOT_FOUND) {
fprintf(stderr, "Device not found\n");
} else {
fprintf(stderr, "Failed to open device, ret: %d\n", ret);
}
return ret;
}
@ -67,37 +69,49 @@ blisp_return_t blisp_common_prepare_flash(struct blisp_device* device) {
printf("Sending a handshake...\n");
ret = blisp_device_handshake(device, false);
if (ret != BLISP_OK) {
fprintf(stderr, "Failed to handshake with device.\n");
fprintf(stderr, "Failed to handshake with device, ret: %d\n", ret);
return ret;
}
printf("Handshake successful!\nGetting chip info...\n");
struct blisp_boot_info boot_info;
ret = blisp_device_get_boot_info(device, &boot_info);
if (ret != BLISP_OK) {
fprintf(stderr, "Failed to get boot info.\n");
fprintf(stderr, "Failed to get boot info, ret: %d\n", ret);
return ret;
}
printf(
"BootROM version %d.%d.%d.%d, ChipID: "
"%02X%02X%02X%02X%02X%02X%02X%02X\n",
boot_info.boot_rom_version[0], boot_info.boot_rom_version[1],
boot_info.boot_rom_version[2], boot_info.boot_rom_version[3],
boot_info.chip_id[0], boot_info.chip_id[1], boot_info.chip_id[2],
boot_info.chip_id[3], boot_info.chip_id[4], boot_info.chip_id[5],
boot_info.chip_id[6], boot_info.chip_id[7]);
// TODO: Do we want this to print in big endian to match the output
// of Bouffalo's software?
if (device->chip->type == BLISP_CHIP_BL70X) {
printf(
"BootROM version %d.%d.%d.%d, ChipID: "
"%02X%02X%02X%02X%02X%02X%02X%02X\n",
boot_info.boot_rom_version[0], boot_info.boot_rom_version[1],
boot_info.boot_rom_version[2], boot_info.boot_rom_version[3],
boot_info.chip_id[0], boot_info.chip_id[1], boot_info.chip_id[2],
boot_info.chip_id[3], boot_info.chip_id[4], boot_info.chip_id[5],
boot_info.chip_id[6], boot_info.chip_id[7]);
} else {
printf(
"BootROM version %d.%d.%d.%d, ChipID: "
"%02X%02X%02X%02X%02X%02X\n",
boot_info.boot_rom_version[0], boot_info.boot_rom_version[1],
boot_info.boot_rom_version[2], boot_info.boot_rom_version[3],
boot_info.chip_id[0], boot_info.chip_id[1], boot_info.chip_id[2],
boot_info.chip_id[3], boot_info.chip_id[4], boot_info.chip_id[5]);
}
if (device->chip->type == BLISP_CHIP_BL808) {
printf("Setting clock parameters ...\n");
ret = bl808_load_clock_para(device, true, device->current_baud_rate);
if (ret != BLISP_OK) {
fprintf(stderr, "Failed to set clock parameters.\n");
fprintf(stderr, "Failed to set clock parameters, ret: %d\n", ret);
return ret;
}
printf("Setting flash parameters...\n");
ret = bl808_load_flash_para(device);
if (ret != BLISP_OK) {
fprintf(stderr, "Failed to set flash parameters.\n");
fprintf(stderr, "Failed to set flash parameters, ret: %d\n", ret);
return ret;
}
}
@ -137,20 +151,20 @@ blisp_return_t blisp_common_prepare_flash(struct blisp_device* device) {
ret = blisp_device_check_image(device);
if (ret != 0) {
fprintf(stderr, "Failed to check image.\n");
fprintf(stderr, "Failed to check image, ret: %d\n", ret);
goto exit1;
}
ret = blisp_device_run_image(device);
if (ret != BLISP_OK) {
fprintf(stderr, "Failed to run image.\n");
fprintf(stderr, "Failed to run image, ret: %d\n", ret);
goto exit1;
}
printf("Sending a handshake...\n");
ret = blisp_device_handshake(device, true);
if (ret != BLISP_OK) {
fprintf(stderr, "Failed to handshake with device.\n");
fprintf(stderr, "Failed to handshake with device, ret: %d\n", ret);
goto exit1;
}
printf("Handshake with eflash_loader successful.\n");