close
 

I:修改mtd block partition size




1.修改kernel 原始碼




arch/arm/mach-xx/devices.c


static struct mtd_partition nand_partitions[] = {


{


.name = "Boot Area",


.offset = 0x40000, //0x40000 - 0x80000 //0.25M


.size = 256 * 1024,


},


{


.name = "Diag Area",


.offset = MTDPART_OFS_APPEND, //0x80000 - 0x180000 //1M


.size = 1 * 1024 * 1024,


},


{


.name = "Kernel",


.offset = MTDPART_OFS_APPEND, //0x180000 - 0x1500000 //19.5M


.size = 19 * 1024 * 1024 + 512 * 1024,


},


{


.name = "Root Filesystem",


.offset = MTDPART_OFS_APPEND, //0x1500000 - 0x3500000 - 32M


.size = 32 * 1024 * 1024,//32


},


{


.name = "opt",


.offset = MTDPART_OFS_APPEND, //0x3500000 - 0x6d00000 -56M


.size = 56 * 1024 * 1024 ,


},


{


.name = "demo",


.offset = MTDPART_OFS_APPEND, //0x6d00000 - 0x8000000 - 19M


.size = MTDPART_SIZ_FULL,


},


};


#endif




2.重開測試


Creating 6 MTD partitions on "NAND 128MiB 3,3V 8-bit":
0x00040000-0x00080000 : "Boot Area"
0x00080000-0x00180000 : "Diag Area"
0x00180000-0x01500000 : "Kernel"
0x01500000-0x03500000 : "Root Filesystem"
0x03500000-0x06d00000 : "opt"
0x06d00000-0x08000000 : "demo"






3.建立檔案系統影像檔
如下建立56M


echo "mk opt 56M"


dd if=/dev/zero of=opt56m bs=56M count=1


mke2fs -F opt56m


mkdir -p tmp


mount -o loop opt56m tmp


cd tmp


cp -a ../opt/* ./


cd ..


umount tmp


rm -r tmp




cp -f opt56m /tftpboot




4.燒錄到nand flash


setenv nopt tftp 40800000 opt56m\;nand erase 3500000 3800000\;nand write 40800000 3500000 3800000




run nopt




5.若不想修改kernel 則可使用kernle 帶參數設定mtd大小




Kernel 需支援傳遞mtd參數


Device Drivers --->
     Memory Technology Device (MTD) support --->
          [*] MTD partitioning support
          [*] Command line partition table parsing



u-boot 參數






參數格式如下


linux command mtdparts 格式:
mtdparts   = <mtddef>[;<mtddef ]
<mtddef>  := <mtd-id>:<partdef>[,<partdef>]
<partdef> := <size>[@offset][<name>][ro]
<mtd-id>  := unique id used in mapping driver/device
<size>      := standard linux memsize OR "-" to denote all
remaining space
<name>    := (NAME)


EX:


mtdparts=xx-nand: @ ( ), @ ( )




xx-nand 這個必須與kernel 一致


@ ( ) 必須都有


最後不要有 , 句號 否會出現size 太小錯誤(因逗號後面也當作一個新的分割區)




實測;
u-boot下執行下命令


set k27mtd setenv bootargs console=ttyS0,115200n8 root=/dev/mtdblock6 rw init=/linuxrc mtdparts=xx-nand:32m@0x01500000(rootfs),56m@0x03500000(qt),19m@0x06d00000(demo)\;tftp 41000000 uImage_k27_src\;bootm 41000000




測試結果


 


3 cmdlinepart partitions found on MTD device xx-nand


MTD:nr_partitions = 3


MTD:new partition rootfs offset 0x1500000 size 0x2000000


MTD:new partition qt offset 0x3500000 size 0x3800000


MTD:new partition demo offset 0x6d00000 size 0x1300000


Creating 6 MTD partitions on "xx-nand":


0x00040000-0x00080000 : "Boot Area"


0x00080000-0x00180000 : "Diag Area"


0x00180000-0x01500000 : "Kernel"


0x01500000-0x03500000 : "rootfs"


0x03500000-0x06d00000 : "qt"


0x06d00000-0x08000000 : "demo"


上面的結果 因為有修改KERNEL程式碼 保留 前三塊 所以才會總共六塊


 


 


但是 s3c2410.c 並沒有把 linux command mtdparts 實做出來。
難怪怎麼測試都沒反應。

修改 linux/driver/mtd/nand/s3c2410.c:


#ifdef CONFIG_MTD_PARTITIONS

#ifdef CONFIG_MTD_CMDLINE_PARTS 
const char *part_probes[] = { "cmdlinepart", NULL };
#endif


static int s3c2410_nand_add_partition(struct s3c2410_nand_info *info,
                                      struct s3c2410_nand_mtd *mtd,
                                      struct s3c2410_nand_set *set)
{
#ifdef CONFIG_MTD_CMDLINE_PARTS 
        struct mtd_partition *partitions = NULL;
        int num_partitions = 0;
#endif
        if (set == NULL)
                return add_mtd_device(&mtd->mtd);

#ifdef CONFIG_MTD_CMDLINE_PARTS
        mtd->mtd.name = "s3c2440_nand";
        num_partitions = parse_mtd_partitions(&(mtd->mtd), part_probes, &partitions, 0);

        if(num_partitions > 0) {
            set->partitions = partitions;
            set->nr_partitions = num_partitions;
        }
#endif

        if (set->nr_partitions > 0 && set->partitions != NULL) {
             return add_mtd_partitions(&mtd->mtd, set->partitions, set->nr_partitions);
        } 
        return add_mtd_device(&mtd->mtd);
}

#else
........ }


這樣就可以在 linux command line 裡面把分區傳給 kernel
使用方法
mtdparts=s3c2440_nand:<size1>@<offset1>(<name1>),<size2>@<offset2>(<name2>)

其中 "s3c2440_nand" 要跟 mtd->mtd.name 一樣

arrow
arrow
    全站熱搜

    立你斯 發表在 痞客邦 留言(0) 人氣()