From 0c06127499d0f0d13dcc1958f84d446f56a77fec Mon Sep 17 00:00:00 2001 From: Jens Ahrensfeld Date: Mon, 22 Nov 2021 11:12:23 +0000 Subject: [PATCH] [Bootloader] - cleaned up - added srec_init() git-svn-id: http://moon:8086/svn/mips@178 a8ebac50-d88d-4704-bea3-6648445a41b3 --- src/bootloader/bootloader_with_flash.c | 21 +++++++++++---------- src/bootloader/srec.c | 5 +++++ src/bootloader/srec.h | 1 + 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/src/bootloader/bootloader_with_flash.c b/src/bootloader/bootloader_with_flash.c index 623e61a..0ede29e 100644 --- a/src/bootloader/bootloader_with_flash.c +++ b/src/bootloader/bootloader_with_flash.c @@ -118,7 +118,7 @@ int main(int argc, char *argv[]) uint8_t srec_buf[SREC_BUFSIZE]; srec_t srec; int srec_state; - uint32_t haddr = 0, result; + uint32_t haddr = 0; flash_t flash; flash_img_hdr_t img_hdr = {0}; flash_img_hdr_t *pImg_hdr; @@ -126,14 +126,13 @@ int main(int argc, char *argv[]) volatile uint32_t *pGPIO_DATA = (uint32_t*)SYS_GPIO_0_DATA; volatile uint32_t *pGPIO_DIR = (uint32_t*)SYS_GPIO_0_DIR; - volatile uint32_t *pFlashIO = (uint32_t*)FLASH_BASE_IO; // Flash in uncached area uint32_t flash_offset; *pGPIO_DIR = GPIO_0_DFLT_DIR; *pGPIO_DATA = GPIO_0_DFLT_DATA; block_sel = 0x7F & (uint32_t)((*pGPIO_DATA >> GPIO_0_ALIGN_DIP) & GPIO_0_MASK_DIP); - sputs("\n\nMIPS bootloader 2.01\n"); + sputs("\n\nMIPS bootloader 2.02\n"); PrintCPUinfo(); // ---------------------------------------------------------- @@ -146,10 +145,9 @@ int main(int argc, char *argv[]) // Get flash offset by value of DIP-switch flash_offset = flash_get_offset_by_blocknum(&flash, block_sel); - pFlashIO = (uint32_t*)(SYS_FLASH_IO + flash_offset); - if (!(((*pGPIO_DATA >> GPIO_0_ALIGN_BTN) & GPIO_0_MASK_BTN) & 2)) { + volatile uint32_t *pFlashIO = (uint32_t*)(SYS_FLASH_IO + flash_offset); // Flash in uncached area pImg_hdr = (flash_img_hdr_t*)pFlashIO; if ((pImg_hdr->magic != MAGIC_EL) && (pImg_hdr->magic != MAGIC_EB)) { @@ -175,15 +173,16 @@ int main(int argc, char *argv[]) while(1) { + srec_init(); sputs("."); while(1) { - result = srec_getline(srec_buf); - srec_state = srec_decode(&srec, srec_buf, result); + uint32_t size = srec_getline(srec_buf); + srec_state = srec_decode(&srec, srec_buf, size); + uint32_t result = -1; switch (srec_state) { case srec_data: - result = -1; if ((srec.addr + srec.size) > (SDRAM_BASE + MAX_IMG_SIZE)) { sputs("O"); @@ -196,7 +195,6 @@ int main(int argc, char *argv[]) haddr = srec.addr + srec.size; } result = 0; - break; case srec_eob: @@ -246,11 +244,14 @@ int main(int argc, char *argv[]) // Jump to reset vector Jump_to((void*)0xBFC00000); + result = 0; break; + case srec_sob: + break; + default: sputs("E"); - result = -1; break; } if (IS_ERROR(result)) diff --git a/src/bootloader/srec.c b/src/bootloader/srec.c index 9ddd58e..28862c1 100644 --- a/src/bootloader/srec.c +++ b/src/bootloader/srec.c @@ -23,6 +23,11 @@ uint8_t h2i(uint8_t *c) return b; } +void srec_init() +{ + +} + int srec_decode(srec_t *pRec, uint8_t *pBuf, int buflen) { uint8_t chksum, byte; diff --git a/src/bootloader/srec.h b/src/bootloader/srec.h index b8032ea..5f08f99 100644 --- a/src/bootloader/srec.h +++ b/src/bootloader/srec.h @@ -34,6 +34,7 @@ enum srec_type extern "C" { #endif +void srec_init(); int srec_decode(srec_t *pRec, uint8_t *pBuf, int buflen); int srec_getline(uint8_t *pLine);