tools/pbi_creation/create_pbi_common.c
/***************************************************************************
 * Function	:	create_pbi_ta2
 * Arguments	:	argc - Argument Count
 *			argv - Argumnet List
 * Return	:	SUCCESS or FAILURE
 * Description	:	Main function where execution starts
 ***************************************************************************/
Function     :       create_pbi_ta2
Arguments    :       argc - Argument Count
argv - Argumnet List
Return       :       SUCCESS or FAILURE
Description  :       Main function where execution starts
Function : create_pbi_ta2 Arguments : argc - Argument Count argv - Argumnet List Return : SUCCESS or FAILURE Description : Main function where execution starts
int create_pbi_ta2(int argc, char **argv)
{
	int ret;
	FILE *fp_rcw_pbi_ip, *fp_rcw_pbi_op;
	uint32_t word;
	enum cfg_taal cfg_taal;
	printf("\n\t#----------------------------------------------------#");
	printf("\n\t#-------         --------     --------        -------#");
	printf("\n\t#------- CST (Code Signing Tool) Version 2.0  -------#");
	printf("\n\t#-------         --------     --------        -------#");
	printf("\n\t#----------------------------------------------------#");
	printf("\n");
	ret = ta2_parse_input_file(parse_list, NUM_PARSE_LIST);
	printf("Input File Name : %s\n", gd.rcw_fname);
	fp_rcw_pbi_ip = fopen(gd.rcw_fname, "rb");
	if (fp_rcw_pbi_ip == NULL) {
		printf("Error in opening the file: %s\n", gd.rcw_fname);
		return FAILURE;
	}
	printf("Output File Name : %s\n", gd.rcw_op_fname);
	fp_rcw_pbi_op = fopen(gd.rcw_op_fname, "wb+");
	if (fp_rcw_pbi_op == NULL) {
		printf("Error in opening the file: %s\n", gd.rcw_op_fname);
		fclose(fp_rcw_pbi_ip);
		return FAILURE;
	}
	printf("\nInput File is %s\n", gd.input_file);
	cfg_taal = get_ta_from_file(gd.input_file);
	switch (cfg_taal)  {
	case TA_2_0_PBL:
		gd.stop_cmd = CRC_STOP_CMD_POWERPC;
		break;
	default :
		gd.stop_cmd = CRC_STOP_CMD_ARM;
		break;
	}
	ret = rcw_sben_boot_ho(fp_rcw_pbi_ip, fp_rcw_pbi_op);
	ret = fread(&word, sizeof(word), 1, fp_rcw_pbi_ip);
	while (BYTE_SWAP_32(word) != gd.stop_cmd) {
		ret = fwrite(&word, sizeof(word), 1, fp_rcw_pbi_op);
		if (ret == 0) {
			printf("Error in Writing PBI Words\n");
                        ret = FAILURE;
                        goto exit;
		}
		ret = fread(&word, sizeof(word), 1, fp_rcw_pbi_ip);
		if (ret == 0) {
			printf("Error in Reading PBI Words\n");
                        ret = FAILURE;
                        goto exit;
		}
	}
	ret = get_bootptr(fp_rcw_pbi_op);
	if (ret != SUCCESS)
		goto exit;
	ret = get_copy_cmd(gd.input_file);
	if (ret != SUCCESS)
		goto exit;
	ret = add_cpy_cmd(fp_rcw_pbi_op);
	if (ret != SUCCESS)
		goto exit;
	ret = add_pbi_stop_cmd(fp_rcw_pbi_op);
	if (ret != SUCCESS)
		goto exit;
	ret = get_ap_img(gd.input_file);
	if (ret != SUCCESS)
		goto exit;
	ret = add_ap_img(fp_rcw_pbi_op);
	if (ret != SUCCESS)
		goto exit;
	printf("\n\n");
	ret = SUCCESS;
exit:
	fclose(fp_rcw_pbi_op);
	fclose(fp_rcw_pbi_ip);
	return ret;
}
int create_pbi_ta2 ( int argc , char * * argv ) { int ret ; FILE * fp_rcw_pbi_ip , * fp_rcw_pbi_op ; uint32_t word ; enum cfg_taal cfg_taal ; printf ( " \n \t " ) ; printf ( " \n \t " ) ; printf ( " \n \t " ) ; printf ( " \n \t " ) ; printf ( " \n \t " ) ; printf ( " \n " ) ; ret = ta2_parse_input_file ( parse_list , NUM_PARSE_LIST ) ; printf ( " \n " , gd . rcw_fname ) ; fp_rcw_pbi_ip = fopen ( gd . rcw_fname , " " ) ; if ( fp_rcw_pbi_ip == NULL ) { printf ( " \n " , gd . rcw_fname ) ; return FAILURE ; } printf ( " \n " , gd . rcw_op_fname ) ; fp_rcw_pbi_op = fopen ( gd . rcw_op_fname , " " ) ; if ( fp_rcw_pbi_op == NULL ) { printf ( " \n " , gd . rcw_op_fname ) ; fclose ( fp_rcw_pbi_ip ) ; return FAILURE ; } printf ( " \n \n " , gd . input_file ) ; cfg_taal = get_ta_from_file ( gd . input_file ) ; switch ( cfg_taal ) { case TA_2_0_PBL : gd . stop_cmd = CRC_STOP_CMD_POWERPC ; break ; default : gd . stop_cmd = CRC_STOP_CMD_ARM ; break ; } ret = rcw_sben_boot_ho ( fp_rcw_pbi_ip , fp_rcw_pbi_op ) ; ret = fread ( & word , sizeof ( word ) , 1 , fp_rcw_pbi_ip ) ; while ( BYTE_SWAP_32 ( word ) != gd . stop_cmd ) { ret = fwrite ( & word , sizeof ( word ) , 1 , fp_rcw_pbi_op ) ; if ( ret == 0 ) { printf ( " \n " ) ; ret = FAILURE ; goto exit ; } ret = fread ( & word , sizeof ( word ) , 1 , fp_rcw_pbi_ip ) ; if ( ret == 0 ) { printf ( " \n " ) ; ret = FAILURE ; goto exit ; } } ret = get_bootptr ( fp_rcw_pbi_op ) ; if ( ret != SUCCESS ) goto exit ; ret = get_copy_cmd ( gd . input_file ) ; if ( ret != SUCCESS ) goto exit ; ret = add_cpy_cmd ( fp_rcw_pbi_op ) ; if ( ret != SUCCESS ) goto exit ; ret = add_pbi_stop_cmd ( fp_rcw_pbi_op ) ; if ( ret != SUCCESS ) goto exit ; ret = get_ap_img ( gd . input_file ) ; if ( ret != SUCCESS ) goto exit ; ret = add_ap_img ( fp_rcw_pbi_op ) ; if ( ret != SUCCESS ) goto exit ; printf ( " \n \n " ) ; ret = SUCCESS ; exit : fclose ( fp_rcw_pbi_op ) ; fclose ( fp_rcw_pbi_ip ) ; return ret ; }
Function     :       create_pbi_ta2
 Arguments    :       argc - Argument Count
                      argv - Argumnet List
 Return       :       SUCCESS or FAILURE
 Description  :       Main function where execution starts
Function : create_pbi_ta2 Arguments : argc - Argument Count argv - Argumnet List Return : SUCCESS or FAILURE Description : Main function where execution starts
/* Initialization of Global Structure to 0 */ /* Check the command line argument */ /* modify rcw field based on sben and boot_ho */ /* Add command to set boot_loc ptr */ /* Get acs write command and fill global data structure */ /* Write acs write commands to output file */ /* Add stop command after adding pbi commands */ /* get data for images to be appended and fill data struct */ /* append images to the output file */