- no memset and strcpy in gdb_stub

- boattloader : refactored, size optimization, nostartup, nostdlib, nodefaultlibs

git-svn-id: http://moon:8086/svn/mips@119 a8ebac50-d88d-4704-bea3-6648445a41b3
This commit is contained in:
2017-01-22 13:51:31 +00:00
parent 793df682b1
commit e86064fd65
6 changed files with 69 additions and 385 deletions
+3 -137
View File
@@ -1,5 +1,6 @@
#include <board.h>
#include "libsys.h"
#include "srec.h"
#define MAGIC_EB 0x4A464931 // "JFI1" in big-endian;
#define MAGIC_EL 0x3149464A // "JFI1" in little-endian;
@@ -16,112 +17,6 @@ typedef struct _sflash_img_hdr_t
} flash_img_hdr_t;
typedef struct _ssrec_t
{
uint32_t addr;
uint32_t size;
uint32_t type;
uint8_t *data;
} srec_t;
enum srec_type
{
srec_err, srec_sob, srec_data, srec_rec, srec_eob
};
uint8_t h2i(uint8_t *c)
{
int i;
uint8_t t, b = 0;
for (i=0; i < 2; i++)
{
t = c[i];
if (t >= 'A')
t = t - 'A' + 10;
else
t -= '0';
b = (b << 4) | t;
}
return b;
}
int decode_srec(srec_t *pRec, uint8_t *pBuf, int buflen)
{
uint8_t chksum, byte;
int alen, i;
if (!buflen)
return srec_err;
pRec->type = srec_rec;
alen = 0;
if ((pBuf[1] > '0') && (pBuf[1] < '4'))
{
alen = pBuf[1] - '0' + 1;
pRec->type = srec_data;
}
else if ((pBuf[1] >= '7') && (pBuf[1] <= '9'))
{
alen = 11 - (pBuf[1] - '0');
pRec->type = srec_eob;
}
else if (pBuf[1] == '0')
{
alen = 2;
pRec->type = srec_sob;
}
byte = h2i(&pBuf[2]);
pRec->size = byte;
chksum = byte;
pRec->addr = 0;
for (i=0; i < alen; i++)
{
byte = h2i(&pBuf[4+2*i]);
pRec->addr = pRec->addr << 8 | byte;
chksum += byte;
}
pRec->size -= (alen+1);
pRec->data = (uint8_t*) &pBuf[4 + 2*alen];
for (i=0; i < (int)pRec->size; i++)
{
byte = h2i(&pRec->data[2*i]);
pRec->data[i] = byte;
chksum += byte;
}
chksum = ~chksum;
byte = h2i(&pRec->data[2*i]);
if (chksum != byte)
return 0;
return pRec->type;
}
int srec_getline(uint8_t *pLine)
{
char c;
int i = 0;
do
{
c = readchar();
} while ((c != 's') && (c != 'S'));
while(((c != 0x0D) && (c != 0x0A)))
{
pLine[i++] = c;
c = readchar();
};
return i;
}
void Jump_to(void *pEntry)
{
__asm
@@ -172,32 +67,6 @@ void Exec_at(void *pEntry)
);
}
void PrintCPUinfo(void)
{
int result, rev_id;
char *cpu_type_str[7] = {"invalid", "R2000", "R3000", "R6000", "R4000", "reserved", "R6000A"};
// Print Revision
result = CP0_PRID_read();
rev_id = (result >> 8) & 0xFF;
sputs("CPU type: ");
if ((rev_id > 0) && (rev_id < 0x07))
{
sputs(cpu_type_str[rev_id]);
sputs(" Rev.");
rev_id = result & 0xFF;
print_byte((char)rev_id);
}
else
sputs("Unknown");
sputs("\n");
// Print Status register
sputs("Status : ");print_word(CP0_SR_read());sputs("\n");
}
#define MAX_IMG_SIZE (1024*1024) // bytes
int main(int argc, char *argv[])
@@ -215,8 +84,7 @@ int main(int argc, char *argv[])
volatile uint32_t *pSdram32 = (uint32_t*)SDRAM_BASE;
sputs("\nMIPS bootloader\n");
PrintCPUinfo();
// ----------------------------------------------------------
sputs("Loading image from flash at ");print_word((int)pFlashMem);sputs("\n");
img_hdr = *((flash_img_hdr_t*)pFlashMem);
@@ -257,8 +125,6 @@ int main(int argc, char *argv[])
Exec_at((void*)pSdram32);
// ----------------------------------------------------------
sputs("\n\n");
PrintCPUinfo();
sputs("Booting from UART..");
while(1)
@@ -267,7 +133,7 @@ int main(int argc, char *argv[])
while(1)
{
result = srec_getline(buf);
srec_state = decode_srec(&srec, buf, result);
srec_state = srec_decode(&srec, buf, result);
switch (srec_state)
{
case srec_data: