mirror of
https://github.com/pine64/blisp.git
synced 2025-06-22 11:54:44 +00:00
Compare commits
3 Commits
59cf5fb038
...
0e0ffb1d8c
Author | SHA1 | Date | |
---|---|---|---|
|
0e0ffb1d8c | ||
|
a6b9b4102b | ||
|
279f2433ea |
@ -20,15 +20,15 @@ add_library(libblisp_static STATIC $<TARGET_OBJECTS:libblisp_obj>)
|
|||||||
|
|
||||||
set_target_properties(libblisp PROPERTIES
|
set_target_properties(libblisp PROPERTIES
|
||||||
PUBLIC_HEADER "include/blisp.h"
|
PUBLIC_HEADER "include/blisp.h"
|
||||||
VERSION 1.0
|
VERSION 0.0.1
|
||||||
SOVERSION 1
|
SOVERSION 1
|
||||||
LIBRARY_OUTPUT_DIRECTORY "shared"
|
LIBRARY_OUTPUT_DIRECTORY "shared"
|
||||||
OUTPUT_NAME "blisp")
|
OUTPUT_NAME "blisp")
|
||||||
|
|
||||||
set_target_properties(libblisp_static PROPERTIES
|
set_target_properties(libblisp_static PROPERTIES
|
||||||
PUBLIC_HEADER "include/blisp.h"
|
PUBLIC_HEADER "include/blisp.h"
|
||||||
VERSION 1.0
|
VERSION 0.0.1
|
||||||
SOVERSION 1
|
SOVERSION 2
|
||||||
ARCHIVE_OUTPUT_DIRECTORY "static"
|
ARCHIVE_OUTPUT_DIRECTORY "static"
|
||||||
OUTPUT_NAME "blisp")
|
OUTPUT_NAME "blisp")
|
||||||
|
|
||||||
|
3109
data/bl60x_eflash_loader.h
Normal file
3109
data/bl60x_eflash_loader.h
Normal file
File diff suppressed because it is too large
Load Diff
4947
data/bl70x_eflash_loader.h
Normal file
4947
data/bl70x_eflash_loader.h
Normal file
File diff suppressed because it is too large
Load Diff
@ -19,7 +19,8 @@ struct blisp_chip { // TODO: Move elsewhere?
|
|||||||
bool usb_isp_available;
|
bool usb_isp_available;
|
||||||
float handshake_byte_multiplier;
|
float handshake_byte_multiplier;
|
||||||
const char* default_xtal; // TODO: Make this selectable
|
const char* default_xtal; // TODO: Make this selectable
|
||||||
bool needs_eflash_loader;
|
int64_t (*load_eflash_loader)(uint8_t clk_type, uint8_t** firmware_buf_ptr);
|
||||||
|
uint32_t tcm_address;
|
||||||
};
|
};
|
||||||
|
|
||||||
extern struct blisp_chip blisp_chip_bl60x;
|
extern struct blisp_chip blisp_chip_bl60x;
|
||||||
|
@ -26,6 +26,9 @@ typedef void (*blisp_easy_progress_callback)(uint32_t current_value,
|
|||||||
uint32_t max_value);
|
uint32_t max_value);
|
||||||
|
|
||||||
struct blisp_easy_transport blisp_easy_transport_new_from_file(FILE* file);
|
struct blisp_easy_transport blisp_easy_transport_new_from_file(FILE* file);
|
||||||
|
struct blisp_easy_transport blisp_easy_transport_new_from_memory(
|
||||||
|
void* data_location,
|
||||||
|
uint32_t data_size);
|
||||||
|
|
||||||
int32_t blisp_easy_load_segment_data(
|
int32_t blisp_easy_load_segment_data(
|
||||||
struct blisp_device* device,
|
struct blisp_device* device,
|
||||||
@ -38,6 +41,10 @@ int32_t blisp_easy_load_ram_image(
|
|||||||
struct blisp_easy_transport* image_transport,
|
struct blisp_easy_transport* image_transport,
|
||||||
blisp_easy_progress_callback progress_callback);
|
blisp_easy_progress_callback progress_callback);
|
||||||
|
|
||||||
|
int32_t blisp_easy_load_ram_app(struct blisp_device* device,
|
||||||
|
struct blisp_easy_transport* app_transport,
|
||||||
|
blisp_easy_progress_callback progress_callback);
|
||||||
|
|
||||||
int32_t blisp_easy_flash_write(struct blisp_device* device,
|
int32_t blisp_easy_flash_write(struct blisp_device* device,
|
||||||
struct blisp_easy_transport* data_transport,
|
struct blisp_easy_transport* data_transport,
|
||||||
uint32_t flash_location,
|
uint32_t flash_location,
|
||||||
|
@ -32,4 +32,67 @@ static void sleep_ms(int milliseconds) {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* * Generated on Mon Jan 9 19:56:36 2023
|
||||||
|
* by pycrc vunknown, https://pycrc.org
|
||||||
|
* using the configuration:
|
||||||
|
* - Width = 32
|
||||||
|
* - Poly = 0x04c11db7
|
||||||
|
* - XorIn = 0xffffffff
|
||||||
|
* - ReflectIn = True
|
||||||
|
* - XorOut = 0xffffffff
|
||||||
|
* - ReflectOut = True
|
||||||
|
* - Algorithm = table-driven
|
||||||
|
*/
|
||||||
|
|
||||||
|
static const uint32_t crc_table[256] = {
|
||||||
|
0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f, 0xe963a535, 0x9e6495a3,
|
||||||
|
0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91,
|
||||||
|
0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de, 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7,
|
||||||
|
0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9, 0xfa0f3d63, 0x8d080df5,
|
||||||
|
0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b,
|
||||||
|
0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59,
|
||||||
|
0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599, 0xb8bda50f,
|
||||||
|
0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924, 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d,
|
||||||
|
0x76dc4190, 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433,
|
||||||
|
0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01,
|
||||||
|
0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457,
|
||||||
|
0x65b0d9c6, 0x12b7e950, 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65,
|
||||||
|
0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb,
|
||||||
|
0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9,
|
||||||
|
0x5005713c, 0x270241aa, 0xbe0b1010, 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
|
||||||
|
0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad,
|
||||||
|
0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683,
|
||||||
|
0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8, 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1,
|
||||||
|
0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb, 0x196c3671, 0x6e6b06e7,
|
||||||
|
0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5,
|
||||||
|
0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b,
|
||||||
|
0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef, 0x4669be79,
|
||||||
|
0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236, 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f,
|
||||||
|
0xc5ba3bbe, 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d,
|
||||||
|
0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713,
|
||||||
|
0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21,
|
||||||
|
0x86d3d2d4, 0xf1d4e242, 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777,
|
||||||
|
0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45,
|
||||||
|
0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db,
|
||||||
|
0xaed16a4a, 0xd9d65adc, 0x40df0b66, 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
|
||||||
|
0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, 0xcdd70693, 0x54de5729, 0x23d967bf,
|
||||||
|
0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d
|
||||||
|
};
|
||||||
|
|
||||||
|
static uint32_t crc32_calculate(const void *data, size_t data_len)
|
||||||
|
{
|
||||||
|
uint32_t crc = 0xffffffff;
|
||||||
|
const unsigned char *d = (const unsigned char *)data;
|
||||||
|
unsigned int tbl_idx;
|
||||||
|
|
||||||
|
while (data_len--) {
|
||||||
|
tbl_idx = (crc ^ *d) & 0xff;
|
||||||
|
crc = (crc_table[tbl_idx] ^ (crc >> 8)) & 0xffffffff;
|
||||||
|
d++;
|
||||||
|
}
|
||||||
|
return (crc & 0xffffffff) ^ 0xffffffff;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
224
lib/blisp_easy.c
224
lib/blisp_easy.c
@ -1,18 +1,32 @@
|
|||||||
// SPDX-License-Identifier: MIT
|
// SPDX-License-Identifier: MIT
|
||||||
#include "blisp_easy.h"
|
#include "blisp_easy.h"
|
||||||
#include "blisp_struct.h"
|
#include "blisp_struct.h"
|
||||||
|
#include "blisp_util.h"
|
||||||
|
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
static int64_t blisp_easy_transport_read(struct blisp_easy_transport* transport,
|
static int64_t blisp_easy_transport_read(struct blisp_easy_transport* transport,
|
||||||
void* buffer,
|
void* buffer,
|
||||||
uint32_t size) {
|
uint32_t size) {
|
||||||
if (transport->type == 0) {
|
if (transport->type == 0) {
|
||||||
|
// TODO: Implement reading more than available
|
||||||
|
memcpy(buffer, (uint8_t*)transport->data.memory.data_location + transport->data.memory.current_position, size);
|
||||||
|
transport->data.memory.current_position += size;
|
||||||
|
return size;
|
||||||
} else {
|
} else {
|
||||||
return fread(buffer, size, 1, transport->data.file_handle);
|
return fread(buffer, size, 1, transport->data.file_handle);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int64_t blisp_easy_transport_size(struct blisp_easy_transport* transport) {
|
||||||
|
if (transport->type == 0) {
|
||||||
|
return transport->data.memory.data_size;
|
||||||
|
} else {
|
||||||
|
// TODO: Implement
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void blisp_easy_report_progress(blisp_easy_progress_callback callback,
|
static void blisp_easy_report_progress(blisp_easy_progress_callback callback,
|
||||||
uint32_t current_value,
|
uint32_t current_value,
|
||||||
uint32_t max_value) {
|
uint32_t max_value) {
|
||||||
@ -26,6 +40,17 @@ struct blisp_easy_transport blisp_easy_transport_new_from_file(FILE* file) {
|
|||||||
return transport;
|
return transport;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct blisp_easy_transport blisp_easy_transport_new_from_memory(
|
||||||
|
void* data_location,
|
||||||
|
uint32_t data_size) {
|
||||||
|
struct blisp_easy_transport transport = {
|
||||||
|
.type = 0,
|
||||||
|
.data.memory.data_location = data_location,
|
||||||
|
.data.memory.data_size = data_size,
|
||||||
|
.data.memory.current_position = 0};
|
||||||
|
return transport;
|
||||||
|
}
|
||||||
|
|
||||||
int32_t blisp_easy_load_segment_data(
|
int32_t blisp_easy_load_segment_data(
|
||||||
struct blisp_device* device,
|
struct blisp_device* device,
|
||||||
uint32_t segment_size,
|
uint32_t segment_size,
|
||||||
@ -44,13 +69,13 @@ int32_t blisp_easy_load_segment_data(
|
|||||||
if (buffer_size > 4092) {
|
if (buffer_size > 4092) {
|
||||||
buffer_size = 4092;
|
buffer_size = 4092;
|
||||||
}
|
}
|
||||||
blisp_easy_transport_read(segment_transport, buffer, buffer_size); // TODO: Error Handling
|
blisp_easy_transport_read(segment_transport, buffer,
|
||||||
ret = blisp_device_load_segment_data(device, buffer,
|
buffer_size); // TODO: Error Handling
|
||||||
buffer_size);
|
ret = blisp_device_load_segment_data(device, buffer, buffer_size);
|
||||||
if (ret < BLISP_OK) {
|
if (ret < BLISP_OK) {
|
||||||
// TODO: Error logging fprintf(stderr, "Failed to load segment data. (ret
|
// TODO: Error logging fprintf(stderr, "Failed to load segment data. (ret
|
||||||
// %d)\n", ret);
|
// %d)\n", ret);
|
||||||
return BLISP_EASY_ERR_TRANSPORT_ERROR;
|
return ret;
|
||||||
}
|
}
|
||||||
sent_data += buffer_size;
|
sent_data += buffer_size;
|
||||||
blisp_easy_report_progress(progress_callback, sent_data, segment_size);
|
blisp_easy_report_progress(progress_callback, sent_data, segment_size);
|
||||||
@ -71,7 +96,7 @@ int32_t blisp_easy_load_ram_image(
|
|||||||
ret = blisp_device_load_boot_header(device, (uint8_t*)&image_boot_header);
|
ret = blisp_device_load_boot_header(device, (uint8_t*)&image_boot_header);
|
||||||
if (ret != BLISP_OK) {
|
if (ret != BLISP_OK) {
|
||||||
// TODO: Error printing: fprintf(stderr, "Failed to load boot header.\n");
|
// TODO: Error printing: fprintf(stderr, "Failed to load boot header.\n");
|
||||||
return BLISP_EASY_ERR_TRANSPORT_ERROR;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
@ -85,14 +110,14 @@ int32_t blisp_easy_load_ram_image(
|
|||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
// TODO: Error printing: fprintf(stderr, "Failed to load segment
|
// TODO: Error printing: fprintf(stderr, "Failed to load segment
|
||||||
// header.");
|
// header.");
|
||||||
return BLISP_EASY_ERR_TRANSPORT_ERROR;
|
return ret;
|
||||||
}
|
}
|
||||||
// TODO: Info printing: printf("Flashing %d. segment\n", seg_index + 1);
|
// TODO: Info printing: printf("Flashing %d. segment\n", seg_index + 1);
|
||||||
|
|
||||||
ret = blisp_easy_load_segment_data(device, segment_header.length,
|
ret = blisp_easy_load_segment_data(device, segment_header.length,
|
||||||
image_transport, progress_callback);
|
image_transport, progress_callback);
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
return BLISP_EASY_ERR_TRANSPORT_ERROR;
|
return ret;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -106,6 +131,188 @@ int32_t blisp_easy_load_ram_image(
|
|||||||
return BLISP_OK;
|
return BLISP_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int32_t blisp_easy_load_ram_app(struct blisp_device* device,
|
||||||
|
struct blisp_easy_transport* app_transport,
|
||||||
|
blisp_easy_progress_callback progress_callback)
|
||||||
|
{
|
||||||
|
int32_t ret;
|
||||||
|
// TODO: Rework
|
||||||
|
// region boot header fill
|
||||||
|
struct bfl_boot_header boot_header;
|
||||||
|
memcpy(boot_header.magiccode, "BFNP", 4);
|
||||||
|
memcpy(boot_header.flashCfg.magiccode, "FCFG", 4);
|
||||||
|
boot_header.revison = 0x01;
|
||||||
|
boot_header.flashCfg.cfg.ioMode = 0x04;
|
||||||
|
boot_header.flashCfg.cfg.cReadSupport = 0x01;
|
||||||
|
boot_header.flashCfg.cfg.clkDelay = 0x01;
|
||||||
|
boot_header.flashCfg.cfg.clkInvert = 0x01;
|
||||||
|
boot_header.flashCfg.cfg.resetEnCmd = 0x66;
|
||||||
|
boot_header.flashCfg.cfg.resetCmd = 0x99;
|
||||||
|
boot_header.flashCfg.cfg.resetCreadCmd = 0xFF;
|
||||||
|
boot_header.flashCfg.cfg.resetCreadCmdSize = 0x03;
|
||||||
|
boot_header.flashCfg.cfg.jedecIdCmd = 0x9F;
|
||||||
|
boot_header.flashCfg.cfg.jedecIdCmdDmyClk = 0x00;
|
||||||
|
boot_header.flashCfg.cfg.qpiJedecIdCmd = 0x9F;
|
||||||
|
boot_header.flashCfg.cfg.qpiJedecIdCmdDmyClk = 0x00;
|
||||||
|
boot_header.flashCfg.cfg.sectorSize = 0x04;
|
||||||
|
boot_header.flashCfg.cfg.mid = 0xEF;
|
||||||
|
boot_header.flashCfg.cfg.pageSize = 0x100;
|
||||||
|
boot_header.flashCfg.cfg.chipEraseCmd = 0xC7;
|
||||||
|
boot_header.flashCfg.cfg.sectorEraseCmd = 0x20;
|
||||||
|
boot_header.flashCfg.cfg.blk32EraseCmd = 0x52;
|
||||||
|
boot_header.flashCfg.cfg.blk64EraseCmd = 0xD8;
|
||||||
|
boot_header.flashCfg.cfg.writeEnableCmd = 0x06;
|
||||||
|
boot_header.flashCfg.cfg.pageProgramCmd = 0x02;
|
||||||
|
boot_header.flashCfg.cfg.qpageProgramCmd = 0x32;
|
||||||
|
boot_header.flashCfg.cfg.qppAddrMode = 0x00;
|
||||||
|
boot_header.flashCfg.cfg.fastReadCmd = 0x0B;
|
||||||
|
boot_header.flashCfg.cfg.frDmyClk = 0x01;
|
||||||
|
boot_header.flashCfg.cfg.qpiFastReadCmd = 0x0B;
|
||||||
|
boot_header.flashCfg.cfg.qpiFrDmyClk = 0x01;
|
||||||
|
boot_header.flashCfg.cfg.fastReadDoCmd = 0x3B;
|
||||||
|
boot_header.flashCfg.cfg.frDoDmyClk = 0x01;
|
||||||
|
boot_header.flashCfg.cfg.fastReadDioCmd = 0xBB;
|
||||||
|
boot_header.flashCfg.cfg.frDioDmyClk = 0x00;
|
||||||
|
boot_header.flashCfg.cfg.fastReadQoCmd = 0x6B;
|
||||||
|
boot_header.flashCfg.cfg.frQoDmyClk = 0x01;
|
||||||
|
boot_header.flashCfg.cfg.fastReadQioCmd = 0xEB;
|
||||||
|
boot_header.flashCfg.cfg.frQioDmyClk = 0x02;
|
||||||
|
boot_header.flashCfg.cfg.qpiFastReadQioCmd = 0xEB;
|
||||||
|
boot_header.flashCfg.cfg.qpiFrQioDmyClk = 0x02;
|
||||||
|
boot_header.flashCfg.cfg.qpiPageProgramCmd = 0x02;
|
||||||
|
boot_header.flashCfg.cfg.writeVregEnableCmd = 0x50;
|
||||||
|
boot_header.flashCfg.cfg.wrEnableIndex = 0x00;
|
||||||
|
boot_header.flashCfg.cfg.qeIndex = 0x01;
|
||||||
|
boot_header.flashCfg.cfg.busyIndex = 0x00;
|
||||||
|
boot_header.flashCfg.cfg.wrEnableBit = 0x01;
|
||||||
|
boot_header.flashCfg.cfg.qeBit = 0x01;
|
||||||
|
boot_header.flashCfg.cfg.busyBit = 0x00;
|
||||||
|
boot_header.flashCfg.cfg.wrEnableWriteRegLen = 0x02;
|
||||||
|
boot_header.flashCfg.cfg.wrEnableReadRegLen = 0x01;
|
||||||
|
boot_header.flashCfg.cfg.qeWriteRegLen = 0x01;
|
||||||
|
boot_header.flashCfg.cfg.qeReadRegLen = 0x01;
|
||||||
|
boot_header.flashCfg.cfg.releasePowerDown = 0xAB;
|
||||||
|
boot_header.flashCfg.cfg.busyReadRegLen = 0x01;
|
||||||
|
boot_header.flashCfg.cfg.readRegCmd[0] = 0x05;
|
||||||
|
boot_header.flashCfg.cfg.readRegCmd[1] = 0x35;
|
||||||
|
boot_header.flashCfg.cfg.readRegCmd[2] = 0x00;
|
||||||
|
boot_header.flashCfg.cfg.readRegCmd[3] = 0x00;
|
||||||
|
boot_header.flashCfg.cfg.writeRegCmd[0] = 0x01;
|
||||||
|
boot_header.flashCfg.cfg.writeRegCmd[1] = 0x31;
|
||||||
|
boot_header.flashCfg.cfg.writeRegCmd[2] = 0x00;
|
||||||
|
boot_header.flashCfg.cfg.writeRegCmd[3] = 0x00;
|
||||||
|
boot_header.flashCfg.cfg.enterQpi = 0x38;
|
||||||
|
boot_header.flashCfg.cfg.exitQpi = 0xFF;
|
||||||
|
boot_header.flashCfg.cfg.cReadMode = 0x20;
|
||||||
|
boot_header.flashCfg.cfg.cRExit = 0xFF;
|
||||||
|
boot_header.flashCfg.cfg.burstWrapCmd = 0x77;
|
||||||
|
boot_header.flashCfg.cfg.burstWrapCmdDmyClk = 0x03;
|
||||||
|
boot_header.flashCfg.cfg.burstWrapDataMode = 0x02;
|
||||||
|
boot_header.flashCfg.cfg.burstWrapData = 0x40;
|
||||||
|
boot_header.flashCfg.cfg.deBurstWrapCmd = 0x77;
|
||||||
|
boot_header.flashCfg.cfg.deBurstWrapCmdDmyClk = 0x03;
|
||||||
|
boot_header.flashCfg.cfg.deBurstWrapDataMode = 0x02;
|
||||||
|
boot_header.flashCfg.cfg.deBurstWrapData = 0xF0;
|
||||||
|
boot_header.flashCfg.cfg.timeEsector = 0x12C;
|
||||||
|
boot_header.flashCfg.cfg.timeE32k = 0x4B0;
|
||||||
|
boot_header.flashCfg.cfg.timeE64k = 0x4B0;
|
||||||
|
boot_header.flashCfg.cfg.timePagePgm = 0x05;
|
||||||
|
boot_header.flashCfg.cfg.timeCe = 0xD40;
|
||||||
|
boot_header.flashCfg.cfg.pdDelay = 0x03;
|
||||||
|
boot_header.flashCfg.cfg.qeData = 0x00;
|
||||||
|
boot_header.flashCfg.crc32 = 0xC4BDD748;
|
||||||
|
boot_header.clkCfg.cfg.xtal_type = 0x04;
|
||||||
|
boot_header.clkCfg.cfg.pll_clk = 0x04;
|
||||||
|
boot_header.clkCfg.cfg.hclk_div = 0x00;
|
||||||
|
boot_header.clkCfg.cfg.bclk_div = 0x01;
|
||||||
|
boot_header.clkCfg.cfg.flash_clk_type = 0x02;
|
||||||
|
boot_header.clkCfg.cfg.flash_clk_div = 0x00;
|
||||||
|
boot_header.clkCfg.crc32 = 0x824E14BB;
|
||||||
|
boot_header.bootcfg.bval.sign = 0x00;
|
||||||
|
boot_header.bootcfg.bval.encrypt_type = 0x00;
|
||||||
|
boot_header.bootcfg.bval.key_sel = 0x00;
|
||||||
|
boot_header.bootcfg.bval.rsvd6_7 = 0x00;
|
||||||
|
boot_header.bootcfg.bval.no_segment = 0x01;
|
||||||
|
boot_header.bootcfg.bval.cache_enable = 0x01;
|
||||||
|
boot_header.bootcfg.bval.notload_in_bootrom = 0x00;
|
||||||
|
boot_header.bootcfg.bval.aes_region_lock = 0x00;
|
||||||
|
boot_header.bootcfg.bval.cache_way_disable = 0x00;
|
||||||
|
boot_header.bootcfg.bval.crc_ignore = 0x01;
|
||||||
|
boot_header.bootcfg.bval.hash_ignore = 0x01;
|
||||||
|
boot_header.bootcfg.bval.halt_ap = 0x00;
|
||||||
|
boot_header.bootcfg.bval.rsvd19_31 = 0x00;
|
||||||
|
boot_header.segment_info.segment_cnt = 0x01;
|
||||||
|
boot_header.bootentry = 0x00;
|
||||||
|
boot_header.flashoffset = device->chip->tcm_address;
|
||||||
|
boot_header.hash[0x00] = 0xEF;
|
||||||
|
boot_header.hash[0x01] = 0xBE;
|
||||||
|
boot_header.hash[0x02] = 0xAD;
|
||||||
|
boot_header.hash[0x03] = 0xDE;
|
||||||
|
boot_header.hash[0x04] = 0x00;
|
||||||
|
boot_header.hash[0x05] = 0x00;
|
||||||
|
boot_header.hash[0x06] = 0x00;
|
||||||
|
boot_header.hash[0x07] = 0x00;
|
||||||
|
boot_header.hash[0x08] = 0x00;
|
||||||
|
boot_header.hash[0x09] = 0x00;
|
||||||
|
boot_header.hash[0x0a] = 0x00;
|
||||||
|
boot_header.hash[0x0b] = 0x00;
|
||||||
|
boot_header.hash[0x0c] = 0x00;
|
||||||
|
boot_header.hash[0x0d] = 0x00;
|
||||||
|
boot_header.hash[0x0e] = 0x00;
|
||||||
|
boot_header.hash[0x0f] = 0x00;
|
||||||
|
boot_header.hash[0x10] = 0x00;
|
||||||
|
boot_header.hash[0x11] = 0x00;
|
||||||
|
boot_header.hash[0x12] = 0x00;
|
||||||
|
boot_header.hash[0x13] = 0x00;
|
||||||
|
boot_header.hash[0x14] = 0x00;
|
||||||
|
boot_header.hash[0x15] = 0x00;
|
||||||
|
boot_header.hash[0x16] = 0x00;
|
||||||
|
boot_header.hash[0x17] = 0x00;
|
||||||
|
boot_header.hash[0x18] = 0x00;
|
||||||
|
boot_header.hash[0x19] = 0x00;
|
||||||
|
boot_header.hash[0x1a] = 0x00;
|
||||||
|
boot_header.hash[0x1b] = 0x00;
|
||||||
|
boot_header.hash[0x1c] = 0x00;
|
||||||
|
boot_header.hash[0x1d] = 0x00;
|
||||||
|
boot_header.hash[0x1e] = 0x00;
|
||||||
|
boot_header.hash[0x1f] = 0x00;
|
||||||
|
boot_header.rsv1 = 0x00;
|
||||||
|
boot_header.rsv2 = 0x00;
|
||||||
|
boot_header.crc32 = 0xDEADBEEF;
|
||||||
|
// endregion
|
||||||
|
|
||||||
|
|
||||||
|
ret = blisp_device_load_boot_header(device, (uint8_t*)&boot_header);
|
||||||
|
if (ret != BLISP_OK) {
|
||||||
|
blisp_dlog("Failed to load boot header, ret: %d.", ret);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct blisp_segment_header segment_header = {
|
||||||
|
.dest_addr = device->chip->tcm_address,
|
||||||
|
.length = blisp_easy_transport_size(app_transport),
|
||||||
|
.reserved = 0,
|
||||||
|
.crc32 = 0
|
||||||
|
};
|
||||||
|
segment_header.crc32 = crc32_calculate(&segment_header, 3 * sizeof(uint32_t)); // TODO: Make function
|
||||||
|
|
||||||
|
ret = blisp_device_load_segment_header(device, &segment_header);
|
||||||
|
if (ret != 0) {
|
||||||
|
blisp_dlog("Failed to load segment header, ret: %d.", ret);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = blisp_easy_load_segment_data(device, blisp_easy_transport_size(app_transport),
|
||||||
|
app_transport, progress_callback);
|
||||||
|
if (ret != 0) {
|
||||||
|
// TODO: Error printing
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return BLISP_OK;
|
||||||
|
}
|
||||||
|
|
||||||
int32_t blisp_easy_flash_write(struct blisp_device* device,
|
int32_t blisp_easy_flash_write(struct blisp_device* device,
|
||||||
struct blisp_easy_transport* data_transport,
|
struct blisp_easy_transport* data_transport,
|
||||||
uint32_t flash_location,
|
uint32_t flash_location,
|
||||||
@ -122,7 +329,8 @@ int32_t blisp_easy_flash_write(struct blisp_device* device,
|
|||||||
if (buffer_size > 2052) {
|
if (buffer_size > 2052) {
|
||||||
buffer_size = 2052;
|
buffer_size = 2052;
|
||||||
}
|
}
|
||||||
blisp_easy_transport_read(data_transport, buffer, buffer_size); // TODO: Error Handling
|
blisp_easy_transport_read(data_transport, buffer,
|
||||||
|
buffer_size); // TODO: Error Handling
|
||||||
ret = blisp_device_flash_write(device, flash_location + sent_data, buffer,
|
ret = blisp_device_flash_write(device, flash_location + sent_data, buffer,
|
||||||
buffer_size);
|
buffer_size);
|
||||||
if (ret < BLISP_OK) {
|
if (ret < BLISP_OK) {
|
||||||
|
@ -1,11 +1,24 @@
|
|||||||
// SPDX-License-Identifier: MIT
|
// SPDX-License-Identifier: MIT
|
||||||
|
#include <malloc.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include "../../data/bl60x_eflash_loader.h"
|
||||||
#include "blisp.h"
|
#include "blisp.h"
|
||||||
|
|
||||||
|
int64_t blisp_chip_bl60x_get_eflash_loader(uint8_t clk_type, uint8_t** firmware_buf_ptr)
|
||||||
|
{
|
||||||
|
uint8_t* firmware_buf = malloc(sizeof(bl60x_eflash_loader_bin));
|
||||||
|
memcpy(firmware_buf, bl60x_eflash_loader_bin, sizeof(bl60x_eflash_loader_bin));
|
||||||
|
*(firmware_buf + 0xE0) = 4; // TODO: 40 MHz clock
|
||||||
|
*firmware_buf_ptr = firmware_buf;
|
||||||
|
return sizeof(bl60x_eflash_loader_bin);
|
||||||
|
}
|
||||||
|
|
||||||
struct blisp_chip blisp_chip_bl60x = {
|
struct blisp_chip blisp_chip_bl60x = {
|
||||||
.type = BLISP_CHIP_BL60X,
|
.type = BLISP_CHIP_BL60X,
|
||||||
.type_str = "bl60x",
|
.type_str = "bl60x",
|
||||||
.usb_isp_available = false,
|
.usb_isp_available = false,
|
||||||
.default_xtal = "40m",
|
.default_xtal = "40m",
|
||||||
.handshake_byte_multiplier = 0.006f,
|
.handshake_byte_multiplier = 0.006f,
|
||||||
.needs_eflash_loader = true
|
.load_eflash_loader = blisp_chip_bl60x_get_eflash_loader,
|
||||||
|
.tcm_address = 0x22010000
|
||||||
};
|
};
|
||||||
|
@ -7,5 +7,5 @@ struct blisp_chip blisp_chip_bl61x = {
|
|||||||
.usb_isp_available = true,
|
.usb_isp_available = true,
|
||||||
.default_xtal = "-", // ?
|
.default_xtal = "-", // ?
|
||||||
.handshake_byte_multiplier = 0.003f,
|
.handshake_byte_multiplier = 0.003f,
|
||||||
.needs_eflash_loader = false
|
.get_eflash_loader = NULL
|
||||||
};
|
};
|
||||||
|
@ -1,11 +1,25 @@
|
|||||||
// SPDX-License-Identifier: MIT
|
// SPDX-License-Identifier: MIT
|
||||||
|
#include <malloc.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include "../../data/bl70x_eflash_loader.h"
|
||||||
#include "blisp.h"
|
#include "blisp.h"
|
||||||
|
|
||||||
|
int64_t blisp_chip_bl70x_get_eflash_loader(uint8_t clk_type, uint8_t** firmware_buf_ptr)
|
||||||
|
{
|
||||||
|
uint8_t* firmware_buf = malloc(sizeof(bl70x_eflash_loader_bin));
|
||||||
|
memcpy(firmware_buf, bl70x_eflash_loader_bin, sizeof(bl70x_eflash_loader_bin));
|
||||||
|
*(firmware_buf + 0xE0) = 1; // TODO: 32 MHz clock
|
||||||
|
*firmware_buf_ptr = firmware_buf;
|
||||||
|
return sizeof(bl70x_eflash_loader_bin);
|
||||||
|
}
|
||||||
|
|
||||||
struct blisp_chip blisp_chip_bl70x = {
|
struct blisp_chip blisp_chip_bl70x = {
|
||||||
.type = BLISP_CHIP_BL70X,
|
.type = BLISP_CHIP_BL70X,
|
||||||
.type_str = "bl70x",
|
.type_str = "bl70x",
|
||||||
.usb_isp_available = true,
|
.usb_isp_available = true,
|
||||||
.default_xtal = "32m",
|
.default_xtal = "32m",
|
||||||
.handshake_byte_multiplier = 0.003f,
|
.handshake_byte_multiplier = 0.003f,
|
||||||
.needs_eflash_loader = true
|
.load_eflash_loader = blisp_chip_bl70x_get_eflash_loader,
|
||||||
|
.tcm_address = 0x22010000
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -7,5 +7,5 @@ struct blisp_chip blisp_chip_bl808 = {
|
|||||||
.usb_isp_available = true, // TODO: Only for BL808D :-(
|
.usb_isp_available = true, // TODO: Only for BL808D :-(
|
||||||
.default_xtal = "-", // ?
|
.default_xtal = "-", // ?
|
||||||
.handshake_byte_multiplier = 0.003f,
|
.handshake_byte_multiplier = 0.003f,
|
||||||
.needs_eflash_loader = false
|
.get_eflash_loader = NULL
|
||||||
};
|
};
|
||||||
|
@ -1,11 +1,12 @@
|
|||||||
// SPDX-License-Identifier: MIT
|
// SPDX-License-Identifier: MIT
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include <blisp.h>
|
|
||||||
#include <argtable3.h>
|
#include <argtable3.h>
|
||||||
#include <string.h>
|
#include <blisp.h>
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
|
#include <malloc.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
#include "blisp_easy.h"
|
#include "blisp_easy.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
|
||||||
@ -54,7 +55,6 @@ int32_t blisp_common_init_device(struct blisp_device* device, struct arg_str* po
|
|||||||
*/
|
*/
|
||||||
int32_t blisp_common_prepare_flash(struct blisp_device* device) {
|
int32_t blisp_common_prepare_flash(struct blisp_device* device) {
|
||||||
int32_t ret = 0;
|
int32_t ret = 0;
|
||||||
FILE* eflash_loader_file = NULL;
|
|
||||||
|
|
||||||
printf("Sending a handshake...\n");
|
printf("Sending a handshake...\n");
|
||||||
ret = blisp_device_handshake(device, false);
|
ret = blisp_device_handshake(device, false);
|
||||||
@ -79,7 +79,7 @@ int32_t blisp_common_prepare_flash(struct blisp_device* device) {
|
|||||||
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]);
|
||||||
|
|
||||||
if (!device->chip->needs_eflash_loader) {
|
if (device->chip->load_eflash_loader == NULL) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -91,34 +91,27 @@ int32_t blisp_common_prepare_flash(struct blisp_device* device) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
char exe_path[PATH_MAX];
|
uint8_t* eflash_loader_buffer = NULL;
|
||||||
char eflash_loader_path[PATH_MAX];
|
// TODO: Error check
|
||||||
if (util_get_binary_folder(exe_path, PATH_MAX) <= 0) {
|
int64_t eflash_loader_buffer_length = device->chip->load_eflash_loader(0, &eflash_loader_buffer);
|
||||||
fprintf(stderr,
|
|
||||||
"Failed to find executable path to search for the "
|
struct blisp_easy_transport eflash_loader_transport =
|
||||||
"eflash loader\n");
|
blisp_easy_transport_new_from_memory(eflash_loader_buffer, eflash_loader_buffer_length);
|
||||||
return -1;
|
|
||||||
}
|
ret = blisp_easy_load_ram_app(device, &eflash_loader_transport, blisp_common_progress_callback);
|
||||||
snprintf(eflash_loader_path, PATH_MAX, "%s/data/%s/eflash_loader_%s.bin",
|
|
||||||
exe_path, device->chip->type_str,
|
if (ret != BLISP_OK) {
|
||||||
device->chip->default_xtal); // TODO: Let user pick
|
fprintf(stderr, "Failed to load eflash_loader, ret: %d\n", ret);
|
||||||
printf("Loading the eflash loader file from disk\n");
|
|
||||||
eflash_loader_file = fopen(eflash_loader_path, "rb");
|
|
||||||
if (eflash_loader_file == NULL) {
|
|
||||||
fprintf(stderr,
|
|
||||||
"Could not open the eflash loader file from disk.\n"
|
|
||||||
"Does \"%s\" exist?\n",
|
|
||||||
eflash_loader_path);
|
|
||||||
ret = -1;
|
ret = -1;
|
||||||
goto exit1;
|
goto exit1;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct blisp_easy_transport eflash_loader_transport =
|
free(eflash_loader_buffer);
|
||||||
blisp_easy_transport_new_from_file(eflash_loader_file);
|
eflash_loader_buffer = NULL;
|
||||||
ret = blisp_easy_load_ram_image(device, &eflash_loader_transport,
|
|
||||||
blisp_common_progress_callback);
|
ret = blisp_device_check_image(device);
|
||||||
if (ret != BLISP_OK) {
|
if (ret != 0) {
|
||||||
fprintf(stderr, "Failed to load eflash_loader, ret: %d\n", ret);
|
fprintf(stderr, "Failed to check image.\n");
|
||||||
ret = -1;
|
ret = -1;
|
||||||
goto exit1;
|
goto exit1;
|
||||||
}
|
}
|
||||||
@ -139,7 +132,7 @@ int32_t blisp_common_prepare_flash(struct blisp_device* device) {
|
|||||||
}
|
}
|
||||||
printf("Handshake with eflash_loader successful.\n");
|
printf("Handshake with eflash_loader successful.\n");
|
||||||
exit1:
|
exit1:
|
||||||
if (eflash_loader_file != NULL)
|
if (eflash_loader_buffer != NULL)
|
||||||
fclose(eflash_loader_file);
|
free(eflash_loader_buffer);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
@ -45,8 +45,8 @@ int8_t args_parse_exec(int argc, char** argv) {
|
|||||||
print_help();
|
print_help();
|
||||||
return 1;
|
return 1;
|
||||||
} else if (version->count) {
|
} else if (version->count) {
|
||||||
printf("blisp 1.0.0\n");
|
printf("blisp 0.0.1\n");
|
||||||
printf("Copyright (C) 2022 Marek Kraus and PINE64 Community\n");
|
printf("Copyright (C) 2023 Marek Kraus and PINE64 Community\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
#ifndef BLISP_UTIL_H
|
#ifndef BLISP_UTIL_H
|
||||||
#define BLISP_UTIL_H
|
#define BLISP_UTIL_H
|
||||||
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
#ifdef __linux__
|
#ifdef __linux__
|
||||||
|
Loading…
x
Reference in New Issue
Block a user