현재 STB 에서 사용하고 있는 2M, 4M, 8M FLASH 메모리에 대응하기 위해서 각각의 부트 프로그램과 HEX 파일을 만들 때 수정해야 것들을 정리했다.
수정되어야 할 것
일단 FLASH 용량이 달라지기 때문에, 부트 프로그램에서 erase 와 write 하는 주소와 사이즈가 수정되어야 한다. 또한 HEX 파일을 만들 때, .cfg 파일을 수정해주어야 한다.
먼저 부트 프로그램부터 살펴보기로 하겠다.
부트 프로그램
부트 프로그램에서 수정이 가해져야할 부분은 시리얼로부터 받은 HEX 파일을 FLASH 에 write 하는 루틴이다. 여기서는 각 FLASH 용량에 따라 수정되어야 할 부분을 간략하게 설명하도록 하겠다.
src/flash 아래에 bunner.c 와 flash.c 파일이 수정되어야 한다.
flash.c
우선 flash.c 파일이다.
2M FLASH
#define NUM_BLOCKS 35 // FLASH 블럭갯수와 크기 정의(데이터 시트 참조할 것) STFLASH_Block_t BlockData_s[NUM_BLOCKS] = { { 0x00010000, STFLASH_MAIN_BLOCK },/* 0 */ { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK },/*64k*/ { 0x00008000, STFLASH_MAIN_BLOCK },/* 32k*/ { 0x00002000, STFLASH_PARAMETER_BLOCK }, { 0x00002000, STFLASH_PARAMETER_BLOCK },/*8k*/ { 0x00004000, STFLASH_BOOT_BLOCK } }; /* 16k */ /*34*/ ... ... ST_ErrorCode_t FLASH_Initx() { InitParams.BaseAddress = (U32*)0x7fe00000;//STFLASH_BANK_0_BASE; FLASH 시작 주소 } ... ... BOOL EraseBlock(U32 block_count) { case 31: ... ... case 34: errCode = STFLASH_Erase( FLASHHnd, 0+(0x00010000*31)+0x8000+0x2000+0x2000, 0x00004000); // 기준이 되는 블럭 숫자 31 값을 유의할 것 break; } ... ... BOOL WriteBlock(U8* data, U32 wblock_count) { case 31: ... ... case 34: length = 16384; errCode = STFLASH_Write( FLASHHnd, 0+(0x00010000*31)+0x8000+0x2000+0x2000, data, length, &uWriteLen ); // 기준이 되는 블럭 숫자 31 값을 유의할 것 break; }
4M FLASH
#define NUM_BLOCKS 71 // FLASH 블럭갯수와 크기 정의(데이터 시트 참조할 것) STFLASH_Block_t BlockData_s[NUM_BLOCKS] = { { 0x00010000, STFLASH_MAIN_BLOCK },/* 0 */ { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00002000, STFLASH_PARAMETER_BLOCK },/*8k*/ { 0x00002000, STFLASH_PARAMETER_BLOCK },/*8k*/ { 0x00002000, STFLASH_PARAMETER_BLOCK },/*8k*/ { 0x00002000, STFLASH_PARAMETER_BLOCK },/*8k*/ { 0x00002000, STFLASH_PARAMETER_BLOCK },/*8k*/ { 0x00002000, STFLASH_PARAMETER_BLOCK },/*8k*/ { 0x00002000, STFLASH_PARAMETER_BLOCK },/*8k*/ { 0x00002000, STFLASH_BOOT_BLOCK } }; /* 16k */ /*34*/ ... ... ST_ErrorCode_t FLASH_Initx() { ... ... InitParams.BaseAddress = (U32*)0x7fc00000;//STFLASH_BANK_0_BASE; FLASH 시작 주소 ... ... } ... ... BOOL EraseBlock(U32 block_count) { case 63: ... ... case 70: errCode = STFLASH_Erase( FLASHHnd, 0+(0x00010000*63)+0x2000+0x2000+0x2000+0x2000+0x2000+0x2000+0x2000, 0x00002000); // 기준이 되는 블럭 숫자 63 값을 유의할 것 break; } ... ... BOOL WriteBlock(U8* data, U32 wblock_count) { case 63: ... ... case 70: length = 8192; errCode = STFLASH_Write( FLASHHnd, 0+(0x00010000*63)+0x2000+0x2000+0x2000+0x2000+0x2000+0x2000+0x2000, data, length, &uWriteLen ); // 기준이 되는 블럭 숫자 63 값을 유의할 것 break; }
8M FLASH
#define NUM_BLOCKS 135 // FLASH 블럭갯수와 크기 정의(데이터 시트 참조할 것) STFLASH_Block_t BlockData_s[NUM_BLOCKS] = { { 0x00010000, STFLASH_MAIN_BLOCK },/* 0 */ { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, /* 120 */ { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK }, { 0x00010000, STFLASH_MAIN_BLOCK },/*126*/ { 0x00002000, STFLASH_PARAMETER_BLOCK },/*8k*/ { 0x00002000, STFLASH_PARAMETER_BLOCK },/*8k*/ { 0x00002000, STFLASH_PARAMETER_BLOCK },/*8k*/ { 0x00002000, STFLASH_PARAMETER_BLOCK },/*8k*/ { 0x00002000, STFLASH_PARAMETER_BLOCK },/*8k*/ { 0x00002000, STFLASH_PARAMETER_BLOCK },/*8k*/ { 0x00002000, STFLASH_PARAMETER_BLOCK },/*8k*/ { 0x00002000, STFLASH_BOOT_BLOCK } }; /* 16k */ /*34*/ ... ... ST_ErrorCode_t FLASH_Initx() { ... ... InitParams.BaseAddress = (U32*)0x7f800000;//STFLASH_BANK_0_BASE; FLASH 시작 주소 ... ... } ... ... BOOL EraseBlock(U32 block_count) { case 127: ... ... case 134: errCode = STFLASH_Erase( FLASHHnd, 0+(0x00010000*127)+0x2000+0x2000+0x2000+0x2000+0x2000+0x2000+0x2000, 0x00002000); // 기준이 되는 블럭 숫자 134 값을 유의할 것 break; } ... ... BOOL WriteBlock(U8* data, U32 wblock_count) { case 127: ... ... case 134: length = 8192; errCode = STFLASH_Write( FLASHHnd, 0+(0x00010000*127)+0x2000+0x2000+0x2000+0x2000+0x2000+0x2000+0x2000, data, length, &uWriteLen ); // 기준이 되는 블럭 숫자 134 값을 유의할 것 break; }
bunner.c
이번에는 bunner.c 파일을 살펴보겠다.
2M FLASH
void Down_Bun(void) { ST_ErrorCode_t uerr; U8 cbuf[1] = 0; U8 bbuf [65540]; //U8 ebuf[16385]; U8 ebuf[65540]; U8 fbuf[16]; U8 check = 0; U32 array = 0, barray = 0; U32 read_len = 0; U32 xcount = 0; U32 ycount = 0; U32 zcount = 0; cbuf[0] = 'S'; fbuf[0] = 'F'; fbuf[1] = 'I'; fbuf[2] = 'N'; fbuf[3] = 'I'; fbuf[4] = 'S'; fbuf[5] = 'H'; fbuf[6] = 'E'; fbuf[7] = 'D'; fbuf[8] = '_'; fbuf[9] = 'B'; fbuf[10] = 'U'; fbuf[11] = 'R'; fbuf[12] = 'N'; fbuf[13] = 'N'; fbuf[14] = 'E'; fbuf[15] = 'R'; for(array=0;array<65540;array++) { bbuf[array]= 0xff; } for(barray=0;barray<65540;barray++) { ebuf[barray] = 0xff; } for(check=0; check<35; check++) // 총 블럭의 갯수(35)에 유의할 것 { STUART_Flush(Dev_Uart_Handle); uerr = STUARTremoconReadx(Dev_Uart_Handle, bbuf, &read_len); if(uerr != ST_NO_ERROR)printf("\nUART READ FAIL\n"); if(bbuf[65535] == 0xcd && bbuf[65536] == 0x7a) // LAST BLOCK { for(xcount=0; xcount < 65536; xcount++) { if(bbuf[xcount] == 0xcd && bbuf[xcount+1] == 0xcd && bbuf[xcount+2] == 0xcd) { ycount = xcount; break; } } ebuf[65508] = bbuf[ycount -28]; ebuf[65509] = bbuf[ycount -27]; ebuf[65510] = bbuf[ycount -26]; ebuf[65511] = bbuf[ycount -25]; ebuf[65512] = bbuf[ycount -24]; ebuf[65513] = bbuf[ycount -23]; ebuf[65514] = bbuf[ycount -22]; ebuf[65515] = bbuf[ycount -21]; ebuf[65516] = bbuf[ycount -20]; ebuf[65517] = bbuf[ycount -19]; ebuf[65518] = bbuf[ycount -18]; ebuf[65519] = bbuf[ycount -17]; ebuf[65520] = bbuf[ycount -16]; ebuf[65521] = bbuf[ycount -15]; ebuf[65522] = bbuf[ycount -14]; ebuf[65523] = bbuf[ycount -13]; ebuf[65524] = bbuf[ycount -12]; ebuf[65525] = bbuf[ycount -11]; ebuf[65526] = bbuf[ycount -10]; ebuf[65527] = bbuf[ycount -9]; ebuf[65528] = bbuf[ycount -8]; ebuf[65529] = bbuf[ycount -7]; ebuf[65530] = bbuf[ycount -6]; ebuf[65531] = bbuf[ycount -5]; ebuf[65532] = bbuf[ycount -4]; ebuf[65533] = bbuf[ycount -3]; ebuf[65534] = bbuf[ycount -2]; ebuf[65535] = bbuf[ycount -1]; for(zcount = (ycount-28); zcount < 65536; zcount++) { bbuf[zcount] = 0xff; } EraseBlock(check); WriteBlock(bbuf,check); STUART_Flush(Dev_Uart_Handle); break; }else{ // LOCAL BLOCK EraseBlock(check); WriteBlock(bbuf,check); STUART_Flush(Dev_Uart_Handle); STUARTremoconWritex(Dev_Uart_Handle,cbuf,1); } } EraseBlock(15); // 응용 프로그램의 부트블럭을 write 할 블력번호 지정 WriteBlock(ebuf, 15); // 역시 마찬가지!! //ReadFlash(); /* */ STUARTremoconWritex(Dev_Uart_Handle,fbuf,15); STUART_Flush(Dev_Uart_Handle); FLASH_Close(BANK0); FLASH_Term(TRUE, BANK0); printf("\nFinsh!!\n"); }
4M FLASH
void Down_Bun(void) { ST_ErrorCode_t uerr; U8 cbuf[1] = 0; U8 bbuf [65540]; //U8 ebuf[16385]; U8 ebuf[65540]; U8 fbuf[16]; U8 check = 0; U32 ck = 0; U32 array = 0, barray = 0; U32 read_len = 0; U32 xcount = 0; U32 ycount = 0; U32 zcount = 0; cbuf[0] = 'S'; fbuf[0] = 'F'; fbuf[1] = 'I'; fbuf[2] = 'N'; fbuf[3] = 'I'; fbuf[4] = 'S'; fbuf[5] = 'H'; fbuf[6] = 'E'; fbuf[7] = 'D'; fbuf[8] = '_'; fbuf[9] = 'B'; fbuf[10] = 'U'; fbuf[11] = 'R'; fbuf[12] = 'N'; fbuf[13] = 'N'; fbuf[14] = 'E'; fbuf[15] = 'R'; for(array=0;array<65540;array++) { bbuf[array]= 0xff; } for(barray=0;barray<65540;barray++) { ebuf[barray] = 0xff; } for(check=0; check<71; check++) // 총 블럭의 갯수(71)에 유의할 것 { STUART_Flush(Dev_Uart_Handle); uerr = STUARTremoconReadx(Dev_Uart_Handle, bbuf, &read_len); if(uerr != ST_NO_ERROR)printf("\nUART READ FAIL\n"); if(bbuf[65535] == 0xcd && bbuf[65536] == 0x7a) // LAST BLOCK { for(xcount=0; xcount < 65536; xcount++) { if(bbuf[xcount] == 0xcd && bbuf[xcount+1] == 0xcd && bbuf[xcount+2] == 0xcd) { ycount = xcount; break; } } ebuf[65508] = bbuf[ycount -28]; ebuf[65509] = bbuf[ycount -27]; ebuf[65510] = bbuf[ycount -26]; ebuf[65511] = bbuf[ycount -25]; ebuf[65512] = bbuf[ycount -24]; ebuf[65513] = bbuf[ycount -23]; ebuf[65514] = bbuf[ycount -22]; ebuf[65515] = bbuf[ycount -21]; ebuf[65516] = bbuf[ycount -20]; ebuf[65517] = bbuf[ycount -19]; ebuf[65518] = bbuf[ycount -18]; ebuf[65519] = bbuf[ycount -17]; ebuf[65520] = bbuf[ycount -16]; ebuf[65521] = bbuf[ycount -15]; ebuf[65522] = bbuf[ycount -14]; ebuf[65523] = bbuf[ycount -13]; ebuf[65524] = bbuf[ycount -12]; ebuf[65525] = bbuf[ycount -11]; ebuf[65526] = bbuf[ycount -10]; ebuf[65527] = bbuf[ycount -9]; ebuf[65528] = bbuf[ycount -8]; ebuf[65529] = bbuf[ycount -7]; ebuf[65530] = bbuf[ycount -6]; ebuf[65531] = bbuf[ycount -5]; ebuf[65532] = bbuf[ycount -4]; ebuf[65533] = bbuf[ycount -3]; ebuf[65534] = bbuf[ycount -2]; ebuf[65535] = bbuf[ycount -1]; for(zcount = (ycount-28); zcount < 65536; zcount++) { bbuf[zcount] = 0xff; } EraseBlock(check); WriteBlock(bbuf,check); STUART_Flush(Dev_Uart_Handle); break; }else{ // LOCAL BLOCK EraseBlock(check); WriteBlock(bbuf,check); STUART_Flush(Dev_Uart_Handle); STUARTremoconWritex(Dev_Uart_Handle,cbuf,1); } } EraseBlock(61); // 응용 프로그램의 부트블럭을 write 할 블력번호 지정 WriteBlock(ebuf, 61); // 역시 마찬가지 STUARTremoconWritex(Dev_Uart_Handle,fbuf,15); STUART_Flush(Dev_Uart_Handle); //printf("\ntest\n"); FLASH_Close(BANK0); FLASH_Term(TRUE, BANK0); printf("\nFinsh!!\n"); }
8M FLASH
void Down_Bun(void) { ST_ErrorCode_t uerr; U8 cbuf[1] = 0; U8 bbuf [65540]; //U8 ebuf[16385]; U8 ebuf[65540]; U8 fbuf[16]; U8 check = 0; U32 ck = 0; U32 array = 0, barray = 0; U32 read_len = 0; U32 xcount = 0; U32 ycount = 0; U32 zcount = 0; cbuf[0] = 'S'; fbuf[0] = 'F'; fbuf[1] = 'I'; fbuf[2] = 'N'; fbuf[3] = 'I'; fbuf[4] = 'S'; fbuf[5] = 'H'; fbuf[6] = 'E'; fbuf[7] = 'D'; fbuf[8] = '_'; fbuf[9] = 'B'; fbuf[10] = 'U'; fbuf[11] = 'R'; fbuf[12] = 'N'; fbuf[13] = 'N'; fbuf[14] = 'E'; fbuf[15] = 'R'; for(array=0;array<65540;array++) { bbuf[array]= 0xff; } for(barray=0;barray<65540;barray++) { ebuf[barray] = 0xff; } for(check=0; check<135; check++) // 총 블럭의 갯수(135)에 유의할 것 { STUART_Flush(Dev_Uart_Handle); uerr = STUARTremoconReadx(Dev_Uart_Handle, bbuf, &read_len); if(uerr != ST_NO_ERROR)printf("\nUART READ FAIL\n"); if(bbuf[65535] == 0xcd && bbuf[65536] == 0x7a) // LAST BLOCK { for(xcount=0; xcount < 65536; xcount++) { if(bbuf[xcount] == 0xcd && bbuf[xcount+1] == 0xcd && bbuf[xcount+2] == 0xcd) { ycount = xcount; break; } } ebuf[65508] = bbuf[ycount -28]; ebuf[65509] = bbuf[ycount -27]; ebuf[65510] = bbuf[ycount -26]; ebuf[65511] = bbuf[ycount -25]; ebuf[65512] = bbuf[ycount -24]; ebuf[65513] = bbuf[ycount -23]; ebuf[65514] = bbuf[ycount -22]; ebuf[65515] = bbuf[ycount -21]; ebuf[65516] = bbuf[ycount -20]; ebuf[65517] = bbuf[ycount -19]; ebuf[65518] = bbuf[ycount -18]; ebuf[65519] = bbuf[ycount -17]; ebuf[65520] = bbuf[ycount -16]; ebuf[65521] = bbuf[ycount -15]; ebuf[65522] = bbuf[ycount -14]; ebuf[65523] = bbuf[ycount -13]; ebuf[65524] = bbuf[ycount -12]; ebuf[65525] = bbuf[ycount -11]; ebuf[65526] = bbuf[ycount -10]; ebuf[65527] = bbuf[ycount -9]; ebuf[65528] = bbuf[ycount -8]; ebuf[65529] = bbuf[ycount -7]; ebuf[65530] = bbuf[ycount -6]; ebuf[65531] = bbuf[ycount -5]; ebuf[65532] = bbuf[ycount -4]; ebuf[65533] = bbuf[ycount -3]; ebuf[65534] = bbuf[ycount -2]; ebuf[65535] = bbuf[ycount -1]; for(zcount = (ycount-28); zcount < 65536; zcount++) { bbuf[zcount] = 0xff; } EraseBlock(check); WriteBlock(bbuf,check); STUART_Flush(Dev_Uart_Handle); break; }else{ // LOCAL BLOCK EraseBlock(check); WriteBlock(bbuf,check); STUART_Flush(Dev_Uart_Handle); STUARTremoconWritex(Dev_Uart_Handle,cbuf,1); } } EraseBlock(125); // 응용 프로그램의 부트블럭을 write 할 블력번호 지정 WriteBlock(ebuf, 125); // 역시 마찬가지!! STUARTremoconWritex(Dev_Uart_Handle,fbuf,15); STUART_Flush(Dev_Uart_Handle); FLASH_Close(BANK0); FLASH_Term(TRUE, BANK0); printf("\nFinsh!!\n"); }
이번에는 앞에서 살펴본 부트 프로그램을 HEX 파일로 만들 때의 설정에 대해서 알아보도록 하겠다.
mb382_um.cfg
HEX 파일 생성시에 참조되는 mb382_um.cfg 파일이다.
2M FLASH
memory FLASH 0x7Ff00000 (1*M) ROM
4M FLASH
memory FLASH 0x7Ffe0000 (128*K) ROM
8M FLASH
memory FLASH 0x7Ffe0000 (128*K) ROM
참고로 2M 의 경우에는 HEX 파일 용량 최적화를 하지 않았다. 그래서 1M 용량을 잡은 것이다. 4M 와 8M 의 경우에는 부트 프로그램을 128K 안에 만들었다. HEX 파일의 시작하는 주소만 다를 뿐, 끝 주소는 동일하다.
응용 프로그램
mb382_um.cfg
응용 프로그램의 경우에는 HEX 파일을 만들 때, 필요한 .cfg 파일만 각 FLASH 용량에 따라 수정해주면 된다. 가장 중요한 파일이라고 할 수 있는 mb382_um.cfg 이다.
2M FLASH
memory FLASH0 0x7Fe00000 (1*M) ROM ... ... proc board_init_hex { write Setup5517 reset Mem5517Space (0) (1) ST20C2MemoryInit ## procedure written by MCDT, replaces c2MemoryInit, reserves area 0x80000000 to 0x80000040 bootiptr (0x7ffffffe - (1 * M)) }
4M FLASH
memory FLASH 0x7fc00000 (3968*K) ROM ... ... proc board_init_hex { write Setup5517 reset Mem5517Space (0) (1) ST20C2MemoryInit ## procedure written by MCDT, replaces c2MemoryInit, reserves area 0x80000000 to 0x80000040 bootiptr (0x7Ff00000 + (896*K)-2 ) }
8M FLASH
memory FLASH 0x7F800000 (8064*K) ROM ... ... proc board_init_hex { write Setup5517 reset Mem5517Space (0) (1) ST20C2MemoryInit ## procedure written by MCDT, replaces c2MemoryInit, reserves area 0x80000000 to 0x80000040 bootiptr (0x7Ff00000 + (896*K)-2 ) }