@ -369,6 +369,7 @@ static size_t image_headersz_v1(int *hasext)
fprintf ( stderr , " Increase CONFIG_SYS_U_BOOT_OFFS! \n " ) ;
return 0 ;
}
headersz = CONFIG_SYS_U_BOOT_OFFS ;
# endif
@ -379,63 +380,9 @@ static size_t image_headersz_v1(int *hasext)
return ALIGN_SUP ( headersz , 4096 ) ;
}
static void * image_create_v1 ( size_t * imagesz , struct image_tool_params * params ,
int payloadsz )
int add_binary_header_v1 ( uint8_t * cur )
{
struct image_cfg_element * e , * binarye ;
struct main_hdr_v1 * main_hdr ;
size_t headersz ;
uint8_t * image , * cur ;
int hasext = 0 ;
/*
* Calculate the size of the header and the size of the
* payload
*/
headersz = image_headersz_v1 ( & hasext ) ;
if ( headersz = = 0 )
return NULL ;
image = malloc ( headersz ) ;
if ( ! image ) {
fprintf ( stderr , " Cannot allocate memory for image \n " ) ;
return NULL ;
}
memset ( image , 0 , headersz ) ;
main_hdr = ( struct main_hdr_v1 * ) image ;
cur = image + sizeof ( struct main_hdr_v1 ) ;
/* Fill the main header */
main_hdr - > blocksize =
cpu_to_le32 ( payloadsz - headersz + sizeof ( uint32_t ) ) ;
main_hdr - > headersz_lsb = cpu_to_le16 ( headersz & 0xFFFF ) ;
main_hdr - > headersz_msb = ( headersz & 0xFFFF0000 ) > > 16 ;
main_hdr - > destaddr = cpu_to_le32 ( params - > addr )
- sizeof ( image_header_t ) ;
main_hdr - > execaddr = cpu_to_le32 ( params - > ep ) ;
main_hdr - > srcaddr = cpu_to_le32 ( headersz ) ;
main_hdr - > ext = hasext ;
main_hdr - > version = 1 ;
e = image_find_option ( IMAGE_CFG_BOOT_FROM ) ;
if ( e )
main_hdr - > blockid = e - > bootfrom ;
e = image_find_option ( IMAGE_CFG_NAND_BLKSZ ) ;
if ( e )
main_hdr - > nandblocksize = e - > nandblksz / ( 64 * 1024 ) ;
e = image_find_option ( IMAGE_CFG_NAND_BADBLK_LOCATION ) ;
if ( e )
main_hdr - > nandbadblklocation = e - > nandbadblklocation ;
e = image_find_option ( IMAGE_CFG_BAUDRATE ) ;
if ( e )
main_hdr - > options = baudrate_to_option ( e - > baudrate ) ;
e = image_find_option ( IMAGE_CFG_DEBUG ) ;
if ( e )
main_hdr - > flags = e - > debug ? 0x1 : 0 ;
binarye = image_find_option ( IMAGE_CFG_BINARY ) ;
if ( binarye ) {
struct image_cfg_element * binarye ;
struct opt_hdr_v1 * hdr = ( struct opt_hdr_v1 * ) cur ;
uint32_t * args ;
size_t binhdrsz ;
@ -444,13 +391,18 @@ static void *image_create_v1(size_t *imagesz, struct image_tool_params *params,
FILE * bin ;
int ret ;
binarye = image_find_option ( IMAGE_CFG_BINARY ) ;
if ( ! binarye )
return 0 ;
hdr - > headertype = OPT_HDR_V1_BINARY_TYPE ;
bin = fopen ( binarye - > binary . file , " r " ) ;
if ( ! bin ) {
fprintf ( stderr , " Cannot open binary file %s \n " ,
binarye - > binary . file ) ;
return NULL ;
return - 1 ;
}
fstat ( fileno ( bin ) , & s ) ;
@ -483,7 +435,7 @@ static void *image_create_v1(size_t *imagesz, struct image_tool_params *params,
fprintf ( stderr ,
" Could not read binary image %s \n " ,
binarye - > binary . file ) ;
return NULL ;
return - 1 ;
}
fclose ( bin ) ;
@ -499,8 +451,68 @@ static void *image_create_v1(size_t *imagesz, struct image_tool_params *params,
* ( ( uint32_t * ) cur ) = 0x00000000 ;
cur + = sizeof ( uint32_t ) ;
return 0 ;
}
static void * image_create_v1 ( size_t * imagesz , struct image_tool_params * params ,
int payloadsz )
{
struct image_cfg_element * e ;
struct main_hdr_v1 * main_hdr ;
size_t headersz ;
uint8_t * image , * cur ;
int hasext = 0 ;
/*
* Calculate the size of the header and the size of the
* payload
*/
headersz = image_headersz_v1 ( & hasext ) ;
if ( headersz = = 0 )
return NULL ;
image = malloc ( headersz ) ;
if ( ! image ) {
fprintf ( stderr , " Cannot allocate memory for image \n " ) ;
return NULL ;
}
memset ( image , 0 , headersz ) ;
main_hdr = ( struct main_hdr_v1 * ) image ;
cur = image + sizeof ( struct main_hdr_v1 ) ;
/* Fill the main header */
main_hdr - > blocksize =
cpu_to_le32 ( payloadsz - headersz + sizeof ( uint32_t ) ) ;
main_hdr - > headersz_lsb = cpu_to_le16 ( headersz & 0xFFFF ) ;
main_hdr - > headersz_msb = ( headersz & 0xFFFF0000 ) > > 16 ;
main_hdr - > destaddr = cpu_to_le32 ( params - > addr )
- sizeof ( image_header_t ) ;
main_hdr - > execaddr = cpu_to_le32 ( params - > ep ) ;
main_hdr - > srcaddr = cpu_to_le32 ( headersz ) ;
main_hdr - > ext = hasext ;
main_hdr - > version = 1 ;
e = image_find_option ( IMAGE_CFG_BOOT_FROM ) ;
if ( e )
main_hdr - > blockid = e - > bootfrom ;
e = image_find_option ( IMAGE_CFG_NAND_BLKSZ ) ;
if ( e )
main_hdr - > nandblocksize = e - > nandblksz / ( 64 * 1024 ) ;
e = image_find_option ( IMAGE_CFG_NAND_BADBLK_LOCATION ) ;
if ( e )
main_hdr - > nandbadblklocation = e - > nandbadblklocation ;
e = image_find_option ( IMAGE_CFG_BAUDRATE ) ;
if ( e )
main_hdr - > options = baudrate_to_option ( e - > baudrate ) ;
e = image_find_option ( IMAGE_CFG_DEBUG ) ;
if ( e )
main_hdr - > flags = e - > debug ? 0x1 : 0 ;
if ( add_binary_header_v1 ( cur ) )
return NULL ;
/* Calculate and set the header checksum */
main_hdr - > checksum = image_checksum8 ( main_hdr , headersz ) ;