马上注册 登录
中文乐高 返回首页

t_fisher的个人空间 https://bbs.cmnxt.com/?37285 [收藏] [复制] [分享] [RSS]

日志

利用官方固件搭建EV3自制系统-附录

热度 1已有 773 次阅读2014-7-10 21:07 |个人分类:EV3

提取uImage程序
#include <unistd.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <sys/stat.h>

int main()
{
    int ifd,ofd;
    int begin = 0x50000;
    int end   = 0x249999;
    struct stat st;
    unsigned char* ptr;
    char* fname ="EV3 Firmware V1.06E.bin";
    char* ofile ="uImage";
    ifd = open(fname,O_RDONLY);
    if(ifd == -1)
        return -1;

    ofd = open(ofile,O_CREAT | O_TRUNC | O_RDWR,0664);
    if(ofd == -1)
        return -1;
    fstat(ifd,&st);

    ptr = mmap(NULL,st.st_size,PROT_READ,MAP_SHARED,ifd,0);
    if(ptr == MAP_FAILED)
        return -1;

    while(ptr[end] == 0xFF && end > begin )
        end--;
    write(ofd,ptr+begin, end-begin+1);
    munmap(ptr,st.st_size);
    close(ofd);
    close(ifd);
    return 0;
}


路过
1

雷人

握手

鲜花

鸡蛋

刚表态过的朋友 (1 人)

发表评论 评论 (1 个评论)

回复 struct 2016-8-8 07:15

facelist

您需要登录后才可以评论 登录 | 马上注册

QQ|手机版|中文乐高 ( 桂ICP备13001575号-7 )

GMT+8, 2024-5-20 21:53 , Processed in 0.048199 second(s), 21 queries .

Powered by Discuz! X3.5

Copyright © 2001-2020, Tencent Cloud.

返回顶部