Open Model Railroad Network (OpenMRN)
Loading...
Searching...
No Matches
ReflashBootloader.cxx
Go to the documentation of this file.
1
37
39
43extern const SegmentTable table[];
44
45extern "C" {
48{
51
52 for (unsigned i = 0; table[i].length; i++)
53 {
54 uint8_t *dst_address = table[i].dst_address;
55 const uint8_t *src_address = table[i].src_address;
56 uint8_t *const end_address = table[i].dst_address + table[i].length;
57 while (dst_address < end_address)
58 {
59 const void *page_start;
60 uint32_t page_length_bytes;
61 get_flash_page_info(dst_address, &page_start, &page_length_bytes);
62 raw_erase_flash_page(page_start);
63 uint32_t write_length = end_address - dst_address;
64 uint32_t max_length = ((const uint8_t*)page_start) + page_length_bytes - dst_address;
65 if (write_length > max_length)
66 {
67 write_length = max_length;
68 }
69 raw_write_flash(dst_address, src_address, write_length);
70 dst_address += write_length;
71 src_address += write_length;
72 }
73 }
74
76}
77}
void bootloader_reboot(void)
Callback from the bootloader when a reboot should be triggered.
void get_flash_page_info(const void *address, const void **page_start, uint32_t *page_length_bytes)
Callback from the bootloader to retrieve flash page information.
void bootloader_hw_init(void)
Callback from the bootloader to configure and start the TWAI hardware.
const SegmentTable table[]
The list of segments to copy from the reflash-bootloader program code to the flash space occupied by ...
void reflash_bootloader_entry()
This function needs to be called from reset_handler (instead of main etc.)
void raw_write_flash(const void *address, const void *data, uint32_t size_bytes)
Writes data to the flash.
void raw_erase_flash_page(const void *address)
Erases the flash page at a specific address.
void bootloader_hw_set_to_safe(void)
Initializes the hardware to a safe state of the outputs.
Declares that a given piece of data has to be copied from one place in memory to a place in flash.
const uint8_t * src_address
address where to read the golden data from
uint8_t * dst_address
address in the flash space where to write
uint32_t length
number of bytes to write