Changes between Initial Version and Version 1 of malibu/boot


Ignore:
Timestamp:
04/07/2023 12:51:13 AM (14 months ago)
Author:
Tim Harvey
Comment:

initial page

Legend:

Unmodified
Added
Removed
Modified
  • malibu/boot

    v1 v1  
     1[[PageOutline]]
     2
     3= Malibu Boot Firmware
     4The 'Boot Firmware' for Malibu is defined as the combination of the firmware stages through up to and including the bootloader. This can be broken down into the following stages:
     5 * Boot ROM (internal on CN913x SoC): fetch first level boot firmware from boot device (ie eMMC) into L2 cache
     6 * ATF (ARM Trusted Firmware)
     7 * Bootloader (U-Boot)
     8
     9Gateworks provides [http://dev.gateworks.com/malibu/boot_firmware/ pre-built Boot Firmware] ready to flash onto boot devices as well as source for building and/or modifying the boot firmware yourself.
     10
     11
     12[=#bootrom]
     13== CN913x BOOT ROM
     14The BOOT ROM is firmware baked into the SoC and is in charge of loading code from the 'boot device' into L2 cache, verifying signatures (if using trusted boot) and executing it.
     15
     16The BOOT ROM fetches code from an offset, verifies a header, and jumps to that code. If the header verification fails it will move on to the next offset. The offsets vary per boot device:
     17 - eMMC:
     18  - boot0/boot1 hardware partitions: LBA0 (0)
     19  - data hardware partition: LBA1 (512B), LBA34 (512B*34), LBA4096 (2M), LBA8192 (4M), LBA12288 (6M)
     20 - SD:
     21  - LBA1 (512B), LBA34 (512B*34), LBA4096 (2M), LBA8192 (4M), LBA12288 (6M)
     22
     23Note that LBA refers to Logical Block Address which is a block device unit of 512 bytes.
     24
     25The image header contains a 4-byte magic pattern to identify the boot image, 32bit checksums, a load address, an execution address, a 1byte uart config to configure the serial port for boot info, a baudrate for the serial port and some extension data.
     26
     27The CN913x Boot flow is documented in chapter 28 of the ARMADA 80xx Family Functional Specification which can be obtained under NDA with Marvell.
     28
     29
     30[=#firmware-image]
     31== Boot Firmware Image
     32The boot firmware image contains all of the components of the 'Boot Firmware':
     33- ARM Trusted Firmware
     34- Marvell DDR configuration software; this is a Binary ROM extension (BLE) for the ATF
     35- U-Boot; this is a BL33 for the ATF
     36
     37The boot firmware for Malibu is placed on the boot0 emmc hardware partition so that it is separated from the OS image.
     38
     39Malibu Boot Firmware Image Map:
     40 * imx8mm:
     41||= start-end                 =||= len =||= item =||
     42|| 0x00000000 - 0x003f0000 || 4032K || ATF (including ddr config as BLE and U-Boot as BL33) ||
     43|| 0x0003f000 - 0x00400000 || 64K  || U-Boot env (redundant 32KB env) ||
     44
     45
     46[=#disk-images]
     47== Compressed Disk Images
     48Gateworks releases compressed disk images that can be easily flashed using the U-Boot Bootloader or Linux (booted on a ramdisk based root filesystem). These disk images contain a partition table so they are tailored to the specific device size they are intended for. Additionally they are commonly configured for a small partition size to keep flash programming time at a minimum. This requires resizing the rootfs filesystem in order to take advantage of the remaining flash space.
     49
     50Once you have a root filesystem directory/tarball and have a kernel Image you can create a compressed disk image that can be installed easily from the bootloader.
     51
     52The creation of the compressed disk image is demonstrated in the [https://github.com/Gateworks/bsp-malibu/blob/master/Makefile Malibu BSP makefile]
     53
     54Once you have a compressed disk image you can install this using the methods described in [wiki:malibu#firmware-update malibu/firware-update]. For example in the bootloader:
     55{{{#!bash
     56setenv dev 0 # emmc device; use mmc list to see all mmc devs
     57tftpboot ${loadaddr} image.img.gz && gzwrite mmc ${dev} ${loadaddr} ${filesize}
     58}}}
     59
     60If you created a filesystem that did not stretch to the partition it was installed on (as we create a minimally sized filesystem image to fit within the eMMC device for faster programming) you will want to resize it after booting to Linux. This is a one time operation after flashing a compressed disk image and can be done using the 'growpart_once' script that we install on the Ubuntu Root filesystems found in the script [https://github.com/Gateworks/ubuntu-rootfs/blob/master/ubuntu-rootfs.sh here] (search for growpart_once)
     61
     62To install the kernel and root filesystem on a removable block storage device see [wiki:linux/blockdev].
     63
     64
     65[=#u-boot]
     66== U-Boot Bootloader
     67Gateworks supports the U-Boot Bootloader for the Malibu product family.
     68
     69The purpose of a bootloader is to load the Linux kernel and execute it passing it configuration parameters such as an optional kernel command-line, an optional initial ramdisk filesystem, and a device-tree.
     70
     71The following items are supported in the Gateworks U-Boot for Malibu:
     72 - eth0 (RGMII)
     73 - USB Host mode (USB Mass Storage and USB Networking for various USB Ethernet adapters supported by U-Boot
     74 - eMMC / microSD
     75
     76The following items are not currently supported in the Gateworks U-Boot for Malibu:
     77- PCIe support
     78- USB device mode support (for USB OTG)
     79
     80
     81[=#distro-config]
     82== Distro Config
     83The Malibu Bootloader uses U-Boot's 'Distro Config' which is a well defined U-Boot env intended to make it easier for distro maintainers to develop compatible bootscripts. This primarily entails a set of 'boot scripts' and variables that control them.
     84
     85Ultimately this U-Boot environment is looking for a U-Boot [#bootscript boot script] on a 'bootable' partition (partitions with the 'boot' flag enabled). It searches in this order with these rules:
     86 - **boot_targets** - list of target device type/nums to search: defaults to mmc1 mmc0 usb0 usb1 pxe dhcp
     87 - **devplist** - ''dynamically created'' list of all partitions flagged as 'bootable'
     88 - **boot_prefixes** - list of directories within a partition searched for bootscripts
     89 - **boot_scripts** - list of boot script names searched for
     90
     91
     92[=#bootscript]
     93== Boot Scripts
     94When writing bootscripts compatible with [#distro-config Distro Config] you can assume the following env variables:
     95 - **devtype** - the device type the script was loaded from (mmc|usb|sata)
     96 - **devnum** - the device number the script was loaded from (ie 0 for mmc0, 1 for mmc1, etc)
     97 - **distro_bootpart** - the partition number the script was loaded from (ie 0, 1, etc)
     98 - **fdtcontroladdr** - the address the device-tree is at (Note that the Malibu bootloader contains a static version of the board device-tree)
     99 - **kernel_addr_r** - address where kernel can be loaded
     100 - **bootargs** - default bootargs to pass to the kernel - you probably want to add to this and not overwrite it
     101 - **console** - the serial console device to pass to the kernel
     102
     103Additionally you should note the following:
     104 - use load/ls/save commands which support FAT/ext filesystem types automatically instead of the fs specific commands
     105 - if using a root filesystem that is not supported by the bootloader (ie F2FS or BTRFS) you can place your bootscript and kernel image in the FAT12 filesystem on partition 1 of the boot device. This filesystem is part of the 16MB 'Boot Firmware' image. If doing so you will need to compress the kernel and package it into a [#fit FIT image] in order to fit it in the available space.
     106
     107The Distro-Config environment supports legacy uImage scripts (it does not support FIT images with scripts). You can create these with the {{{mkimage}}} tool from U-Boot as such:
     108{{{#!bash
     109mkimage -A arm64 -T script -C none -d boot.txt boot.scr
     110}}}
     111
     112The bootscript can be updated at runtime on the Linux target. For example:
     113{{{#!bash
     114mkimage -A arm64 -T script -C none -d boot.txt /boot/boot.scr
     115}}}
     116
     117
     118[=#boot_targets]
     119=== Boot Device Order (boot_targets)
     120While the Malibu product family can only boot from its primary boot device (typically eMMC), once you are booted to the bootloader you can choose from a wider variety of devices to boot the OS from.
     121
     122This OS boot device order is specified by the [#distro-config Distro Config] environment. Specifically it is controlled by the {{{boot_targets}}} env variable which typically defaults to {{{mmc1 mmc0 usb0 usb1 pxe dhcp}}}.
     123
     124For example, to limit OS booting to only USB:
     125{{{#!bash
     126setenv boot_targets usb0 usb1
     127saveenv
     128}}}
     129
     130
     131[=#fit]
     132== Flattened Image Tree (FIT) images
     133The U-Boot bootloader supports Flattened Image Tree (FIT) images which expand greatly on the legacy U-Boot image (uImage) format by allowing multiple binary blobs within an image. These blobs can be kernel images, ramdisk images, device-tree blobs, and bootloader scripts. Each image can also be optionally compressed (meaning U-Boot will decompress it) and check-sumed with a variety of hash mechanisms (meaning U-Boot will verify the image before using it).
     134
     135Quick summary of FIT Images:
     136 * introduced to resolve limitations with original single-image formats and follow-on multi-image format supported by UBoot bootm (boot memory)
     137 * uses power of the Device-Tree-Compiler (DTC)
     138 * FIT .itb files can be created with mkimage by passing in a .its file which in device-tree notation describes the images
     139 * U-Boot supports FIT with several commands:
     140  - {{{source <addr>:<name>}}} # source a script by name from FIT image in memory
     141  - {{{iminfo <fitaddress>}}} # print all the info contained in a FIT image in memory and verify (just not boot it)
     142  - {{{imextract <fitaddress> <item> <addr>}}} # extract item (ie kernel@1) to addr
     143  - {{{bootm <fitaddress>[#conf] - $fdtcontroladdr}}} # boot default or 'conf' configuration (ie #config@1)
     144  - {{{bootm start <fitaddress>[#conf] - $fdtcontroladdr}}} # boot from memory a specific configuration (or default configuration) from FIT image
     145
     146Example:
     147 * kernel.its with a single compressed kernel for ARM64
     148{{{#!bash
     149/dts-v1/;
     150/ {
     151        description = "Simple image with single Linux kernel";
     152        #address-cells = <1>;
     153        images {
     154                kernel@1 {
     155                        description = "Linux kernel";
     156                        data = /incbin/("./Image.gz");
     157                        type = "kernel";
     158                        arch = "arm64";
     159                        os = "linux";
     160                        compression = "gzip";
     161                        load = <0x40200000>;
     162                        entry = <0x40200000>;
     163                        hash@1 {
     164                                algo = "sha256";
     165                        };
     166                };
     167        };
     168
     169        configurations {
     170                default = "conf@1";
     171                conf@1 {
     172                        description = "Boot Linux kernel";
     173                        kernel = "kernel@1";
     174                };
     175        };
     176};
     177}}}
     178 * create image:
     179{{{#!bash
     180cp arch/arm64/boot/Image .
     181gzip Image
     182mkimage -f kernel.its /tftpboot/kernel.itb
     183}}}
     184 * boot the default configuration from U-Boot:
     185{{{#!bash
     186tftpboot $loadaddr kernel.itb && bootm $loadaddr - $fdtcontroladdr
     187}}}
     188
     189References:
     190 * [http://git.denx.de/?p=u-boot.git;a=tree;f=doc/uImage.FIT doc/uImage.FIT]
     191 * http://www.denx.de/wiki/pub/U-Boot/Documentation/multi_image_booting_scenarios.pdf
     192 * http://elinux.org/images/f/f4/Elc2013_Fernandes.pdf
     193
     194
     195= U-boot env tools
     196A detailed description of u-boot-tools usage can be found [wiki:/ventana/bootloader#U-Bootenvtoolsfw_printenvfw_setenv here]. 
     197
     198In order to configure u-boot-tools to work correctly for Malibu you will need a fw_env.config file the appropriate values.
     199
     200To create this file:
     201{{{#!bash
     202cat << EOF > /etc/fw_env.config
     203# Device               offset          Env. size
     204/dev/mmcblk0boot0      0x3f0000        0x8000
     205/dev/mmcblk0boot0      0x3f8000        0x8000
     206EOF
     207}}}
     208