oh well
This commit is contained in:
parent
a695df73d2
commit
3768522850
|
@ -26,9 +26,11 @@ char errr[5] = "ERR\r\n";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
char* argvs[3][10];
|
||||||
|
|
||||||
cmd_t cmd;
|
cmd_t cmd;
|
||||||
|
|
||||||
|
|
||||||
uint32_t offset, total_size, offset_pointer;
|
uint32_t offset, total_size, offset_pointer;
|
||||||
|
|
||||||
crc_t crc_prog, crc_data;
|
crc_t crc_prog, crc_data;
|
||||||
|
@ -41,6 +43,7 @@ crc_t crc_prog, crc_data;
|
||||||
char buff[256];
|
char buff[256];
|
||||||
|
|
||||||
int main(void) {
|
int main(void) {
|
||||||
|
cmd.argv = argvs;
|
||||||
uart_init(115200);
|
uart_init(115200);
|
||||||
while(1){
|
while(1){
|
||||||
uart_receive_command(buff);
|
uart_receive_command(buff);
|
||||||
|
@ -55,7 +58,7 @@ int main(void) {
|
||||||
crc_prog = uart_string_to_int(cmd.argv[3]);
|
crc_prog = uart_string_to_int(cmd.argv[3]);
|
||||||
total_size = uart_string_to_int(cmd.argv[2]);
|
total_size = uart_string_to_int(cmd.argv[2]);
|
||||||
offset = uart_string_to_int(cmd.argv[1]);
|
offset = uart_string_to_int(cmd.argv[1]);
|
||||||
crc_data = uart_commands_prog();
|
crc_data = uart_commands_prog(&status, total_size);
|
||||||
offset_pointer = offset;
|
offset_pointer = offset;
|
||||||
|
|
||||||
}else if(strcmp("DATA", cmd.argv[0])==0){
|
}else if(strcmp("DATA", cmd.argv[0])==0){
|
||||||
|
|
2
iap.c
2
iap.c
|
@ -94,7 +94,7 @@ uint32_t iap_read_part_id(error_code* status){
|
||||||
void iap_copy_to_flash(error_code* status, int dst_flash, uint32_t* src_ram, int num_bytes){
|
void iap_copy_to_flash(error_code* status, int dst_flash, uint32_t* src_ram, int num_bytes){
|
||||||
//iap_prepare_sectors(status, dst_flash, dst_flash+num_bytes);
|
//iap_prepare_sectors(status, dst_flash, dst_flash+num_bytes);
|
||||||
//iap_erase_sectors(status, dst_flash, dst_flash+num_bytes);
|
//iap_erase_sectors(status, dst_flash, dst_flash+num_bytes);
|
||||||
//iap_prepare_sectors(status, dst_flash, dst_flash+num_bytes);
|
iap_prepare_sectors(status, dst_flash, dst_flash+num_bytes);
|
||||||
command[0] = 51;
|
command[0] = 51;
|
||||||
command[1] = dst_flash;
|
command[1] = dst_flash;
|
||||||
command[2] = src_ram;
|
command[2] = src_ram;
|
||||||
|
|
|
@ -22,13 +22,16 @@ void uart_commands_getserial(error_code* status){
|
||||||
iap_read_serial(status, res);
|
iap_read_serial(status, res);
|
||||||
sprintf(hex, "0x%x%x%x%x\r\n", res[0], res[1], res[2], res[3]);
|
sprintf(hex, "0x%x%x%x%x\r\n", res[0], res[1], res[2], res[3]);
|
||||||
if(*status == 0){
|
if(*status == 0){
|
||||||
uart_send(OK, 4);
|
uart_send_ok();
|
||||||
uart_send(hex, 35);
|
uart_send(hex, 35);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
crc_t uart_commands_prog(void){
|
crc_t uart_commands_prog(error_code* status, int size){
|
||||||
uart_send(OK, 5);
|
iap_prepare_sectors(status, APP_OFFSET, APP_OFFSET+size/4095+5);
|
||||||
|
iap_erase_sectors(status, APP_OFFSET, APP_OFFSET+size/4095+5);
|
||||||
|
iap_prepare_sectors(status, APP_OFFSET, APP_OFFSET+size/4095+5);
|
||||||
|
uart_send_ok();
|
||||||
return crc_init();
|
return crc_init();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,49 +40,50 @@ error_code uart_commands_data(error_code* status, int size, crc_t* checksum_glob
|
||||||
crc_t checksum_tmp = crc_init();
|
crc_t checksum_tmp = crc_init();
|
||||||
checksum_tmp = crc_update(checksum_tmp, data, size);
|
checksum_tmp = crc_update(checksum_tmp, data, size);
|
||||||
checksum_tmp = crc_finalize(checksum_tmp);
|
checksum_tmp = crc_finalize(checksum_tmp);
|
||||||
|
int offset_counter = offset;
|
||||||
if(checksum_loc == checksum_tmp){
|
if(checksum_loc == checksum_tmp){
|
||||||
int tmp = size;
|
int tmp = size;
|
||||||
iap_prepare_sectors(status, APP_OFFSET, APP_OFFSET+size/4095+1);
|
//iap_prepare_sectors(status, APP_OFFSET, APP_OFFSET+size/4095+1);
|
||||||
iap_erase_sectors(status, APP_OFFSET, APP_OFFSET+size/4095+1);
|
//iap_erase_sectors(status, APP_OFFSET, APP_OFFSET+size/4095+1);
|
||||||
iap_prepare_sectors(status, APP_OFFSET, APP_OFFSET+size/4095+1);
|
iap_prepare_sectors(status, APP_OFFSET, APP_OFFSET+size/4095+5);
|
||||||
*checksum_global = crc_update(*checksum_global, data, size);
|
*checksum_global = crc_update(*checksum_global, data, size);
|
||||||
while(tmp >= 4096){
|
while(tmp >= 4096){
|
||||||
iap_copy_to_flash(status, offset/0x1000, checksum_global, 4096);
|
iap_copy_to_flash(status, offset, checksum_global, 4096);
|
||||||
if(*status != ok){
|
if(*status != ok){
|
||||||
uart_send(ERR, 6);
|
uart_send_err();
|
||||||
return *status;
|
return *status;
|
||||||
}
|
}
|
||||||
tmp = tmp - 4096;
|
tmp = tmp - 4096;
|
||||||
}
|
}
|
||||||
while(tmp >= 1024){
|
while(tmp >= 1024){
|
||||||
//iap_copy_to_flash(status, offset/0x1000, checksum_global, 1024);
|
|
||||||
iap_copy_to_flash(status, offset, checksum_global, 1024);
|
iap_copy_to_flash(status, offset, checksum_global, 1024);
|
||||||
if(*status != ok){
|
if(*status != ok){
|
||||||
uart_send(ERR, 6);
|
uart_send_err();
|
||||||
return *status;
|
return *status;
|
||||||
}
|
}
|
||||||
tmp = tmp - 1024;
|
tmp = tmp - 1024;
|
||||||
|
offset_counter += 1024;
|
||||||
}
|
}
|
||||||
while(tmp >= 512){
|
while(tmp >= 512){
|
||||||
iap_copy_to_flash(status, offset/0x1000, checksum_global, 512);
|
iap_copy_to_flash(status, offset, checksum_global, 512);
|
||||||
if(*status != ok){
|
if(*status != ok){
|
||||||
uart_send(ERR, 6);
|
uart_send_err();
|
||||||
return *status;
|
return *status;
|
||||||
}
|
}
|
||||||
tmp = tmp - 512;
|
tmp = tmp - 512;
|
||||||
}
|
}
|
||||||
while(tmp >= 256){
|
while(tmp >= 256){
|
||||||
iap_copy_to_flash(status, offset/0x1000, checksum_global, 256);
|
iap_copy_to_flash(status, offset, checksum_global, 256);
|
||||||
if(*status != ok){
|
if(*status != ok){
|
||||||
uart_send(ERR, 6);
|
uart_send_err();
|
||||||
return *status;
|
return *status;
|
||||||
}
|
}
|
||||||
tmp = tmp - 256;
|
tmp = tmp - 256;
|
||||||
}
|
}
|
||||||
uart_send(OK, 4);
|
uart_send_ok();
|
||||||
return ok;
|
return ok;
|
||||||
}else{
|
}else{
|
||||||
uart_send(ERR, 6);
|
uart_send_err();
|
||||||
return local_checksum;
|
return local_checksum;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -94,7 +98,9 @@ error_code uart_commands_check(crc_t crc_received, crc_t crc_calculated){
|
||||||
int uart_parse_command(char *user_input, cmd_t *cmd) {
|
int uart_parse_command(char *user_input, cmd_t *cmd) {
|
||||||
|
|
||||||
//Initialize a simple command (empty, simple, foreground)
|
//Initialize a simple command (empty, simple, foreground)
|
||||||
cmd->argv = NULL;
|
cmd->argv[0] = NULL;
|
||||||
|
cmd->argv[1] = NULL;
|
||||||
|
cmd->argv[2] = NULL;
|
||||||
cmd->argc = -1;
|
cmd->argc = -1;
|
||||||
|
|
||||||
//Separate string in different token (i.e. command name + params + &)
|
//Separate string in different token (i.e. command name + params + &)
|
||||||
|
@ -102,10 +108,6 @@ int uart_parse_command(char *user_input, cmd_t *cmd) {
|
||||||
//A new element will be added
|
//A new element will be added
|
||||||
cmd->argc += 1;
|
cmd->argc += 1;
|
||||||
|
|
||||||
//Allocate a new pointer on char for next argv element
|
|
||||||
if((cmd->argv = realloc(cmd->argv, (cmd->argc+1)*sizeof(char*))) == NULL)
|
|
||||||
perror("uart_parse_command::realloc");
|
|
||||||
|
|
||||||
//Get the adress of the next token (could be NULL to indicate end of argv)
|
//Get the adress of the next token (could be NULL to indicate end of argv)
|
||||||
cmd->argv[cmd->argc] = strtok(user_input, DELIMIERS);
|
cmd->argv[cmd->argc] = strtok(user_input, DELIMIERS);
|
||||||
user_input = NULL; //Useless to execute it each time but easier than having two different strtok calls
|
user_input = NULL; //Useless to execute it each time but easier than having two different strtok calls
|
||||||
|
@ -121,3 +123,11 @@ uint32_t uart_string_to_int(const char *str) {
|
||||||
unsigned long long int hex = strtoull(str, &tmp, 16);
|
unsigned long long int hex = strtoull(str, &tmp, 16);
|
||||||
return hex;
|
return hex;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void uart_send_ok(){
|
||||||
|
uart_send(OK, 4);
|
||||||
|
}
|
||||||
|
|
||||||
|
void uart_send_err(){
|
||||||
|
uart_send(ERR, 6);
|
||||||
|
}
|
|
@ -22,7 +22,7 @@ void uart_commands_getid(error_code* status);
|
||||||
|
|
||||||
void uart_commands_getserial(error_code* status);
|
void uart_commands_getserial(error_code* status);
|
||||||
|
|
||||||
crc_t uart_commands_prog(void);
|
crc_t uart_commands_prog(error_code* status, int size);
|
||||||
|
|
||||||
error_code uart_commands_data(error_code* status, int size, crc_t* checksum_global, crc_t checksum_loc, int offset);
|
error_code uart_commands_data(error_code* status, int size, crc_t* checksum_global, crc_t checksum_loc, int offset);
|
||||||
|
|
||||||
|
@ -30,4 +30,8 @@ error_code uart_commands_check(crc_t crc_received, crc_t crc_calculated);
|
||||||
|
|
||||||
int uart_parse_command(char *user_input, cmd_t *cmd);
|
int uart_parse_command(char *user_input, cmd_t *cmd);
|
||||||
|
|
||||||
|
void uart_send_ok();
|
||||||
|
|
||||||
|
void uart_send_err();
|
||||||
|
|
||||||
uint32_t uart_string_to_int(const char* str);
|
uint32_t uart_string_to_int(const char* str);
|
||||||
|
|
Loading…
Reference in New Issue