mirror of
https://github.com/pine64/blisp.git
synced 2025-08-21 11:00:52 +00:00
Compare commits
4 Commits
c48950e07b
...
aa79ad3601
Author | SHA1 | Date | |
---|---|---|---|
|
aa79ad3601 | ||
|
04916cf5a4 | ||
|
80a0854f2c | ||
|
dddb316d91 |
@ -20,6 +20,14 @@ 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
|
||||||
|
190
lib/blisp.c
190
lib/blisp.c
@ -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 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);
|
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,8 +250,16 @@ blisp_return_t blisp_device_handshake(struct blisp_device* device,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!ok) {
|
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;
|
return BLISP_ERR_NO_RESPONSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -271,12 +279,15 @@ blisp_return_t blisp_device_get_boot_info(struct blisp_device* device,
|
|||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
memcpy(boot_info->boot_rom_version, &device->rx_buffer[0],
|
// TODO: Endianess; this may break on big endian machines
|
||||||
4); // 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 || 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 {
|
||||||
|
memcpy(boot_info->chip_id, &device->rx_buffer[12], 6);
|
||||||
}
|
}
|
||||||
// TODO: BL60X, BL808
|
|
||||||
return BLISP_OK;
|
return BLISP_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -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,
|
// 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?
|
||||||
uint8_t flash_pin = 0x4;
|
const uint8_t flash_pin = 0x4;
|
||||||
uint8_t flash_clk_cfg = 0x41;
|
const uint8_t flash_clk_cfg = 0x41;
|
||||||
uint8_t flash_io_mode = 0x01;
|
const uint8_t flash_io_mode = 0x01;
|
||||||
uint8_t flash_clk_delay = 0;
|
const 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
|
||||||
struct bl808_spi_flash_cfg_t cfg = {0};
|
const static struct bl808_spi_flash_cfg_t cfg = {
|
||||||
cfg.ioMode = 0x04;
|
.ioMode = 0x04,
|
||||||
cfg.cReadSupport = 0x01;
|
.cReadSupport = 0x01,
|
||||||
cfg.clkDelay = 0;
|
.clkDelay = 0,
|
||||||
cfg.clkInvert = 0;
|
.clkInvert = 0,
|
||||||
cfg.resetEnCmd = 0x66;
|
.resetEnCmd = 0x66,
|
||||||
cfg.resetCmd = 0x99;
|
.resetCmd = 0x99,
|
||||||
cfg.resetCreadCmd = 0xff;
|
.resetCreadCmd = 0xff,
|
||||||
cfg.resetCreadCmdSize = 0x03;
|
.resetCreadCmdSize = 0x03,
|
||||||
cfg.jedecIdCmd = 0x9f;
|
.jedecIdCmd = 0x9f,
|
||||||
cfg.jedecIdCmdDmyClk = 0;
|
.jedecIdCmdDmyClk = 0,
|
||||||
cfg.enter32BitsAddrCmd = 0xb7;
|
.enter32BitsAddrCmd = 0xb7,
|
||||||
cfg.exit32BitsAddrCmd = 0xe9;
|
.exit32BitsAddrCmd = 0xe9,
|
||||||
cfg.sectorSize = 0x04;
|
.sectorSize = 0x04,
|
||||||
cfg.mid = 0xef;
|
.mid = 0xef,
|
||||||
cfg.pageSize = 0x100;
|
.pageSize = 0x100,
|
||||||
cfg.chipEraseCmd = 0xc7;
|
.chipEraseCmd = 0xc7,
|
||||||
cfg.sectorEraseCmd = 0x20;
|
.sectorEraseCmd = 0x20,
|
||||||
cfg.blk32EraseCmd = 0x52;
|
.blk32EraseCmd = 0x52,
|
||||||
cfg.blk64EraseCmd = 0xd8;
|
.blk64EraseCmd = 0xd8,
|
||||||
cfg.writeEnableCmd = 0x06;
|
.writeEnableCmd = 0x06,
|
||||||
cfg.pageProgramCmd = 0x02;
|
.pageProgramCmd = 0x02,
|
||||||
cfg.qpageProgramCmd = 0x32;
|
.qpageProgramCmd = 0x32,
|
||||||
cfg.qppAddrMode = 0;
|
.qppAddrMode = 0,
|
||||||
cfg.fastReadCmd = 0x0b;
|
.fastReadCmd = 0x0b,
|
||||||
cfg.frDmyClk = 0x01;
|
.frDmyClk = 0x01,
|
||||||
cfg.qpiFastReadCmd = 0x0b;
|
.qpiFastReadCmd = 0x0b,
|
||||||
cfg.qpiFrDmyClk = 0x01;
|
.qpiFrDmyClk = 0x01,
|
||||||
cfg.fastReadDoCmd = 0x3b;
|
.fastReadDoCmd = 0x3b,
|
||||||
cfg.frDoDmyClk = 0x01;
|
.frDoDmyClk = 0x01,
|
||||||
cfg.fastReadDioCmd = 0xbb;
|
.fastReadDioCmd = 0xbb,
|
||||||
cfg.frDioDmyClk = 0;
|
.frDioDmyClk = 0,
|
||||||
cfg.fastReadQoCmd = 0x6b;
|
.fastReadQoCmd = 0x6b,
|
||||||
cfg.frQoDmyClk = 0x01;
|
.frQoDmyClk = 0x01,
|
||||||
cfg.fastReadQioCmd = 0xeb;
|
.fastReadQioCmd = 0xeb,
|
||||||
cfg.frQioDmyClk = 0x02;
|
.frQioDmyClk = 0x02,
|
||||||
cfg.qpiFastReadQioCmd = 0xeb;
|
.qpiFastReadQioCmd = 0xeb,
|
||||||
cfg.qpiFrQioDmyClk = 0x02;
|
.qpiFrQioDmyClk = 0x02,
|
||||||
cfg.qpiPageProgramCmd = 0x02;
|
.qpiPageProgramCmd = 0x02,
|
||||||
cfg.writeVregEnableCmd = 0x50;
|
.writeVregEnableCmd = 0x50,
|
||||||
cfg.wrEnableIndex = 0;
|
.wrEnableIndex = 0,
|
||||||
cfg.qeIndex = 0x01;
|
.qeIndex = 0x01,
|
||||||
cfg.busyIndex = 0;
|
.busyIndex = 0,
|
||||||
cfg.wrEnableBit = 0x01;
|
.wrEnableBit = 0x01,
|
||||||
cfg.qeBit = 0x01;
|
.qeBit = 0x01,
|
||||||
cfg.busyBit = 0;
|
.busyBit = 0,
|
||||||
cfg.wrEnableWriteRegLen = 0x02;
|
.wrEnableWriteRegLen = 0x02,
|
||||||
cfg.wrEnableReadRegLen = 0x01;
|
.wrEnableReadRegLen = 0x01,
|
||||||
cfg.qeWriteRegLen = 0x01;
|
.qeWriteRegLen = 0x01,
|
||||||
cfg.qeReadRegLen = 0x01;
|
.qeReadRegLen = 0x01,
|
||||||
cfg.releasePowerDown = 0xab;
|
.releasePowerDown = 0xab,
|
||||||
cfg.busyReadRegLen = 0x01;
|
.busyReadRegLen = 0x01,
|
||||||
cfg.readRegCmd[0] = 0x05;
|
.readRegCmd[0] = 0x05,
|
||||||
cfg.readRegCmd[1] = 0x35;
|
.readRegCmd[1] = 0x35,
|
||||||
cfg.readRegCmd[2] = 0;
|
.readRegCmd[2] = 0,
|
||||||
cfg.readRegCmd[3] = 0;
|
.readRegCmd[3] = 0,
|
||||||
cfg.writeRegCmd[0] = 0x01;
|
.writeRegCmd[0] = 0x01,
|
||||||
cfg.writeRegCmd[1] = 0x31;
|
.writeRegCmd[1] = 0x31,
|
||||||
cfg.writeRegCmd[2] = 0;
|
.writeRegCmd[2] = 0,
|
||||||
cfg.writeRegCmd[3] = 0;
|
.writeRegCmd[3] = 0,
|
||||||
cfg.enterQpi = 0x38;
|
.enterQpi = 0x38,
|
||||||
cfg.exitQpi = 0xff;
|
.exitQpi = 0xff,
|
||||||
cfg.cReadMode = 0xa0;
|
.cReadMode = 0xa0,
|
||||||
cfg.cRExit = 0xff;
|
.cRExit = 0xff,
|
||||||
cfg.burstWrapCmd = 0x77;
|
.burstWrapCmd = 0x77,
|
||||||
cfg.burstWrapCmdDmyClk = 0x03;
|
.burstWrapCmdDmyClk = 0x03,
|
||||||
cfg.burstWrapDataMode = 0x02;
|
.burstWrapDataMode = 0x02,
|
||||||
cfg.burstWrapData = 0x40;
|
.burstWrapData = 0x40,
|
||||||
cfg.deBurstWrapCmd = 0x77;
|
.deBurstWrapCmd = 0x77,
|
||||||
cfg.deBurstWrapCmdDmyClk = 0x03;
|
.deBurstWrapCmdDmyClk = 0x03,
|
||||||
cfg.deBurstWrapDataMode = 0x02;
|
.deBurstWrapDataMode = 0x02,
|
||||||
cfg.deBurstWrapData = 0xf0;
|
.deBurstWrapData = 0xf0,
|
||||||
cfg.timeEsector = 0x12c;
|
.timeEsector = 0x12c,
|
||||||
cfg.timeE32k = 0x4b0;
|
.timeE32k = 0x4b0,
|
||||||
cfg.timeE64k = 0x4b0;
|
.timeE64k = 0x4b0,
|
||||||
cfg.timePagePgm = 0x05;
|
.timePagePgm = 0x05,
|
||||||
cfg.timeCe = 0x80e8;
|
.timeCe = 0x80e8,
|
||||||
cfg.pdDelay = 0x03;
|
.pdDelay = 0x03,
|
||||||
cfg.qeData = 0;
|
.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] = {};
|
||||||
|
@ -42,15 +42,17 @@ 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.\n");
|
fprintf(stderr, "Failed to init device, ret: %d\n", ret);
|
||||||
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) {
|
||||||
fprintf(stderr, ret == BLISP_ERR_DEVICE_NOT_FOUND
|
if (ret == BLISP_ERR_DEVICE_NOT_FOUND) {
|
||||||
? "Device not found\n"
|
fprintf(stderr, "Device not found\n");
|
||||||
: "Failed to open device.\n");
|
} else {
|
||||||
|
fprintf(stderr, "Failed to open device, ret: %d\n", ret);
|
||||||
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -67,17 +69,20 @@ 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.\n");
|
fprintf(stderr, "Failed to handshake with device, ret: %d\n", ret);
|
||||||
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.\n");
|
fprintf(stderr, "Failed to get boot info, ret: %d\n", ret);
|
||||||
return ret;
|
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(
|
printf(
|
||||||
"BootROM version %d.%d.%d.%d, ChipID: "
|
"BootROM version %d.%d.%d.%d, ChipID: "
|
||||||
"%02X%02X%02X%02X%02X%02X%02X%02X\n",
|
"%02X%02X%02X%02X%02X%02X%02X%02X\n",
|
||||||
@ -86,18 +91,27 @@ blisp_return_t blisp_common_prepare_flash(struct blisp_device* device) {
|
|||||||
boot_info.chip_id[0], boot_info.chip_id[1], boot_info.chip_id[2],
|
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[3], boot_info.chip_id[4], boot_info.chip_id[5],
|
||||||
boot_info.chip_id[6], boot_info.chip_id[7]);
|
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.\n");
|
fprintf(stderr, "Failed to set clock parameters, ret: %d\n", ret);
|
||||||
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.\n");
|
fprintf(stderr, "Failed to set flash parameters, ret: %d\n", ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -137,20 +151,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.\n");
|
fprintf(stderr, "Failed to check image, ret: %d\n", ret);
|
||||||
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.\n");
|
fprintf(stderr, "Failed to run image, ret: %d\n", ret);
|
||||||
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.\n");
|
fprintf(stderr, "Failed to handshake with device, ret: %d\n", ret);
|
||||||
goto exit1;
|
goto exit1;
|
||||||
}
|
}
|
||||||
printf("Handshake with eflash_loader successful.\n");
|
printf("Handshake with eflash_loader successful.\n");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user