Compare commits

..

No commits in common. "aa79ad360186feef5e486838610280c55e9dec5a" and "c48950e07b4a222c0313ba54a2a652509e865484" have entirely different histories.

3 changed files with 112 additions and 146 deletions

View File

@ -20,14 +20,6 @@ static void blisp_dlog(const char* format, ...)
fputc('\n', stderr); 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) { static void sleep_ms(int milliseconds) {
#ifdef WIN32 #ifdef WIN32

View File

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

View File

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