flash bin文件合成

#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);

}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值