flash bin文件合成

  • Post author:
  • Post category:其他


#include <stdio.h>

#include <stdlib.h>

#include <string.h>

#include <sys/types.h>

#include <sys/stat.h>

#include <sys/ioctl.h>

#include <sys/poll.h>

#include <sys/time.h>

#include <fcntl.h>

#include <errno.h>

#include <pthread.h>

#include <math.h>

#include <unistd.h>

#include <signal.h>

#define PMON_FILEPATH         “gzrom-dtb-pi.bin”

#define KERNEL_FILEPATH         “vmlinuz”

#define ROOTFS_FILEPATH         “rootfs.jffs2”

#define BIN_FILEPATH         “ls2k.bin”

#define PMON_SIZE   0x100000

#define KERNEL_SIZE 0x600000

#define ROOTFS_SIZE 0x900000

FILE *pfd_pmon;

FILE *pfd_kernel;

FILE *pfd_rootfs;

FILE *pfd_bin;


#define BUF_SIZE 4096

unsigned char temp[BUF_SIZE] = {0};

unsigned char temp_fill[1048576] = {0};

int main(void)

{


int u32ReadLen=0;

int read_all_len=0;

int need_write_fill=0;

pfd_pmon = fopen(PMON_FILEPATH, “rb” );

pfd_kernel = fopen(KERNEL_FILEPATH, “rb” );

pfd_rootfs = fopen(ROOTFS_FILEPATH, “rb” );

pfd_bin = fopen(BIN_FILEPATH, “wb” );

memset(temp_fill,0xff,1048576);

printf(“1\n”);

while(1)

{

u32ReadLen = fread(temp, 1, BUF_SIZE, pfd_pmon);

if(u32ReadLen>0)

{

read_all_len+=u32ReadLen;

fwrite(temp, u32ReadLen, 1, pfd_bin);

}

else

{


need_write_fill=PMON_SIZE-read_all_len;

fwrite(temp_fill, need_write_fill, 1, pfd_bin);

read_all_len=0;

printf(“pmon_ok!\n”);

break;

}

}

while(1)

{

u32ReadLen = fread(temp, 1, BUF_SIZE, pfd_kernel);

if(u32ReadLen>0)

{

read_all_len+=u32ReadLen;

fwrite(temp, u32ReadLen, 1, pfd_bin);

}

else

{


need_write_fill=KERNEL_SIZE-read_all_len;

fwrite(temp_fill, need_write_fill, 1, pfd_bin);

read_all_len=0;

printf(“kernel_ok!\n”);

break;

}

}

while(1)

{

u32ReadLen = fread(temp, 1, BUF_SIZE, pfd_rootfs);

if(u32ReadLen>0)

{

read_all_len+=u32ReadLen;

fwrite(temp, u32ReadLen, 1, pfd_bin);

}

#if 1

else

{


need_write_fill=ROOTFS_SIZE-read_all_len;

fwrite(temp_fill, need_write_fill, 1, pfd_bin);

read_all_len=0;

printf(“rootfs_ok!\n”);

break;

}

#endif

}

printf(“5\n”);

fclose(pfd_pmon);

fclose(pfd_kernel);

fclose(pfd_rootfs);

fclose(pfd_bin);

}



版权声明:本文为dongdong12345678900原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。