#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include "MPC8248MPU-139.h"

// #define DEBUG_TRACE

#define FNAME	"u-boot.bin"
int main ( void ) {
	FILE *fp;
	char buff[64];
#ifdef DEBUG_TRACE
	int loop;
#endif
	fp = fopen( FNAME, "r+" );
	fseek( fp, U_BOOT_OFFSET, SEEK_SET );

	memset( buff, 0, sizeof( buff) );

	fread( buff, sizeof(buff), 1, fp );

	memcpy( buff, U_BOOT_VERSION, strlen(U_BOOT_VERSION) );
#ifdef DEBUG_TRACE
	for ( loop = 0; loop < sizeof(buff); loop++ ) {
		printf("0x%02X ", buff[loop]);
	}
	printf("\n");
#endif

	fseek( fp, U_BOOT_OFFSET, SEEK_SET );
	
	fwrite( buff, sizeof(buff), 1, fp );
	fflush(fp);


#ifdef DEBUG_TRACE
	
	memset( buff, 0, sizeof( buff) );
	fseek( fp, U_BOOT_OFFSET, SEEK_SET );
	fread( buff, sizeof(buff), 1, fp );
	for ( loop = 0; loop < sizeof(buff); loop++ ) {
		printf("0x%02X ", buff[loop]);
	}
	printf("\n");
#endif
	fclose(fp);

	return 0;
}
