mirror of
https://github.com/pine64/blisp.git
synced 2025-08-21 11:00:52 +00:00
Compare commits
No commits in common. "aa79ad360186feef5e486838610280c55e9dec5a" and "c48950e07b4a222c0313ba54a2a652509e865484" have entirely different histories.
aa79ad3601
...
c48950e07b
@ -20,14 +20,6 @@ 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
|
||||
@ -103,4 +95,4 @@ static uint32_t crc32_calculate(const void *data, size_t data_len)
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
#endif
|
196
lib/blisp.c
196
lib/blisp.c
@ -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 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);
|
||||
if (ret < 0) {
|
||||
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) {
|
||||
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("");
|
||||
blisp_dlog("Received no response from chip.");
|
||||
return BLISP_ERR_NO_RESPONSE;
|
||||
}
|
||||
|
||||
@ -279,16 +271,13 @@ blisp_return_t blisp_device_get_boot_info(struct blisp_device* device,
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
// 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;
|
||||
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: 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,
|
||||
// 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?
|
||||
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;
|
||||
uint8_t flash_pin = 0x4;
|
||||
uint8_t flash_clk_cfg = 0x41;
|
||||
uint8_t flash_io_mode = 0x01;
|
||||
uint8_t flash_clk_delay = 0;
|
||||
|
||||
// Yes, these values are (slightly) different to the ones in blisp_chip_bl808.c
|
||||
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,
|
||||
};
|
||||
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 uint32_t payload_size = 4 + sizeof(struct bl808_spi_flash_cfg_t);
|
||||
uint8_t payload[payload_size] = {};
|
||||
|
@ -42,17 +42,15 @@ 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, ret: %d\n", ret);
|
||||
fprintf(stderr, "Failed to init device.\n");
|
||||
return ret;
|
||||
}
|
||||
ret = blisp_device_open(device,
|
||||
port_name->count == 1 ? port_name->sval[0] : NULL);
|
||||
if (ret != BLISP_OK) {
|
||||
if (ret == BLISP_ERR_DEVICE_NOT_FOUND) {
|
||||
fprintf(stderr, "Device not found\n");
|
||||
} else {
|
||||
fprintf(stderr, "Failed to open device, ret: %d\n", ret);
|
||||
}
|
||||
fprintf(stderr, ret == BLISP_ERR_DEVICE_NOT_FOUND
|
||||
? "Device not found\n"
|
||||
: "Failed to open device.\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -69,49 +67,37 @@ 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, ret: %d\n", ret);
|
||||
fprintf(stderr, "Failed to handshake with device.\n");
|
||||
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, ret: %d\n", ret);
|
||||
fprintf(stderr, "Failed to get boot info.\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
// 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]);
|
||||
}
|
||||
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]);
|
||||
|
||||
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, ret: %d\n", ret);
|
||||
fprintf(stderr, "Failed to set clock parameters.\n");
|
||||
return ret;
|
||||
}
|
||||
printf("Setting flash parameters...\n");
|
||||
ret = bl808_load_flash_para(device);
|
||||
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;
|
||||
}
|
||||
}
|
||||
@ -151,20 +137,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, ret: %d\n", ret);
|
||||
fprintf(stderr, "Failed to check image.\n");
|
||||
goto exit1;
|
||||
}
|
||||
|
||||
ret = blisp_device_run_image(device);
|
||||
if (ret != BLISP_OK) {
|
||||
fprintf(stderr, "Failed to run image, ret: %d\n", ret);
|
||||
fprintf(stderr, "Failed to run image.\n");
|
||||
goto exit1;
|
||||
}
|
||||
|
||||
printf("Sending a handshake...\n");
|
||||
ret = blisp_device_handshake(device, true);
|
||||
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;
|
||||
}
|
||||
printf("Handshake with eflash_loader successful.\n");
|
||||
|
Loading…
x
Reference in New Issue
Block a user