⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 createflashimage.c

📁 用于dm6467 开发平台的uboot源码
💻 C
字号:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

typedef unsigned int	Uint32;

typedef struct {
	Uint32		magicNo;
	Uint32		appSize;
	Uint32		appEntry;
	Uint32		reserved;
} nor_hdr;

int main (int argc, char **argv)
{
	FILE *inPtr, *outPtr;
	nor_hdr	hdr;
	unsigned char *data = NULL;

	if(argc != 5)
	{
		printf("Usage %s <input file> <output file> <Entry point> <Flag>\n", argv[0]);
		return -1;
	}

	inPtr = fopen (argv[1], "rb");
	if(inPtr == NULL)
	{
		printf("Input file open failed\n");
		return -1;
	}

	outPtr = fopen (argv[2], "wb");
	if(outPtr == NULL)
	{
		printf("Output file open failed\n");
		fclose (inPtr);
		return -1;
	}

	hdr.appEntry = strtoul(argv[3], NULL, 16);
	hdr.magicNo = strtoul(argv[4], NULL, 16);

	/* Calculate the Application Size */
	fseek (inPtr, 0, SEEK_END);
	hdr.appSize = ftell (inPtr);

	hdr.reserved = 0x00000000;

	/* Write the header */
	fwrite(&hdr, sizeof(hdr), 1, outPtr);

	/* Go to the Start of the Input File */
	fseek (inPtr, 0, SEEK_SET);

	/* Allocate Memory */
	data = (unsigned char *) malloc(hdr.appSize);
	if(data == NULL)
	{
		printf("Memory Allocation Failed\n");
		goto err_exit;
	}

	/* Read the data */
	fread(data, 1, hdr.appSize, inPtr);

	/* Write the data */
	fwrite(data, 1, hdr.appSize, outPtr);

	printf("File %d\n", hdr.appSize);

	free (data);

err_exit:
	fclose(inPtr);
	fclose(outPtr);
	return 0;
}

⌨️ 快捷键说明

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