Chinaunix首页 | 论坛 | 博客
  • 博客访问: 62561
  • 博文数量: 11
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 100
  • 用 户 组: 普通用户
  • 注册时间: 2015-03-24 12:34
文章分类
文章存档

2019年(3)

2018年(8)

我的朋友

分类: LINUX

2018-11-22 15:06:01

################################################################################
# mtdparts of u-boot
#     mtdparts 主要是u-boot 中对环境变量或者默认配置 env
#       mtdids="nand0=VENDOR-nand"
#       mtdparts="mtdparts=VERDOR-nand:1M(U-BOOT),1M(bootargs)...,-(other)"
#     进行解析, common/cmd_mtdparts.c 主要的核心工作:
#       <1> 支持对mtdids, mtdparts字符串格式解析成2个核心链表(linux 通用双向带头循环链表)
#             (此过程中会验证是否存在 当前 NVM 设备, 也是cmd_mtdparts.c
#               唯一一个依赖外部的接口: linux/mtd:
#                 int mtd_device_validate(u8 type, u8 num, u32 *size);
#                 struct mtd_info *get_mtd_device_nm(const char *name); // 被依赖MTD接口
#               // 2 个链表: struct list_head mtdids; struct list_head devices;
#       <2> 记录了当前正在使用的 mtd 设备信息: 当前设备, 当前分区, 所有设备分区统一编号
#           struct mtd_device *current_mtd_dev = NULL;
#           u8 current_mtd_partnum = 0;
#           比较相关的接口 : int mtd_devices_init(void); void current_save(void);
#
#   总体上看 : mtdparts 命令 针对某一个已经存在的mtd设备进行分区
#       (解析分区信息, 分区信息存储到链表, 无核心算法或者设备操作(依赖于mtd) )
#




################################################################################
# 1. u-boot intrduction of ubi in the u-boot.git
#   []
# 2. usage of ubi in the u-boot
# 3. details of ubi/ubifs/mtdparts
# 3.1 mtdparts (linux MTD)
# 3.2 ubi part NAME OFFSET
# 3.3 ubi info [layout]
# 3.4 ubifsmount VOLUME
# 3.5 ubifsls                   # Current Volume
# 3.6 ubifsload ADDR FILENAME   # Current Volume
# 3.7 ubi volume management: create/write/read/remove
# 4. linux MTD/u-boot mtdids (parse_mtdids)
# 4.1 query API: drivers/mtd/mtdcore.c 基于引用计数的 API (get_mtd_device_nm, put_mtd_device)
# 4.2 registre/unregister API (add_mtd_device, del_mtd_device)
# 4.3 drivers (drivers/mtd/mtdpart.c, drivers/mtd/nand/nand.c)
# 5. nand for mtd (arch/arm/lib/board.c void nand_init())
# 6. mtd (do_ubi/ubi_dev_scan, add_mtd_partitios)




################################################################################
# 1. u-boot intrduction of ubi in the u-boot.git
# []
#
| * | | | | 3b089e4f889a2902449d55e081c886ae607cae89 UBI: Set ubi_dev.type back to DEV_TYPE_NONE upon failing initialization
| * | | | | 817329351639a8895cd9b87b33aeff043f3d5a44 UBI: Return -ENOMEM upon failing malloc
| * | | | | 2d2e05727fe4013f807ffa814dff0e75259a1db4 UBI: Fix size parsing in "ubi create"
| * | | | | 2ee951ba2ac9874d2a93d52e7a187d3184be937e UBI: Enable re-initializing of the "ubi part" command
| * | | | | 9def12cae33d2d3ea2dd56b197fd3dfb3ad60bf4 MTD: Fix problem based on non-working relocation (list head mtd_partitions)


* | | |   f9b354faa0417b7f8888de246ff5f267f7cb17f2 Merge branch 'master' of git://git.denx.de/u-boot-ubi
|\ \ \ \
| * | | | 25ea652e907516a283b38237e83712a918f125d7 UBI: Add proof-of-concept CFI flash support
| * | | | e6a7edbc1778d27431ac663b40a71dafa5d20578 mtd: Remove a printf() from add_mtd_device().
| * | | | a5c4067017631d903e1afa6ad615f0ce19fea517 UBI: Change parsing of size in commands to default to hex
| * | | | 8000b086b33a5a81f3f390f37e178db7956dc08b ARM: Add Apollon UBI support
| * | | | 694a0b3f1c0accd0de94b89555155d69f8022824 UBI: Add UBI command support
| * | | | 58be3a1056d88c6d05f3e914389282807e69923a UBI: Add basic UBI support to U-Boot (Part 8/8)
| * | | | 47ae6693f54f80455ae32c2e0d995e0e4bdc15b9 UBI: Add basic UBI support to U-Boot (Part 7/8)
| * | | | 7e6ee7ad27de5216db1baef76f38c3429c8f4a2a UBI: Add basic UBI support to U-Boot (Part 6/8)
| * | | | c91a719daa331b5856109313371e4ece5ec06d96 UBI: Add basic UBI support to U-Boot (Part 5/8)
| * | | | f412fefa079c6aa9a9763f6869bf787ea6bf6e1b UBI: Add basic UBI support to U-Boot (Part 4/8)
| * | | | 2d262c4853cb5b6ddce1a28a9641f2de3688d7ea UBI: Add basic UBI support to U-Boot (Part 3/8)
| * | | | 961df83361aff9a14f226214224eb8a06e05ba24 UBI: Add basic UBI support to U-Boot (Part 2/8)
| * | | | f399d4a281713d5ef2d764f05d545fe61e3bd569 UBI: Add basic UBI support to U-Boot (Part 1/8)
| * | | | e29c22f5abe6e0f4baa6251efed6074cdfc3db79 MTD: Add MTD paritioning infrastructure




################################################################################
# 2. usage of ubi in the u-boot


# 2.1 u-boot env of mtdids and mtdparts


e.g. // TODO REMOVE VERDOR specific :
        KEY WORDS: VERDOR-nand, VerdorRes1, VerdorRes2, VerdorRes3, VerdorRes4, VerdorRes5, VerdorRes6, U-BOOT
mtdparts=mtdparts=VERDOR-nand:1M(boot),1M(bootargs),1M(VerdorRes1),1M(VerdorRes2),1M(VerdorRes3),1M(VerdorRes4),1M(VerdorRes5),1M(VerdorRes6),8M(loader),5M(kernel),64M(rootfs),8M(res1),16M(res2),-(others)
mtdids=nand0=VERDOR-nand


# 2.2 commands of ubi


# <0> precondicition: mtd partition of ubifs  (e.g. res1 res2)
# <1> mtdparts
# <2> ubi commands:
#       ubi     - ubi commands
#       ubifsload- load file from an UBIFS filesystem
#       ubifsls - list files in a directory
#       ubifsmount- mount UBIFS volume
U-BOOT# help ubi
ubi - ubi commands


Usage:
ubi part [part] [offset]
 - Show or set current partition (with optional VID header offset)
ubi info [l[ayout]] - Display volume and ubi layout information
ubi create[vol] volume [size] [type] - create volume name with size
ubi write[vol] address volume size - Write volume from address with size
ubi read[vol] address volume [size] - Read volume to address with size
ubi remove[vol] volume - Remove volume
[Legends]
 volume: character name
 size: specified in bytes
 type: s[tatic] or d[ynamic] (default=dynamic)




U-BOOT# mtdparts


device nand0 , # parts = 14
 #: name                size            offset          mask_flags
 0: boot                0x00100000      0x00000000      0
 1: bootargs            0x00100000      0x00100000      0
 2: VerdorRes1          0x00100000      0x00200000      0
 3: VerdorRes2          0x00100000      0x00300000      0
 4: VerdorRes3          0x00100000      0x00400000      0
 5: VerdorRes4          0x00100000      0x00500000      0
 6: VerdorRes5          0x00100000      0x00600000      0
 7: VerdorRes6          0x00100000      0x00700000      0
 8: loader              0x00800000      0x00800000      0
 9: kernel              0x00500000      0x01000000      0
10: rootfs              0x04000000      0x01500000      0
11: res1                0x00800000      0x05500000      0
12: res2                0x01000000      0x05d00000      0
13: others              0x01300000      0x06d00000      0


active partition: nand0,0 - (boot) 0x00100000 @ 0x00000000


defaults:
mtdids  : none
mtdparts: none




U-BOOT# ubi part
Error, no UBI device/partition selected!


U-BOOT# ubi part res1 2048
Creating 1 MTD partitions on "nand0":
0x000005500000-0x000005d00000 : "mtd=11"
UBI: attaching mtd1 to ubi0
UBI: physical eraseblock size:   131072 bytes (128 KiB)
UBI: logical eraseblock size:    126976 bytes
UBI: smallest flash I/O unit:    2048
UBI: sub-page size:              1024
UBI: VID header offset:          2048 (aligned 2048)
UBI: data offset:                4096
UBI: attached mtd1 to ubi0
UBI: MTD device name:            "mtd=11"
UBI: MTD device size:            8 MiB
UBI: number of good PEBs:        64
UBI: number of bad PEBs:         0
UBI: max. allowed volumes:       128
UBI: wear-leveling threshold:    4096
UBI: number of internal volumes: 1
UBI: number of user volumes:     1
UBI: available PEBs:             18
UBI: total number of reserved PEBs: 46
UBI: number of PEBs reserved for bad PEB handling: 2
UBI: max/mean erase counter: 2/1


U-BOOT# ubifsmount res1fs # precondicition ubifs in res1
UBIFS: mounted UBI device 0, volume 0, name "res1fs"
UBIFS: mounted read-only
UBIFS: file system size:   3809280 bytes (3720 KiB, 3 MiB, 30 LEBs)
UBIFS: journal size:       1269760 bytes (1240 KiB, 1 MiB, 10 LEBs)
UBIFS: media format:       w4/r0 (latest is w4/r0)
UBIFS: default compressor: LZO
UBIFS: reserved for root:  0 bytes (0 KiB)


U-BOOT# ubifsls           # precondicition ubifs in res1
               25  Wed Nov 21 02:37:59 2018  date
               12  Wed Nov 21 02:38:06 2018  README


U-BOOT# ubifsload 2000000 date    # precondicition ubifs in res1
Loading file 'date' to addr 0x02000000 with size 25 (0x00000019)...
Done
U-BOOT# md 2000000 64             # precondicition ubifs in res1
02000000: 20756854 206e614a 30203120 31303a31    Thu Jan  1 01:01
02000010: 2037333a 30373931 0000000a 00000000    :37 1970........


U-BOOT# ubifsload 2000000 README
Loading file 'README' to addr 0x02000000 with size 12 (0x0000000c)...
Done
U-BOOT# md 2000000 32
02000000: 6c6c6568 6f77206f 0a646c72 00000000    hello world.....
02000010: 00000000 00000000 00000000 00000000    ................
U-BOOT# md.b 2000000
02000000: 68 65 6c 6c 6f 20 77 6f 72 6c 64 0a 00 00 00 00    hello world.....






# 3. details of ubi/ubifs/mtdparts
# 3.1 mtdparts (linux MTD)
/** mtdparts_init:
 *
 *  <1> ENV:
 *        mtdids    DEFAULT: mtdids_default(MTDIDS_DEFAULT)       LIMIT: MTDIDS_MAXLEN
 *        mtdparts  DEFAULT: mtdparts_default(MTDPARTS_DEFAULT)   LIMIT: MTDPARTS_MAXLEN
 *        partition DEFAULT: NULL
 *
 *  <2> DATE STRUCTURE:
 *        initialized/status  :  DEFAULT  = 0
 *        index               :
 *                                last_ids    = 0
 *                                last_parts  = 0
 *                                last_partition = 0
 *        list                :
 *                                mtdids  (empty)
 *                                devices (empty)
 *
 *  <3> parse_mtdids(), mtd_devices_init(), parse_mtdparts()
 *    .1 初始化全局数据(变量或者数据结构)
 *    .2 Check env mtdids and sync env mtdids, enabled MTDIDS_DEFAULT
 *    .3 Check env mtdparts and sync env mtdparts, disabled MTDPARTS_DEFAULT
 *    .4 Check env partition and sync current_mtd
 *
 *    .2 Check env mtdids and sync env mtdids
 *        struct list_head mtdids;                    // list head of mtdids
 *
 *        int parse_mtdids(const char *const ids);    // 解析用户 mtdids 字符串为到 list mtdids中
 *                                                    //     delete/clean global mtdids list
 *                                                    //     mtd_id_parse : 标准化 NVM 类型 (type, number) MTD_DEV_TYPE_*,
 *                                                    //        e.g. nand0=xxxx   // 已解析 "nand0"
 *
 *
 *    .3 Check env mtdparts and sync env mtdparts
 *        struct list_head devices;                         // list head of devices
 *
 *        int parse_mtdparts(const char *const mtdparts);   // 解析用户 mtdparts 字符串到 devices 中
 *                                                          //     delete all devices and partitions
 *                                                          //
 *                                                          //
 *                                                          //
 *                                                          //
 */
int mtdparts_init(void);            // all first call of u-boot cmd: mtdparts
int mtd_devices_init(void);
void list_partitions(void);
int do_mtdparts(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);




# 3.2 ubi part NAME OFFSET
# 3.3 ubi info [layout]
# 3.4 ubifsmount VOLUME
# 3.5 ubifsls                   # Current Volume
# 3.6 ubifsload ADDR FILENAME   # Current Volume
# 3.7 ubi volume management: create/write/read/remove






// u-boot
struct part_info* mtd_part_info(struct mtd_device *dev, unsigned int part_num);
void index_partitions(void);      // env: mtddevnum, mtddevname
                                  // global:  current_mtd_dev, current_mtd_partnum
void current_save(void);    // env      partition:            DEPENDS ON current_mtd_dev, current_mtd_partnum
                            // global   last_partition:       DEPENDS ON current_mtd_dev, current_mtd_partnum
                            // env      mtddevnum, mtddevname DEPENDS ON current_mtd_dev, current_mtd_partnum


void part_delall(struct list_head *head);
int device_delall(struct list_head *head);
int mtd_devices_init(void);   // global   clear last_parts, null current_mtd_dev and then current_save(),
                              // global   devices(and all partitions of a device)


int device_parse(const char *const mtd_dev, const char **ret, struct mtd_device **retdev);
struct mtdids* id_find_by_mtd_id(const char *mtd_id, unsigned int mtd_id_len);
char *strchr(const char *s, int c);     // ':' ';'
struct mtd_device *device_find(u8 type, u8 num);    // find mtd devcie By Key(type, num)
int part_parse(const char *const partdef, const char **ret, struct part_info **retpart);
unsigned long memsize_parse (const char *const ptr, const char **retptr); // simple_strtoul
// MIN_PART_SIZE, OFFSET_NOT_SPECIFIED, SIZE_REMAINING
int part_validate_eraseblock(struct mtdids *id, struct part_info *part); // part->sector_size = mtd->erasesize;
int part_sort_add(struct mtd_device *dev, struct part_info *part);
int part_del(struct mtd_device *dev, struct part_info *part);
void part_delall(struct list_head *head);
int device_del(struct mtd_device *dev);
void *malloc(size_t size);


void list_partitions(void);




int find_dev_and_part(const char *id, struct mtd_device **dev, u8 *part_num, struct part_info **part); // mtdid, or nand0
current_mtd_dev
current_mtd_partnum
void current_save(void);    // env      partition:            DEPENDS ON current_mtd_dev, current_mtd_partnum
                            // global   last_partition:       DEPENDS ON current_mtd_dev, current_mtd_partnum
                            // env      mtddevnum, mtddevname DEPENDS ON current_mtd_dev, current_mtd_partnum


# 4. linux MTD/u-boot mtdids (parse_mtdids)
# 4.1 query API: drivers/mtd/mtdcore.c 基于引用计数的 API (get_mtd_device_nm, put_mtd_device)
#         struct mtd_info *get_mtd_device_nm(const char *name);
#         void put_mtd_device(struct mtd_info *mtd);
# 4.2 registre/unregister API (add_mtd_device, del_mtd_device)
#         int add_mtd_device(struct mtd_info *mtd); // 默认引用计数为0
#         int del_mtd_device(struct mtd_info *mtd); // 只有当引用计数为0才能删除
# 4.3 drivers (drivers/mtd/mtdpart.c, drivers/mtd/nand/nand.c)


# 5. nand for mtd (arch/arm/lib/board.c void nand_init())
# 6. mtd (do_ubi/ubi_dev_scan, add_mtd_partitios)

阅读(7577) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~