Changes between Version 28 and Version 29 of linux/ubi


Ignore:
Timestamp:
06/24/2020 06:10:06 PM (4 years ago)
Author:
Tim Harvey
Comment:

add detailed examples of ubi and ubifs access in U-Boot

Legend:

Unmodified
Added
Removed
Modified
  • linux/ubi

    v28 v29  
    359359== Working with UBI in U-boot Bootloader ==
    360360[=#ubiinuboot]
    361 The U-boot bootloader used by Ventana has support for ubi:
    362  * mounting a ubi
     361The U-boot bootloader has support for ubi and ubifs. Before working with a ubi image you need to 'attach' an MTD partition, then you can mount and work with ubifs filesystem images. Note that you can remove/create ubi volumes and you can ls and load from ubifs filesystem images but you cant write to ubifs filesystems:
     362 * determining MTD partition containing ubi's:
     363{{{#!bash
     364Ventana > mtd
     365
     366device nand0 <nand>, # parts = 3
     367 #: name                size            offset          mask_flags
     368 0: uboot               0x01000000      0x00000000      0
     369 1: env                 0x00100000      0x01000000      0
     370 2: rootfs              0x7ef00000      0x01100000      0
     371
     372active partition: nand0,0 - (uboot) 0x01000000 @ 0x00000000
     373
     374defaults:
     375mtdids  : nand0=nand
     376mtdparts: mtdparts=nand:16m(uboot),1m(env),-(rootfs)
     377}}}
     378  - The above shows there is one RAW NAND device (nand0) and it is partitioned into 3 sections: uboot (from 0x00000000 to 0x01000000), uboot env (from 0x01000000 to 0x01100000) and rootfs (from 0x01100000 to 0x7ef00000). The 'uboot' and 'env' are part of the boot firmware, so the section named 'rootfs' is the section that can contain ubi's
     379  - Note that this partitioning is solely based on the 'mtdids' and 'mtdparts' U-Boot env variables and can be changed if desired. Note also that these variables are used to send information into the kernel so that the kernel creates these sections as specific MTD devices
     380 * attaching a ubi image to an MTD partition:
     381{{{#!bash
     382Ventana > ubi part rootfs
     383ubi0: default fastmap pool size: 256
     384ubi0: default fastmap WL pool size: 128
     385ubi0: attaching mtd1
     386ubi0: scanning is finished
     387ubi0: attached mtd1 (name "mtd=2", size 2031 MiB)
     388ubi0: PEB size: 131072 bytes (128 KiB), LEB size: 126976 bytes
     389ubi0: min./max. I/O unit sizes: 2048/2048, sub-page size 2048
     390ubi0: VID header offset: 2048 (aligned 2048), data offset: 4096
     391ubi0: good PEBs: 16248, bad PEBs: 0, corrupted PEBs: 0
     392ubi0: user volume: 3, internal volumes: 1, max. volumes count: 128
     393ubi0: max/mean erase counter: 2/0, WL threshold: 4096, image sequence number: 1592951068
     394ubi0: available PEBs: 0, total reserved PEBs: 16248, PEBs reserved for bad PEB handling: 320
     395}}}
     396  - The above 'attaches' a ubi image to an MTD partition (equivalent to ubiattach in Linux) so that you can mount ubi volumes. Note that this operation can take several seconds as it must scan the entire ubi image to construct a bad block table (unless [#fastmap fastmap] is used). Once attached you can use {{{ubifsmount}}} and you will need to detach via {{{ubi detach}}} before attaching another or when done using it.
     397 * showing ubi volumes that exist in a ubi image:
     398{{{#!bash
     399Ventana > ubi info layout
     400Volume information dump:
     401        vol_id          0
     402        reserved_pebs   124
     403        alignment       1
     404        data_pad        0
     405        vol_type        3
     406        name_len        4
     407        usable_leb_size 126976
     408        used_ebs        124
     409        used_bytes      15745024
     410        last_eb_bytes   126976
     411        corrupted       0
     412        upd_marker      0
     413        name            boot
     414Volume information dump:
     415        vol_id          1
     416        reserved_pebs   210
     417        alignment       1
     418        data_pad        0
     419        vol_type        3
     420        name_len        6
     421        usable_leb_size 126976
     422        used_ebs        210
     423        used_bytes      26664960
     424        last_eb_bytes   126976
     425        corrupted       0
     426        upd_marker      0
     427        name            rootfs
     428Volume information dump:
     429        vol_id          2
     430        reserved_pebs   15586
     431        alignment       1
     432        data_pad        0
     433        vol_type        3
     434        name_len        11
     435        usable_leb_size 126976
     436        used_ebs        15586
     437        used_bytes      1979047936
     438        last_eb_bytes   126976
     439        corrupted       0
     440        upd_marker      0
     441        name            rootfs_data
     442Volume information dump:
     443        vol_id          2147479551
     444        reserved_pebs   2
     445        alignment       1
     446        data_pad        0
     447        vol_type        3
     448        name_len        13
     449        usable_leb_size 126976
     450        used_ebs        2
     451        used_bytes      253952
     452        last_eb_bytes   2
     453        corrupted       0
     454        upd_marker      0
     455        name            layout volume
     456}}}
     457  - The above shows there are 3 ubi volumes in the attached ubi image named 'boot', 'rootfs', 'rootfs_data'. Note the last dump is the volume layout (think of it as a directory table)
     458  - Note the contents of the various ubi volumes is unknown by the ubi layer
     459 * once a ubi volume is mounted 'if' it is a ubifs you can use {{{ubifsmount}}}, {{{ubifsload}}}, {{{ubifsls}}}, {{{ubifsumount}}} to operate on its contents:
     460{{{#!bash
     461Ventana > ubifsmount ubi0:boot
     462Ventana > ubifsls
     463<LNK>          31  Tue Jun 23 23:51:55 2020  imx6q-gw53xx.dtb
     464            38158  Tue Jun 23 23:47:33 2020  gateworks-imx6-imx6q-gw5400-a.dtb
     465            41991  Tue Jun 23 23:47:30 2020  gateworks-imx6-imx6dl-gw53xx.dtb
     466            43296  Tue Jun 23 23:47:33 2020  gateworks-imx6-imx6q-gw53xx.dtb
     467<LNK>          32  Tue Jun 23 23:51:55 2020  imx6dl-gw53xx.dtb
     468...
     469          3275024  Tue Jun 23 23:51:55 2020  gateworks-imx6-uImage
     470<LNK>          21  Tue Jun 23 23:51:55 2020  uImage
     471Ventana > ubifsload $loadaddr uImage
     472Loading file 'uImage' to addr 0x12000000...
     473Done
     474Ventana > ubifsumount
     475Unmounting UBIFS volume boot!
     476}}}
     477  - Again you can only use ubifs commands on ubi volumes that contain ubifs filesystems
     478  - Be sure to unmount your volume when done working with it
    363479 * removing ubi volumes
     480{{{#!bash
     481Ventana > ubi remove rootfs_data
     482Remove UBI volume rootfs_data (id 2)
     483Ventana > ubi remove rootfs
     484Remove UBI volume rootfs (id 1)
     485}}}
    364486 * creating ubi volumes
     487{{{#!bash
     488Ventana > ubi create rootfs a00000 static
     489Creating static volume rootfs of size 10485760
     490}}}
    365491 * writing ubi volumes
     492{{{#!bash
     493Ventana > tftp $loadaddr ventana/test_large.ubifs
     494Using FEC device
     495TFTP from server 192.168.1.146; our IP address is 192.168.1.1
     496Filename 'ventana/test_large.ubifs'.
     497Load address: 0x12000000
     498Loading: #################################################################
     499         #################################################################
     500         #################################################################
     501         #################################################################
     502         #################################################################
     503         #################################################################
     504         #################################################################
     505         #################################################################
     506         #################################################################
     507         #################################################################
     508         #################################################################
     509         ############
     510         8.1 MiB/s
     511done
     512Bytes transferred = 10665984 (a2c000 hex)
     513Ventana > ubi remove rootfs
     514Remove UBI volume rootfs (id 1)
     515Ventana > ubi create rootfs $filesize static                     
     516Creating static volume rootfs of size 10665984
     517Ventana > ubi write $loadaddr rootfs $filesize
     51810665984 bytes written to volume rootfs
     519}}}
    366520
    367521[=#BasicMethod]
     
    381535run nand_update
    382536}}}
    383 
    384537
    385538The more manual method without using the {{{nand_update}}} script, if your ubi image is on a tftp server as image.ubi you can use the following to update the 'rootfs' NAND FLASH partition in U-Boot (update the ip addresses as appropriate for your network environment):
     
    449602The following environment variables need to be set in order for this script to run:
    450603
    451     splitfile    - full path file name prefix of the splitted files (eg file.ubi for file.ubi.part00)
     604    splitfile    - full path file name prefix of the split files (eg file.ubi for file.ubi.part00)
    452605}}}
    453606  An example configuration: