你好,游客 登录 注册 搜索
背景:
阅读新闻

君正JZ4770 bootloader中对nand 进行分区

[日期:2013-03-08] 来源:Linux社区  作者:laojing123 [字体:大 中 小]

下面看代码

Makefile

 157 MBR:
 158        gcc  spl/tools/mbr_creater/mbr_creater.c -o spl/tools/mbr_creater/mbr_creater -I$(TOPDIR) -I$(TOPDIR)/include
 159        spl/tools/mbr_creater/mbr_creater mbr.bin

在编译的时候,创建mbr.bin 文件

然后

 152 mbr-xboot.bin:  $(MSC_SPL) MBR $(MBR_XBOOT_DEPEND)
 153        $(MAKE) -C spl pad
 154        cat spl/msc-spl-pad.bin $(X_BOOT2) > x-boot-msc.bin
 155        cat mbr.bin x-boot-msc.bin > mbr-xboot.bin

将此512字节的文件放到bootloader 的顶部。即可完成分区。

下面看下mbr_creater的代码

10
 11 int main(int argc,char *argv[])
 12 {
 13    int fd;
 14
 15    uint32_t p1,ps1;
 16    uint32_t p2,ps2;
 17    uint32_t p3,ps3;
 18    uint64_t p4,ps4;
 19
 20    uint8_t pt1,pt2,pt3,pt4;
 21    uint8_t block[512];
 22
 23    if(argc != 2)
 24    {
 25        printf("usage: %s filename.\n",argv[0]);
 26        exit(0);
 27    }
 28
 29    p1=p2=p3=p4=0;
 30    ps1=ps2=ps3=ps4=0;
 31    pt1=pt2=pt3=pt4=0;
 32
 33    memset(block,0,512);
 34 #ifdef MBR_P1_OFFSET
 35    p1 = MBR_P1_OFFSET;
 36 #endif
 37 #ifdef MBR_P1_SIZE
 38    ps1 = MBR_P1_SIZE;
 39 #endif
 40 #ifdef MBR_P1_TYPE
 41    pt1 = MBR_P1_TYPE;
 42 #endif
 43 /////////////////////////////////////////////////
 44 #ifdef MBR_P2_OFFSET
 45    p2 = MBR_P2_OFFSET;
 46 #endif
 47 #ifdef MBR_P2_SIZE
 48    ps2 = MBR_P2_SIZE;
 49 #endif
 50 #ifdef MBR_P2_TYPE
 51    pt2 = MBR_P2_TYPE;
 52 #endif
 53 /////////////////////////////////////////////////
 54 #ifdef MBR_P3_OFFSET
 55    p3 = MBR_P3_OFFSET;
 56 #endif
 57 #ifdef MBR_P3_SIZE
 58    ps3 = MBR_P3_SIZE;
 59 #endif
 60 #ifdef MBR_P3_TYPE
 61    pt3 = MBR_P3_TYPE;
 62 #endif
 63 /////////////////////////////////////////////////
 64 #ifdef MBR_P4_OFFSET
 65    p4 = MBR_P4_OFFSET;
 66 #endif
 67 #ifdef MBR_P4_SIZE
 68    ps4 = MBR_P4_SIZE;
 69 #endif
 70 #ifdef MBR_P4_TYPE
 71    pt4 = MBR_P4_TYPE;
 72 #endif
 73 /////////////////////////////////////////////////
 74    block[0x1fe] = 0x55;
 75    block[0x1ff] = 0xaa;
 76
 77    p1 /= 512;
 78    p2 /= 512;
 79    p3 /= 512;
 80    p4 /= 512;
 81
 82    ps1 /= 512;
 83    ps2 /= 512;
 84    ps3 /= 512;
 85    ps4 /= 512;
 86
 87    memcpy(block+0x1c6,&p1,sizeof(uint32_t));
 88    memcpy(block+0x1d6,&p2,sizeof(uint32_t));
 89    memcpy(block+0x1e6,&p3,sizeof(uint32_t));
 90    memcpy(block+0x1f6,&p4,sizeof(uint32_t));
 91
 92    memcpy(block+0x1ca,&ps1,sizeof(uint32_t));
 93    memcpy(block+0x1da,&ps2,sizeof(uint32_t));
 94    memcpy(block+0x1ea,&ps3,sizeof(uint32_t));
 95    memcpy(block+0x1fa,&ps4,sizeof(uint32_t));
 96
 97    memcpy(block+0x1c2,&pt1,sizeof(uint8_t));
 98    memcpy(block+0x1d2,&pt2,sizeof(uint8_t));
 99    memcpy(block+0x1e2,&pt3,sizeof(uint8_t));
100    memcpy(block+0x1f2,&pt4,sizeof(uint8_t));
101 /////////////////////////////////////////////////
102
103    fd = open(argv[1],O_RDWR | O_TRUNC | O_CREAT,0777);
104    if(fd < 0)
105    {
106        printf("open %s failed.\n",argv[1]);
107        exit(1);
108    }
109
110    write(fd,block,512);
111
112    close(fd);
113    return 0;
114 }
115
代码比较简单,将4个分区的偏移,大小,以及文件系统的类型定义好,然后写到mbr扇区的相应位置就可以了。                                                                                                                                                                                               
~                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       
~ 

linux
相关资讯       Bootloader  君正JZ4770  nand分区 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款