- fixed endianness for header data

- no endianness conversion for input data

git-svn-id: http://moon:8086/svn/mips@50 a8ebac50-d88d-4704-bea3-6648445a41b3
This commit is contained in:
2015-06-14 07:47:29 +00:00
parent 55b1322b77
commit 239f2b0a4a
+57 -5
View File
@@ -11,8 +11,51 @@
#define FLASH_BASE_MEM 0x00000000
#endif
#define MAGIC_EB 0x4A464931 // "JFI1" in big-endian;
#define MAGIC_EL 0x3149464A // "JFI1" in little-endian;
#define MAGIC 0x4A464931 // "JFI1" in big-endian;
uint8_t _g_bytes[4] = {0x12, 0x34, 0x56, 0x78};
uint8_t _g_bytes2[4] = {0};
int IsEndianBig(void)
{
int i, result;
uint8_t *pBuf8;
uint16_t *pBuf16;
uint32_t *pBuf32;
uint16_t halve;
uint32_t word;
halve = 0x1234;
word = 0x12345678;
result = -1;
for (i=0; i < 4; i++)
_g_bytes2[i] = _g_bytes[i];
pBuf8 = (uint8_t*)&word;
if (((*pBuf8+0) == 0x12) && (*(pBuf8+1) == 0x34) && (*(pBuf8+2) == 0x56) && (*(pBuf8+3) == 0x78))
{
pBuf8 = (uint8_t*)&halve;
if (((*pBuf8+0) == 0x12) && (*(pBuf8+1) == 0x34))
{
result = 1;
}
}
pBuf8 = (uint8_t*)&word;
if (((*pBuf8+0) == 0x78) && (*(pBuf8+1) == 0x56) && (*(pBuf8+2) == 0x34) && (*(pBuf8+3) == 0x12))
{
pBuf8 = (uint8_t*)&halve;
if (((*pBuf8+0) == 0x34) && (*(pBuf8+1) == 0x12))
{
result = 0;
}
}
return result;
}
uint32_t conv_endian32(uint32_t src)
{
@@ -108,7 +151,8 @@ int main(int argc, char *argv[])
return 1;
}
img_hdr.magic = MAGIC_EL;
img_hdr.magic = MAGIC;
img_hdr.target_addr = SDRAM_BASE;
img_hdr.img_size = filesize;
img_hdr.img_offset = FLASH_BASE_MEM + sizeof(flash_img_hdr_t);
@@ -118,10 +162,18 @@ int main(int argc, char *argv[])
{
if ((argv[2][0] == '-') && (toupper(argv[2][1]) == 'E') && (toupper(argv[2][2]) == 'B'))
{
img_hdr.magic = MAGIC_EB;
if (0 == IsEndianBig())
{
img_hdr.magic = conv_endian32(MAGIC);
img_hdr.target_addr = conv_endian32(SDRAM_BASE);
img_hdr.img_size = conv_endian32(filesize);
img_hdr.img_offset = conv_endian32(FLASH_BASE_MEM + sizeof(flash_img_hdr_t));
img_hdr.hdr_next = conv_endian32(FLASH_BASE_MEM);
}
pBuf32 = (uint32_t*)pBuf;
for (i=0; i < filesize/4; i ++)
pBuf32[i] = conv_endian32(pBuf32[i]);
pBuf32[i] = pBuf32[i]; // don't convert data
}
}
fwrite(&img_hdr, sizeof(flash_img_hdr_t), 1, pFile);