yeaaah
This commit is contained in:
parent
02cc22e6ae
commit
a7f16616f0
50
bootloader.c
50
bootloader.c
|
@ -31,7 +31,7 @@ char* argvs[3][10];
|
||||||
|
|
||||||
cmd_t cmd;
|
cmd_t cmd;
|
||||||
|
|
||||||
uint32_t* size_store = (uint32_t*) 0x3400;
|
uint32_t* size_store = (uint32_t*) 0x3100;
|
||||||
crc_t* crc_store = (crc_t*) 0x3000;
|
crc_t* crc_store = (crc_t*) 0x3000;
|
||||||
|
|
||||||
uint32_t offset, total_size, offset_pointer;
|
uint32_t offset, total_size, offset_pointer;
|
||||||
|
@ -49,6 +49,7 @@ int is_code_valid(){
|
||||||
crc_t expected_crc = *crc_store;
|
crc_t expected_crc = *crc_store;
|
||||||
size_t application_size = *size_store;
|
size_t application_size = *size_store;
|
||||||
crc_t real_crc = crc_init();
|
crc_t real_crc = crc_init();
|
||||||
|
if(application_size > MAX_PROG_SIZE) return 0;
|
||||||
real_crc = crc_update(real_crc, (void*)APP_OFFSET, application_size);
|
real_crc = crc_update(real_crc, (void*)APP_OFFSET, application_size);
|
||||||
real_crc = crc_finalize(real_crc);
|
real_crc = crc_finalize(real_crc);
|
||||||
error_code is_error = uart_commands_check(real_crc, expected_crc);
|
error_code is_error = uart_commands_check(real_crc, expected_crc);
|
||||||
|
@ -58,6 +59,13 @@ int is_code_valid(){
|
||||||
else return 0;
|
else return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int is_b_pressed(){
|
||||||
|
int tmp = (LPC_GPIO0->FIOPIN)>>19;
|
||||||
|
int tmp2 = tmp & 1;
|
||||||
|
if(tmp2 == 0) return 1;
|
||||||
|
else return 0;
|
||||||
|
}
|
||||||
|
|
||||||
void write_app_info(crc_t* checksum, size_t* size){
|
void write_app_info(crc_t* checksum, size_t* size){
|
||||||
iap_prepare_sectors(&status, addr_to_sector(0x3000), addr_to_sector(0x3fff));
|
iap_prepare_sectors(&status, addr_to_sector(0x3000), addr_to_sector(0x3fff));
|
||||||
if(status != ok){
|
if(status != ok){
|
||||||
|
@ -67,26 +75,20 @@ void write_app_info(crc_t* checksum, size_t* size){
|
||||||
if(status != ok){
|
if(status != ok){
|
||||||
uart_send_err();
|
uart_send_err();
|
||||||
}
|
}
|
||||||
iap_prepare_sectors(&status, addr_to_sector(0x3000), addr_to_sector(0x3fff));
|
iap_copy_to_flash(&status, (long unsigned int *)crc_store, (long unsigned int*)checksum, 0x100);
|
||||||
if(status != ok){
|
//0x100 a result of trial and error I initially wanted to put 0x4 but noooo it doesn't work
|
||||||
uart_send_err();
|
iap_copy_to_flash(&status, (long unsigned int *)size_store, (long unsigned int*)size, 0x100);
|
||||||
}
|
|
||||||
iap_copy_to_flash(&status, (long unsigned int *)crc_store, (long unsigned int*)checksum, 0x0400);
|
|
||||||
iap_copy_to_flash(&status, (long unsigned int *)size_store, (long unsigned int*)size, 0x0400);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(void) {
|
void launch_program(){
|
||||||
cmd.argv = (char**)argvs;
|
|
||||||
//verify b is pressed
|
|
||||||
//checksum is correct (
|
|
||||||
//bootloader_init();
|
|
||||||
uart_init(115200);
|
|
||||||
if(is_code_valid()){
|
|
||||||
SCB->VTOR = APP_OFFSET;
|
SCB->VTOR = APP_OFFSET;
|
||||||
__asm("ldr r0,=0x4000");
|
__asm("ldr r0,=0x4000");
|
||||||
__asm("ldr sp,[r0]");
|
__asm("ldr sp,[r0]");
|
||||||
__asm("ldr pc,[r0,#4]");
|
__asm("ldr pc,[r0,#4]");
|
||||||
}else{
|
}
|
||||||
|
|
||||||
|
void manage_bootloader(){
|
||||||
|
cmd.argv = (char**)argvs;
|
||||||
while(1){
|
while(1){
|
||||||
uart_receive_command(buff);
|
uart_receive_command(buff);
|
||||||
uart_parse_command(buff, &cmd);
|
uart_parse_command(buff, &cmd);
|
||||||
|
@ -114,13 +116,31 @@ int main(void) {
|
||||||
error_code is_error = uart_commands_check(crc_prog, crc_data);
|
error_code is_error = uart_commands_check(crc_prog, crc_data);
|
||||||
if(is_error == ok){
|
if(is_error == ok){
|
||||||
uart_send_ok();
|
uart_send_ok();
|
||||||
|
break;
|
||||||
}else{
|
}else{
|
||||||
uart_send_err();
|
uart_send_err();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(void) {
|
||||||
|
//verify b is pressed
|
||||||
|
//checksum is correct (
|
||||||
|
//bootloader_init();
|
||||||
|
uart_init(115200);
|
||||||
|
LPC_GPIO0->FIODIR &=~(1<<19);
|
||||||
|
if(is_b_pressed() == 0){
|
||||||
|
if(is_code_valid()){
|
||||||
|
launch_program();
|
||||||
|
}else{
|
||||||
|
manage_bootloader();
|
||||||
}
|
}
|
||||||
|
}else{
|
||||||
|
manage_bootloader();
|
||||||
|
}
|
||||||
|
launch_program();
|
||||||
while(1);
|
while(1);
|
||||||
return 0 ;
|
return 0 ;
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,9 @@
|
||||||
#include "crc.h"
|
#include "crc.h"
|
||||||
|
|
||||||
#define DELIMIERS ","
|
#define DELIMIERS ","
|
||||||
|
#define LPC1769_FLASH_SIZE 0x80000
|
||||||
#define APP_OFFSET 0x4000
|
#define APP_OFFSET 0x4000
|
||||||
|
#define MAX_PROG_SIZE (LPC1769_FLASH_SIZE - APP_OFFSET)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue