602 | | To work around this limitation Gateworks has created an installable U-Boot script that will apply UBI files containing a single partition image. This can be particularly useful for updating the firmware of a running target. |
| 604 | In order to flash a UBI in this situation within U-Boot you must either split the UBI image into chunks and transfer/flash each chunk, or you can use U-Boot to create a UBI volume and split the UBIFS and transfer/flash each chunk of the UBIFS. Flashing a UBI has the disadvantage of erasing all the NAND wear leveling information the UBI has been tracking and won't support the special handling of bad blocks. Therefore it is recommended that you use the split UBIFS method which preserves wear leveling info and works with bad blocks. |
| 605 | |
| 606 | ==== Split UBIFS flashing |
| 607 | The following example shows how you can take a UBIFS and split it into chunks that fit into low memory devices and flash them via U-Boot. The example uses tftp to transfer but you can easily replace that instruction with one that loads the chunks from removable storage: |
| 608 | |
| 609 | 1. First you must split your ubifs image on your Linux development host and note the total size of the pre-split image which you will need during flashing. This example assumes a ~580MB ubifs that we will split into 200MB chunks to fit within a 256MB DRAM system: |
| 610 | {{{#!bash |
| 611 | $ ls -l focal-ventana_normal.ubifs |
| 612 | -rw-rw-r-- 1 gateworks user 581042176 Sep 9 14:56 focal-ventana_normal.ubifs |
| 613 | $ split -d -b 200M focal-ventana_normal.ubifs focal-ventana_normal.ubifs.part |
| 614 | $ ls -l focal-ventana_normal.ubifs* |
| 615 | -rw-rw-r-- 1 gateworks user 581042176 Sep 9 14:56 focal-ventana_normal.ubifs |
| 616 | -rw-rw-r-- 1 gateworks user 209715200 Sep 9 15:19 |
| 617 | focal-ventana_normal.ubifs.part00 |
| 618 | -rw-rw-r-- 1 gateworks user 209715200 Sep 9 15:19 |
| 619 | focal-ventana_normal.ubifs.part01 |
| 620 | -rw-rw-r-- 1 gateworks user 161611776 Sep 9 15:20 |
| 621 | focal-ventana_normal.ubifs.part02 |
| 622 | $ printf "0x%x\n" 581042176 |
| 623 | 0x22a20000 |
| 624 | }}} |
| 625 | 1. Now boot your target board and break into U-Boot. Use the {{{mtd}}} command to determine the MTD partition name that you wish to use for UBI. This is dictated by the {{{mtdids}}} and {{{mtdparts}}} env variables. The gateworks bootloader defaults the name of the MTD partition used for UBI to 'rootfs' as shown below: |
| 626 | {{{#!bash |
| 627 | Ventana > mtd |
| 628 | |
| 629 | device nand0 <nand>, # parts = 3 |
| 630 | #: name size offset mask_flags |
| 631 | 0: uboot 0x01000000 0x00000000 0 |
| 632 | 1: env 0x00100000 0x01000000 0 |
| 633 | 2: rootfs 0x7ef00000 0x01100000 0 |
| 634 | |
| 635 | active partition: nand0,0 - (uboot) 0x01000000 @ 0x00000000 |
| 636 | ... |
| 637 | }}} |
| 638 | 1. Use the {{{ubi}}} command to attach the {{{rootfs}}} MTD partition to the ubi layer. The {{{rootfs}}} name here must agree with the partition name from the MTD partition as described above... this is 'not' necessarily the name of your UBI 'volume' used below: |
| 639 | {{{#!bash |
| 640 | Ventana > ubi part rootfs |
| 641 | }}} |
| 642 | 1. Use the {{{ubi info layout}}} command to inspect your UBI volumes. You will always have one volume named {{{layout volume}}} which holds the UBI volume information. |
| 643 | {{{#!bash |
| 644 | Ventana > ubi info layout |
| 645 | Volume information dump: |
| 646 | vol_id 0 |
| 647 | reserved_pebs 15920 |
| 648 | alignment 1 |
| 649 | data_pad 0 |
| 650 | vol_type 3 |
| 651 | name_len 6 |
| 652 | usable_leb_size 126976 |
| 653 | used_ebs 15920 |
| 654 | used_bytes 2021457920 |
| 655 | last_eb_bytes 126976 |
| 656 | corrupted 0 |
| 657 | upd_marker 0 |
| 658 | name rootfs |
| 659 | Volume information dump: |
| 660 | vol_id 2147479551 |
| 661 | reserved_pebs 2 |
| 662 | alignment 1 |
| 663 | data_pad 0 |
| 664 | vol_type 3 |
| 665 | name_len 13 |
| 666 | usable_leb_size 126976 |
| 667 | used_ebs 2 |
| 668 | used_bytes 253952 |
| 669 | last_eb_bytes 2 |
| 670 | corrupted 0 |
| 671 | upd_marker 0 |
| 672 | name layout volume |
| 673 | }}} |
| 674 | * The above shows that there is one data volume named 'rootfs' |
| 675 | 1. remove the existing volume (if you are operating on a blank UBI and only have {{{layout volume}}} skip this step): |
| 676 | {{{#!bash |
| 677 | Ventana > ubi remove rootfs |
| 678 | Remove UBI volume rootfs (id 0) |
| 679 | }}} |
| 680 | 1. Create the new volume. Note that the volume name you use here is the name you would pass to the kernel for mounting. We typically call this 'rootfs' (which should not be confused with the MTD partition name). |
| 681 | {{{#!bash |
| 682 | Ventana > ubi create rootfs |
| 683 | No size specified -> Using max size (2021457920) |
| 684 | Creating dynamic volume rootfs of size 2021457920 |
| 685 | }}} |
| 686 | 1. Load your first chunk: |
| 687 | {{{#!bash |
| 688 | Ventana > tftpboot $loadaddr ventana/focal-ventana_normal.ubifs.part00 |
| 689 | ... |
| 690 | done |
| 691 | Bytes transferred = 209715200 (c800000 hex) |
| 692 | }}} |
| 693 | * You could alternatively use the {{{load}}} command to load from removable storage such as microSD or USB Mass storage but you will need to set the {{{$filesize}}} variable appropriately. |
| 694 | 1. Write your first chunk - this first chunk you need to provide the total size of the pre-split UBIFS image as the last argument in hex: |
| 695 | {{{#!bash |
| 696 | Ventana > ubi write.part $loadaddr rootfs $filesize 0x22a20000 |
| 697 | 209715200 bytes written to volume rootfs |
| 698 | }}} |
| 699 | * Note the last argument {{{0x22a20000}}} which is the total size of the pre-split ubifs image in hex. |
| 700 | 1. Continue the transfer and flash of your additional chunks, this time leaving off the last argument: |
| 701 | {{{#!bash |
| 702 | Ventana > tftpboot $loadaddr ventana/focal-ventana_normal.ubifs.part01 |
| 703 | ... |
| 704 | done |
| 705 | Bytes transferred = 209715200 (c800000 hex) |
| 706 | Ventana > ubi write.part $loadaddr rootfs $filesize |
| 707 | 209715200 bytes written to volume rootfs |
| 708 | Ventana > tftpboot $loadaddr ventana/focal-ventana_normal.ubifs.part02 |
| 709 | ... |
| 710 | done |
| 711 | Bytes transferred = 161611776 (9a20000 hex) |
| 712 | Ventana > ubi write.part $loadaddr rootfs $filesize |
| 713 | 161611776 bytes written to volume rootfs |
| 714 | }}} |
| 715 | |
| 716 | ==== Split UBI flashing |
| 717 | Gateworks has created an installable U-Boot script that will apply UBI files containing a single partition image. This can be particularly useful for updating the firmware of a running target. |
| 718 | |
| 719 | This method does not work if you have bad blocks and also erases previous wear-leveling data that may be tracked by the previous UBI image. The split UBIFS method above is recommended instead. |