mtparts & dts partition

Uboot: bootargs  mtdparts=4m(kernel:0),25856k(rootfs:0)设置分区

 

Uboot传给内核mtdparts分区表优先级高于在flash在设备树中的分区表

 

/**

 *mtd_device_parse_register - parse partitions and register an MTD device.

 *

 *@mtd: the MTD device to register

 *@types: the list of MTD partition probes to try, see

 *        'parse_mtd_partitions()' for more information

 *@parser_data: MTD partition parser-specific data

 *@parts: fallback partition information to register, if parsing fails;

 *        only valid if %nr_parts > %0

 *@nr_parts: the number of partitions in parts, if zero then the full

 *           MTD device is registered if no partition info is found

 *

 *This function aggregates MTD partitions parsing (done by

 *'parse_mtd_partitions()') and MTD device and partitions registering. It

 *basically follows the most common pattern found in many MTD drivers:

 *

 * *It first tries to probe partitions on MTD device @mtd using parsers

 *  specified in @types (if @types is %NULL, then the default list ofparsers

 *   isused, see 'parse_mtd_partitions()' for more information). If none are

 *  found this functions tries to fallback to information specified in

 *  @parts/@nr_parts.

 * *If any partitioning info was found, this function registers the found

 *  partitions.

 * *If no partitions were found this function just registers the MTD device

 *   @mtdand exits.

 *

 *Returns zero in case of success and a negative error code in case of failure.

 */

int mtd_device_parse_register(structmtd_info *mtd, const char * const *types,

                                  struct mtd_part_parser_data *parser_data,

                                  const struct mtd_partition *parts,

                                  int nr_parts)

{

         interr;

         structmtd_partition *real_parts;

 

         //首先尝试从mtdparts获取分区表

         err= parse_mtd_partitions(mtd, types, &real_parts, parser_data);

         if(err <= 0 && nr_parts && parts) {

        

                   //其次从flash所在设备树结点获取分区表

                   real_parts= kmemdup(parts, sizeof(*parts) * nr_parts,

                                          GFP_KERNEL);

                   if(!real_parts)

                            err= -ENOMEM;

                   else

                            err= nr_parts;

         }

         //建立分区设备

         if(err > 0) {

                   err= add_mtd_partitions(mtd, real_parts, err);

                   kfree(real_parts);

         }else if (err == 0) {

                   err= add_mtd_device(mtd);

                   if(err == 1)

                            err= -ENODEV;

         }

 

         returnerr;

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值