| 329 | | The ubi root filesystem is originally built by the build system of the specific BSP your using, however if you end up imaging this onto a board, and customizing it, you may be able to pull it back off as long as your flash size is far less than your memory: |
| 330 | | * From Linux assuming /tmp is a tmpfs (ram based) and that you are booted into the filesystem you are copying and you have more ram available than the size of /dev/mtd2 (such as a 256MB flash on a 512MB system) |
| 331 | | {{{#!bash |
| 332 | | dd if=/dev/mtd2 of=/tmp/ubi bs=4M |
| 333 | | }}} |
| 334 | | * From U-Boot |
| 335 | | {{{#!bash |
| 336 | | # read the rootfs (filesystem) partition into temporary memory, note the size reported below as 0xef00000 |
| 337 | | |
| 338 | | Ventana > nand read ${loadaddr} rootfs |
| 339 | | |
| 340 | | NAND read: device 0 offset 0x1100000, size 0xef00000 |
| 341 | | 250609664 bytes read: OK |
| 342 | | |
| 343 | | |
| 344 | | # store it to file on micro-SD with an ext4 fs (size re-used from above) |
| 345 | | Ventana > mmc dev 0 && ext4write mmc 0:1 ${loadaddr} /rootfs 0xef00000 |
| 346 | | switch to partitions #0, OK |
| 347 | | mmc0 is current device |
| 348 | | File System is consistent |
| 349 | | update journal finished |
| 350 | | 250609664 bytes written in 57489 ms (4.2 MiB/s) |
| 351 | | Ventana > |
| 352 | | |
| 353 | | # or store it to file on USB mass storage with an ext4 fs |
| 354 | | usb start && usb dev 0 && ext4write usb 0:1 ${loadaddr} /rootfs 0xef00000 |
| 355 | | }}} |
| 356 | | - Note that your ext4 filesystem must not have checksums enabled (metadata_csum, a feature added to newer e2fsprogs) as U-Boot does not support this in ext4write. |
| | 329 | The ubi root filesystem is originally built by the build system of the specific BSP your using, however if you end up imaging this onto a board, and customizing it, you will not be able to bit-per-bit copy it to another board due to flash geometry changes and bad block mapping on the physical raw NAND parts. |
| | 330 | |
| | 331 | Instead, you will have to boot a ramdisk based Linux rescue image, mount the ubifs and create a tarball of the files which you can then use to re-create a ubi on a Linux development host that can be applied to a new target board via U-Boot or Linux. |
| | 332 | |
| | 333 | Procedure: |
| | 334 | 1. Boot a Linux rescue image that has networking and UBI/EXT4/FAT filesystem support. The [wiki:buildroot#VentanaIMX6 buildroot based image] is suitable for this. You will need to copy the uImage and dtb files from http://dev.gateworks.com/buildroot/ventana/minimal/ to a TFTP server on your network or a removable microSD or USB storage device and boot with one of the following: |
| | 335 | a. boot rescue image from network tftpserver |
| | 336 | {{{#!bash |
| | 337 | setenv bootargs console=ttymxc1,115200 |
| | 338 | setenv fsload tftpboot |
| | 339 | setenv bootdir ventana # set this to the prefix of your tftp dir |
| | 340 | run loadfdt && $fsload $loadaddr $bootdir/uImage && bootm $loadaddr - $fdt_addr |
| | 341 | }}} |
| | 342 | b. boot rescue image from microSD (dev 0 partition 1) with ext/fat filesystem |
| | 343 | {{{#!bash |
| | 344 | setenv bootargs console=ttymxc1,115200 |
| | 345 | setenv fsload load mmc 0:1 |
| | 346 | setenv bootdir . # set this to the prefix of your tftp dir |
| | 347 | run loadfdt && $fsload $loadaddr $bootdir/uImage && bootm $loadaddr - $fdt_addr |
| | 348 | }}} |
| | 349 | c. boot rescue image from USB (dev 0 partition 1) with ext/fat filesystem |
| | 350 | {{{#!bash |
| | 351 | setenv bootargs console=ttymxc1,115200 |
| | 352 | setenv fsload load usb 0:1 |
| | 353 | usb start |
| | 354 | setenv bootdir . # set this to the prefix of your tftp dir |
| | 355 | run loadfdt && $fsload $loadaddr $bootdir/uImage && bootm $loadaddr - $fdt_addr |
| | 356 | }}} |
| | 357 | 2. Mount a filesystem on removable storage (you could use a tmpfs filesystem to do this on a ramdisk if you have enough space): |
| | 358 | {{{#!bash |
| | 359 | mkdir /mnt/removable |
| | 360 | mount /dev/sda1 /mnt/removable |
| | 361 | }}} |
| | 362 | * /dev/sd* would be for USB or mSATA devices and /dev/mmc* would be for microSD devices |
| | 363 | 3. Mount the ubifs: |
| | 364 | {{{#!bash |
| | 365 | ubiattach /dev/ubi_ctrl -m 2 # attach /dev/mtd2 as /dev/ubi0 |
| | 366 | mkdir -p /mnt/ubifs # create a mountpoint for it |
| | 367 | mount -t ubifs ubi0:rootfs /mnt/ubifs # mount 'rootfs' volume |
| | 368 | }}} |
| | 369 | * Note that at this point you could create a tarball of the rootfs if you want to perfor the following steps later or on a Linux development host (tar --numeric-owner -cvzf /mnt/removable/rootfs.tar.gz -C /mnt/ubifs .) |
| | 370 | 4. Create a ubi image for the particular flash geometry of the target device (see wiki:linux/ubi#creatingubi): |
| | 371 | a. 'normal' geometry FLASH devices (2048 byte page size) |
| | 372 | {{{#!bash |
| | 373 | # create a ubifs image |
| | 374 | mkfs.ubifs -F -m 2048 -e 124KiB -c 16248 -x zlib -o /mnt/removable/root.ubifs -d /mnt/ubifs |
| | 375 | # create a ubi image |
| | 376 | cat <<EOF > ubinize.cfg |
| | 377 | [ubifs] |
| | 378 | mode=ubi |
| | 379 | image=/mnt/removable/root.ubifs |
| | 380 | vol_id=0 |
| | 381 | vol_type=dynamic |
| | 382 | vol_name=rootfs |
| | 383 | vol_flags=autoresize |
| | 384 | EOF |
| | 385 | # create ubi suitable for 2048byte page size and 128KiB block size devices |
| | 386 | ubinize -m 2048 -p 128KiB -o /mnt/removable/root.ubi ubinize.cfg |
| | 387 | }}} |
| | 388 | * Note that the mkfs.ubifs process can take quite a bit of time with no output depending on the size of your filesystem; takes about 8 minutes for a 1GiB filesystem |
| | 389 | b. 'large' geometry FLASH devices (4096 byte page size) |
| | 390 | {{{#!bash |
| | 391 | # create a ubif image |
| | 392 | mkfs.ubifs -F -m 4096 -e 248KiB -c 8124 -x zlib -o /mnt/removable/root.ubifs -d /mnt/ubifs |
| | 393 | # create a ubi image |
| | 394 | cat <<EOF > ubinize.cfg |
| | 395 | [ubifs] |
| | 396 | mode=ubi |
| | 397 | image=/mnt/removable/root.ubifs |
| | 398 | vol_id=0 |
| | 399 | vol_type=dynamic |
| | 400 | vol_name=rootfs |
| | 401 | vol_flags=autoresize |
| | 402 | EOF |
| | 403 | # create ubi suitable for 4096byte page size and 256KiB block size devices |
| | 404 | ubinize -m 4096 -p 256KiB -o /mnt/removable/root.ubi ubinize.cfg |
| | 405 | }}} |
| | 406 | * Note that the mkfs.ubifs process can take quite a bit of time with no output depending on the size of your filesystem; takes about 8 minutes for a 1GiB filesystem |
| | 407 | 5. Unmount the filesystems: |
| | 408 | {{{#!bash |
| | 409 | umount /mnt/removable |
| | 410 | umount /mnt/ubifs |
| | 411 | ubidetach /dev/ubi_ctrl -m 2 |
| | 412 | }}} |