Updated linker script and flash helpers to get 128k extra code space. Note that this requires the updated bootloader with compression support.

This commit is contained in:
Benjamin Vedder 2022-01-18 20:31:24 +01:00
parent f74019c940
commit f6baa653ea
7 changed files with 73 additions and 60 deletions

View File

@ -1,3 +1,6 @@
=== FW 6.00 <dev> ===
* Added stack checks.
=== FW 5.03 ===
* Fixed inductance measurement bug.
* Speed tracker windup protection.

View File

@ -252,8 +252,8 @@ void commands_process_packet(unsigned char *data, unsigned int len,
send_buffer[ind++] = 1;
#endif
#else
if (flash_helper_qmlui_data()) {
send_buffer[ind++] = flash_helper_qmlui_flags();
if (flash_helper_code_data(CODE_IND_QML)) {
send_buffer[ind++] = flash_helper_code_flags(CODE_IND_QML);
} else {
send_buffer[ind++] = 0;
}
@ -1372,8 +1372,8 @@ void commands_process_packet(unsigned char *data, unsigned int len,
int32_t len_qml = buffer_get_int32(data, &ind);
int32_t ofs_qml = buffer_get_int32(data, &ind);
uint8_t *qmlui_data = flash_helper_qmlui_data();
int32_t qmlui_len = flash_helper_qmlui_size();
uint8_t *qmlui_data = flash_helper_code_data(CODE_IND_QML);
int32_t qmlui_len = flash_helper_code_size(CODE_IND_QML);
#ifdef QMLUI_SOURCE_APP
qmlui_data = data_qml_app;
@ -1406,7 +1406,7 @@ void commands_process_packet(unsigned char *data, unsigned int len,
if (nrf_driver_ext_nrf_running()) {
nrf_driver_pause(6000);
}
uint16_t flash_res = flash_helper_erase_qmlui();
uint16_t flash_res = flash_helper_erase_code(CODE_IND_QML);
ind = 0;
uint8_t send_buffer[50];
@ -1422,7 +1422,7 @@ void commands_process_packet(unsigned char *data, unsigned int len,
if (nrf_driver_ext_nrf_running()) {
nrf_driver_pause(2000);
}
uint16_t flash_res = flash_helper_write_qmlui(qmlui_offset, data + ind, len - ind);
uint16_t flash_res = flash_helper_write_code(CODE_IND_QML, qmlui_offset, data + ind, len - ind);
SHUTDOWN_RESET();

View File

@ -24,7 +24,7 @@
#define FW_VERSION_MAJOR 6
#define FW_VERSION_MINOR 00
// Set to 0 for building a release and iterate during beta test builds
#define FW_TEST_VERSION_NUMBER 1
#define FW_TEST_VERSION_NUMBER 2
#include "datatypes.h"

View File

@ -1,5 +1,5 @@
/*
Copyright 2016 - 2021 Benjamin Vedder benjamin@vedder.se
Copyright 2016 - 2022 Benjamin Vedder benjamin@vedder.se
This file is part of the VESC firmware.
@ -37,9 +37,11 @@
#define APP_BASE 0
#define NEW_APP_BASE 8
#define NEW_APP_SECTORS 3
#define APP_MAX_SIZE (1024 * 128 * 3 - 8) // Note that the bootloader needs 8 extra bytes
#define QMLUI_BASE 7
#define APP_MAX_SIZE (1024 * 128 * 4 - 8) // Note that the bootloader needs 8 extra bytes
#define QMLUI_BASE 9
#define LISP_BASE 10
#define QMLUI_MAX_SIZE (1024 * 128 - 8)
#define LISP_MAX_SIZE (1024 * 128 - 8)
// Base address of the Flash sectors
#define ADDR_FLASH_SECTOR_0 ((uint32_t)0x08000000) // Base @ of Sector 0, 16 Kbytes
@ -77,11 +79,16 @@ const crc_info_t __attribute__((section (".crcinfo"))) crc_info = {0xFFFFFFFF, 0
// Private functions
static uint16_t erase_sector(uint32_t sector);
static uint16_t write_data(uint32_t base, uint8_t *data, uint32_t len);
static void qmlui_check(void);
static void qmlui_check(int ind);
// Private variables
static bool qmlui_check_done = false;
static bool qmlui_ok = false;
typedef struct {
bool check_done;
bool ok;
} _code_checks;
static _code_checks code_checks[2] = {0};
static int code_sectors[2] = {QMLUI_BASE, LISP_BASE};
// Private constants
static const uint32_t flash_addr[FLASH_SECTORS] = {
@ -161,47 +168,47 @@ uint16_t flash_helper_write_new_app_data(uint32_t offset, uint8_t *data, uint32_
return write_data(flash_addr[NEW_APP_BASE] + offset, data, len);
}
uint16_t flash_helper_erase_qmlui(void) {
qmlui_check_done = false;
qmlui_ok = false;
return erase_sector(flash_sector[QMLUI_BASE]);
uint16_t flash_helper_erase_code(int ind) {
code_checks[ind].check_done = false;
code_checks[ind].ok = false;
return erase_sector(flash_sector[code_sectors[ind]]);
}
uint16_t flash_helper_write_qmlui(uint32_t offset, uint8_t *data, uint32_t len) {
qmlui_check_done = false;
qmlui_ok = false;
return write_data(flash_addr[QMLUI_BASE] + offset, data, len);
uint16_t flash_helper_write_code(int ind, uint32_t offset, uint8_t *data, uint32_t len) {
code_checks[ind].check_done = false;
code_checks[ind].ok = false;
return write_data(flash_addr[code_sectors[ind]] + offset, data, len);
}
uint8_t *flash_helper_qmlui_data(void) {
qmlui_check();
uint8_t* flash_helper_code_data(int ind) {
qmlui_check(ind);
if (qmlui_check_done && qmlui_ok) {
return (uint8_t*)(flash_addr[QMLUI_BASE]) + 8;
if (code_checks[ind].check_done && code_checks[ind].ok) {
return (uint8_t*)(flash_addr[code_sectors[ind]]) + 8;
} else {
return 0;
}
}
uint32_t flash_helper_qmlui_size(void) {
qmlui_check();
uint32_t flash_helper_code_size(int ind) {
qmlui_check(ind);
if (qmlui_check_done && qmlui_ok) {
uint8_t *qmlui_base = (uint8_t*)(flash_addr[QMLUI_BASE]);
int32_t ind = 0;
return buffer_get_uint32(qmlui_base, &ind);
if (code_checks[ind].check_done && code_checks[ind].ok) {
uint8_t *base = (uint8_t*)(flash_addr[code_sectors[ind]]);
int32_t index = 0;
return buffer_get_uint32(base, &index);
} else {
return 0;
}
}
uint16_t flash_helper_qmlui_flags(void) {
qmlui_check();
uint16_t flash_helper_code_flags(int ind) {
qmlui_check(ind);
if (qmlui_check_done && qmlui_ok) {
uint8_t *qmlui_base = (uint8_t*)(flash_addr[QMLUI_BASE]);
int32_t ind = 6;
return buffer_get_uint16(qmlui_base, &ind);
if (code_checks[ind].check_done && code_checks[ind].ok) {
uint8_t *base = (uint8_t*)(flash_addr[code_sectors[ind]]);
int32_t index = 6;
return buffer_get_uint16(base, &index);
} else {
return 0;
}
@ -431,22 +438,22 @@ static uint16_t write_data(uint32_t base, uint8_t *data, uint32_t len) {
return FLASH_COMPLETE;
}
static void qmlui_check(void) {
if (qmlui_check_done) {
static void qmlui_check(int ind) {
if (code_checks[ind].check_done) {
return;
}
uint8_t *qmlui_base = (uint8_t*)(flash_addr[QMLUI_BASE]);
int32_t ind = 0;
uint32_t qmlui_len = buffer_get_uint32(qmlui_base, &ind);
uint16_t qmlui_crc = buffer_get_uint16(qmlui_base, &ind);
uint8_t *base = (uint8_t*)(flash_addr[code_sectors[ind]]);
int32_t index = 0;
uint32_t qmlui_len = buffer_get_uint32(base, &index);
uint16_t qmlui_crc = buffer_get_uint16(base, &index);
if (qmlui_len <= QMLUI_MAX_SIZE) {
uint16_t crc_calc = crc16(qmlui_base + ind, qmlui_len + 2); // CRC includes the 2 byte flags
qmlui_ok = crc_calc == qmlui_crc;
uint16_t crc_calc = crc16(base + index, qmlui_len + 2); // CRC includes the 2 byte flags
code_checks[ind].ok = crc_calc == qmlui_crc;
} else {
qmlui_ok = false;
code_checks[ind].ok = false;
}
qmlui_check_done = true;
code_checks[ind].check_done = true;
}

View File

@ -22,16 +22,19 @@
#include "conf_general.h"
#define CODE_IND_QML 0
#define CODE_IND_LISP 1
// Functions
uint16_t flash_helper_erase_new_app(uint32_t new_app_size);
uint16_t flash_helper_erase_bootloader(void);
uint16_t flash_helper_write_new_app_data(uint32_t offset, uint8_t *data, uint32_t len);
uint16_t flash_helper_erase_qmlui(void);
uint16_t flash_helper_write_qmlui(uint32_t offset, uint8_t *data, uint32_t len);
uint8_t *flash_helper_qmlui_data(void);
uint32_t flash_helper_qmlui_size(void);
uint16_t flash_helper_qmlui_flags(void);
uint16_t flash_helper_erase_code(int ind);
uint16_t flash_helper_write_code(int ind, uint32_t offset, uint8_t *data, uint32_t len);
uint8_t* flash_helper_code_data(int ind);
uint32_t flash_helper_code_size(int ind);
uint16_t flash_helper_code_flags(int ind);
void flash_helper_jump_to_bootloader(void);
uint8_t* flash_helper_get_sector_address(uint32_t fsector);

View File

@ -26,8 +26,8 @@
MEMORY
{
flash : org = 0x08000000, len = 16k
flash2 : org = 0x0800C000, len = 393216 - 16 /* NEW_APP_MAX_SIZE - CRC_INFO */
crcinfo : org = 0x0805FFF0, len = 8 /* CRC info */
flash2 : org = 0x0800C000, len = 524288 - 16 /* NEW_APP_MAX_SIZE - CRC_INFO */
crcinfo : org = 0x0807FFF0, len = 8 /* CRC info */
ram0 : org = 0x20000000, len = 128k /* SRAM1 + SRAM2 */
ram1 : org = 0x20000000, len = 112k /* SRAM1 */
ram2 : org = 0x2001C000, len = 16k /* SRAM2 */
@ -146,7 +146,7 @@ SECTIONS
_etext = .;
_textdata = _etext;
_crcinfo_start_address = 0x0805FFF0;
_crcinfo_start_address = 0x0807FFF0;
.crcinfo _crcinfo_start_address :
{

View File

@ -33,12 +33,12 @@
#include "lispbm.h"
#define HEAP_SIZE 1024
#define LISP_MEM_SIZE MEMORY_SIZE_4K
#define LISP_MEM_BITMAP_SIZE MEMORY_BITMAP_SIZE_4K
#define LISP_MEM_SIZE MEMORY_SIZE_8K
#define LISP_MEM_BITMAP_SIZE MEMORY_BITMAP_SIZE_8K
__attribute__((section(".ram4"))) static cons_t heap[HEAP_SIZE] __attribute__ ((aligned (8)));
__attribute__((section(".ram4"))) static uint32_t memory_array[LISP_MEM_SIZE];
__attribute__((section(".ram4"))) static uint32_t bitmap_array[LISP_MEM_BITMAP_SIZE];
static uint32_t memory_array[LISP_MEM_SIZE];
static uint32_t bitmap_array[LISP_MEM_BITMAP_SIZE];
static thread_t *eval_tp = 0;
static THD_WORKING_AREA(eval_thread_wa, 2048);
@ -64,7 +64,7 @@ static void terminal_start(int argc, const char **argv) {
(void)argc;
(void)argv;
char *code = (char*)(0x08060000);
char *code = (char*)(0x080A0000);
if (!lisp_thd_running) {
lispbm_init(heap, HEAP_SIZE, memory_array, LISP_MEM_SIZE, bitmap_array, LISP_MEM_BITMAP_SIZE);