bff.c

来自「mx21 Nor flash Bootloader 源代码」· C语言 代码 · 共 98 行

C
98
字号
/// @ingroup    AMD_BOOTLOADER/// @file       bff.c/// @brief      The tool is used to combine two files into one.////// @remarks    The format should be\n///             	bff SourceFile2 SourceFile1 TargetFile [size for SourceFile1]\n///             The default size for SourceFile1 is 512/// @bug        /// @version    $Version$/// @section history	History///		24-Dec-03 Add size option for combining bootloader for AXD method/////<<<<<Include#include <stdio.h>//>>>>>Include//<<<<<< Private Macro//>>>>>> Private Macro//<<<<<< Private Structure//>>>>>> Private Structure//<<<<<< Global VariableFILE *in1,*in2, *outfile;//>>>>>> Global Variable//<<<<<Private Function Declearation//>>>>>Private Function Declearation//<<<<<Bodyint CombineFirstFile( unsigned int size){	int number;	unsigned char rData[size];    	number=fread(rData,sizeof(char),size,in2);	fwrite(rData, sizeof(char), size, outfile);		return number;}///Main functionint main (int argc, char *argv[]){	int	i,num;	unsigned int readSize = 512;	unsigned char bData;		if (argc < 4 || argc > 5)	{	    	printf("Usage: bff file2 file1 targetfile [size]\n \			Example: bff bootloader.bin flashloader.bin bootfromflash.bin\n");		return 0;	}	if (!(in1 = fopen(argv[1],"rb")))	{		printf("Input file open error !\n");		return 0;	}	if (!(in2 = fopen(argv[2],"rb")))	{		printf("Input file open error !\n");		fclose(in1);		return 0;	}	if (!(outfile = fopen(argv[3],"wb")))	{		printf("Output file open error !\n");		fclose(in1);		fclose(in2);		return 0;	}	if( argc == 5 )		readSize = atoi(argv[4]);	num = CombineFirstFile( readSize );	printf("read %d chars from %s\n",num,argv[2]);	if( argc == 4 )	{	    	/* For old use */		bData = 0;		for (i=num; i<0x1F8; i++)			fwrite(&bData, sizeof(char), 1, outfile);	}	while( fread(&bData,sizeof(char),1,in1) > 0)		fwrite(&bData,sizeof(char),1, outfile);	fclose(outfile);	fclose(in1);	fclose(in2);	printf("\nConversion done.\n");	return 0;}//>>>>>Body

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?