From a92c134454a382cedd7f28c9ab04e21b4da3c8d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20Fr=C3=B6schle?= Date: Tue, 26 Feb 2013 15:39:36 +0000 Subject: [PATCH] made basflash.s19 more self-contained --- sources/basflash.c | 48 +++++++++++++++++++++++++++++++++++++--- sources/basflash_start.c | 2 +- sources/s19reader.c | 18 +++++++-------- 3 files changed, 55 insertions(+), 13 deletions(-) diff --git a/sources/basflash.c b/sources/basflash.c index 36cbc4f..21aaa0f 100644 --- a/sources/basflash.c +++ b/sources/basflash.c @@ -65,10 +65,52 @@ static const uint16_t cmd_program = 0xa0; static const uint16_t cmd_autoselect = 0x90; static const uint16_t cmd_read = 0xf0; -extern err_t simulate(); -extern err_t memcpy(); -extern err_t verify(); +/* + * this callback just does nothing besides returning OK. Meant to do a dry run over the file to check its integrity + */ +static err_t simulate() +{ + err_t ret = OK; + return ret; +} + +static err_t memcpy(uint8_t *dst, uint8_t *src, uint32_t length) +{ + uint8_t *end = src + length; + + do + { + *dst++ = *src++; + } while (src < end); + + return OK; +} + +static err_t flash(uint8_t *dst, uint8_t *src, uint32_t length) +{ + err_t ret = OK; + + /* TODO: do the actual flash */ + + return ret; +} + +/* + * this callback verifies the data against the S-record file contents after a write to destination + */ +static err_t verify(uint8_t *dst, uint8_t *src, uint32_t length) +{ + uint8_t *end = src + length; + + do + { + if (*src++ != *dst++) + return FAIL; + } while (src < end); + + return OK; +} /* * unlock a flash sector diff --git a/sources/basflash_start.c b/sources/basflash_start.c index 019ad40..2435583 100644 --- a/sources/basflash_start.c +++ b/sources/basflash_start.c @@ -21,6 +21,6 @@ void startup(void) __asm__ __volatile__("move.l sp,%0\n\t" : "=g"(oldstack) : :); __asm__ __volatile__("move.l %0,sp\n\t" : : "g"(stackptr) : ); basflash(); - __asm__ __volatile__("move.l %0,sp\n\t" : : "g"(oldstack) :); + __asm__ __volatile__("move.l %0,sp\n\t" : : "g"(oldstack) : "sp"); (void) stackptr; /* make compiler happy about unused variables */ } diff --git a/sources/s19reader.c b/sources/s19reader.c index 0489b36..1e7550f 100644 --- a/sources/s19reader.c +++ b/sources/s19reader.c @@ -59,7 +59,7 @@ /* * convert a single hex character into byte */ -uint8_t nibble_to_byte(uint8_t nibble) +static uint8_t nibble_to_byte(uint8_t nibble) { if ((nibble >= '0') && (nibble <= '9')) return nibble - '0'; @@ -73,7 +73,7 @@ uint8_t nibble_to_byte(uint8_t nibble) /* * convert two hex characters into byte */ -uint8_t hex_to_byte(uint8_t hex[2]) +static uint8_t hex_to_byte(uint8_t hex[2]) { return 16 * (nibble_to_byte(hex[0])) + (nibble_to_byte(hex[1])); } @@ -81,7 +81,7 @@ uint8_t hex_to_byte(uint8_t hex[2]) /* * convert four hex characters into a 16 bit word */ -uint16_t hex_to_word(uint8_t hex[4]) +static uint16_t hex_to_word(uint8_t hex[4]) { return 256 * hex_to_byte(&hex[0]) + hex_to_byte(&hex[2]); } @@ -89,7 +89,7 @@ uint16_t hex_to_word(uint8_t hex[4]) /* * convert eight hex characters into a 32 bit word */ -uint32_t hex_to_long(uint8_t hex[8]) +static uint32_t hex_to_long(uint8_t hex[8]) { return 65536 * hex_to_word(&hex[0]) + hex_to_word(&hex[4]); } @@ -99,7 +99,7 @@ uint32_t hex_to_long(uint8_t hex[8]) * * it consists of the one's complement of the byte sum of the data from the count field until the end */ -uint8_t checksum(uint8_t arr[]) +static uint8_t checksum(uint8_t arr[]) { int i; uint8_t checksum = SREC_COUNT(arr); @@ -301,14 +301,14 @@ err_t read_srecords(char *filename, void **start_address, uint32_t *actual_lengt /* * this callback just does nothing besides returning OK. Meant to do a dry run over the file to check its integrity */ -err_t simulate() +static err_t simulate() { err_t ret = OK; return ret; } -err_t memcpy(uint8_t *dst, uint8_t *src, uint32_t length) +static err_t memcpy(uint8_t *dst, uint8_t *src, uint32_t length) { uint8_t *end = src + length; @@ -320,7 +320,7 @@ err_t memcpy(uint8_t *dst, uint8_t *src, uint32_t length) return OK; } -err_t flash(uint8_t *dst, uint8_t *src, uint32_t length) +static err_t flash(uint8_t *dst, uint8_t *src, uint32_t length) { err_t ret = OK; @@ -332,7 +332,7 @@ err_t flash(uint8_t *dst, uint8_t *src, uint32_t length) /* * this callback verifies the data against the S-record file contents after a write to destination */ -err_t verify(uint8_t *dst, uint8_t *src, uint32_t length) +static err_t verify(uint8_t *dst, uint8_t *src, uint32_t length) { uint8_t *end = src + length;