tools/header_generation/create_hdr_common.c
/***************************************************************************
 * Function	:	get_apnd_img
 * Arguments	:	file_name - name of the input file
 * Return	:	SUCCESS or FAILURE$
 * Description	:	fill global data structure with data
 *			of images to be appended$
 ***************************************************************************/
Function     :       get_apnd_img
Arguments    :       file_name - name of the input file
Return       :       SUCCESS or FAILURE$
Description  :       fill global data structure with data
of images to be appended$
Function : get_apnd_img Arguments : file_name - name of the input file Return : SUCCESS or FAILURE$ Description : fill global data structure with data of images to be appended$
int add_apnd_img(void)
{
#define BUFFER_SIZE             1024
#define APPEND_IMAGE_PAD        0xff
	FILE *fp_rcw_pbi_op;
	int i, j, size, ret;
	uint32_t image_offset, file_len;
	char *image_name;
	uint8_t data_buffer[BUFFER_SIZE], padding[BUFFER_SIZE];
	FILE *fp_img;
	fp_rcw_pbi_op = fopen(gd.hdr_file_name, "ab");
	if (fp_rcw_pbi_op == NULL) {
		printf("Error in opening the file: %s\n",
		gd.hdr_file_name);
		return FAILURE;
	}
	if (gd.ap_count != 0)
		printf("\n\nImages to be appended\n");
	memset(padding, APPEND_IMAGE_PAD, BUFFER_SIZE);
	for (i = 0; i < gd.ap_count; i++) {
		image_offset = gd.ap_file[i].offset;
		image_name = gd.ap_file[i].name;
		printf("Image Offset: %08x, Image Name: %s\n",
		image_offset, image_name);
		fseek(fp_rcw_pbi_op, 0L, SEEK_END);
		file_len = ftell(fp_rcw_pbi_op);
		if (image_offset < file_len) {
			printf("Error Image offset: %08x less than\n"
			"file length: %08x\n", image_offset, file_len);
			return FAILURE;
		}
		for (j = (image_offset - file_len); j > 0; j -= BUFFER_SIZE) {
			ret = fwrite(&padding, ((j >= BUFFER_SIZE) ?
			BUFFER_SIZE : j), 1, fp_rcw_pbi_op);
			if (ret == 0) {
				printf("Error in Appending Padding\n");
				return FAILURE;
			}
		}
		fp_img = fopen(image_name, "rb");
		if (fp_img == NULL) {
			printf("Error in opening the file append: %s\n",
				image_name);
			return FAILURE;
		}
		while ((size = fread(&data_buffer, 1, BUFFER_SIZE, fp_img))) {
			ret = fwrite(&data_buffer, 1, size, fp_rcw_pbi_op);
			if (ret == 0) {
				printf("Error in Appending Image\n");
				return FAILURE;
			}
		}
		fclose(fp_img);
	}
	return SUCCESS;
}
int add_apnd_img ( void ) { #define BUFFER_SIZE              1024 #define APPEND_IMAGE_PAD         0xff FILE * fp_rcw_pbi_op ; int i , j , size , ret ; uint32_t image_offset , file_len ; char * image_name ; uint8_t data_buffer [ BUFFER_SIZE ] , padding [ BUFFER_SIZE ] ; FILE * fp_img ; fp_rcw_pbi_op = fopen ( gd . hdr_file_name , " " ) ; if ( fp_rcw_pbi_op == NULL ) { printf ( " \n " , gd . hdr_file_name ) ; return FAILURE ; } if ( gd . ap_count != 0 ) printf ( " \n \n \n " ) ; memset ( padding , APPEND_IMAGE_PAD , BUFFER_SIZE ) ; for ( i = 0 ; i < gd . ap_count ; i ++ ) { image_offset = gd . ap_file [ i ] . offset ; image_name = gd . ap_file [ i ] . name ; printf ( " \n " , image_offset , image_name ) ; fseek ( fp_rcw_pbi_op , 0L , SEEK_END ) ; file_len = ftell ( fp_rcw_pbi_op ) ; if ( image_offset < file_len ) { printf ( " \n " " \n " , image_offset , file_len ) ; return FAILURE ; } for ( j = ( image_offset - file_len ) ; j > 0 ; j -= BUFFER_SIZE ) { ret = fwrite ( & padding , ( ( j >= BUFFER_SIZE ) ? BUFFER_SIZE : j ) , 1 , fp_rcw_pbi_op ) ; if ( ret == 0 ) { printf ( " \n " ) ; return FAILURE ; } } fp_img = fopen ( image_name , " " ) ; if ( fp_img == NULL ) { printf ( " \n " , image_name ) ; return FAILURE ; } while ( ( size = fread ( & data_buffer , 1 , BUFFER_SIZE , fp_img ) ) ) { ret = fwrite ( & data_buffer , 1 , size , fp_rcw_pbi_op ) ; if ( ret == 0 ) { printf ( " \n " ) ; return FAILURE ; } } fclose ( fp_img ) ; } return SUCCESS ; }
Function     :       get_apnd_img
 Arguments    :       file_name - name of the input file
 Return       :       SUCCESS or FAILURE$
 Description  :       fill global data structure with data
                      of images to be appended$
Function : get_apnd_img Arguments : file_name - name of the input file Return : SUCCESS or FAILURE$ Description : fill global data structure with data of images to be appended$
/* Get file size */ /* Append padding */