Changes between Version 17 and Version 18 of venice/boot


Ignore:
Timestamp:
05/14/2024 03:58:44 PM (5 months ago)
Author:
Tim Harvey
Comment:

add details regarding moving boot firmware between user and boot0 or boot1 hardware partitions

Legend:

Unmodified
Added
Removed
Modified
  • venice/boot

    v17 v18  
    1818[=#firmware-image]
    1919== Boot Firmware Image
    20 The firmware image contains all of the components of the 'Boot Firmware':
     20The boot firmware image contains all of the components of the 'Boot Firmware':
    2121- ARM Trusted Firmware (ATF)
    2222- SPL
     
    4747  - eMMC boot partition: 0KiB
    4848
     49== eMMC boot partition
     50By default since around Jan 2024 Gateworks has been placing boot firmware on the eMMC 'boot0' hardware partition (instead of the 'user' hardware partition) which accomplishes two things:
     51 1. keeps your boot firmware isolated from your OS (filesystems as well as disk partition table)
     52 2. allows compressed disk images now representing the OS only to be shared between the various IMX8M SoC's supported by the venice family (imx8mm, imx8mn, imx8mp) which have different boot firmware images
     53
     54At this same time the U-Boot environment data was moved from an offset of 0xfe0000 (16M - 128K) to an offset of 0x3e0000 (4M - 128K) so that it fit within the minimal size of the 4MB boot hardware partitions. However regardless of what hardware partition the eMMC boots from, the U-Boot environment data is always at the same offset on that hardware partition (the top of the 4MB boundary)
     55
     56If you wish to move the boot firmware between user, boot0, and boot1 eMMC hardware partitions note the following:
     57 - the different SoC BOOT ROM's use different offsets depending on the emmc hardware partition. Specifically:
     58  * IMX8MM BOOT ROM will always fetch boot code at a 33KB offset for eMMC devices regardless of the hardware partition
     59  * IMX8MN/IMX8MP BOOT ROM will fetch boot code at a 32KB offset for eMMC devices booting from user and 0KB offset for eMMC devices booting from boot0 or boot1
     60 - the eMMC PARTITION_CONFIG register (EXT CSD 179) BOOT_PARTITION_ENABLE field specifies what eMMC hardware partition is active on power-up so if you move the boot firmware you must update the PARTITION_CONFIG register (via U-Boot 'mmc partconf' command, via Linux 'mmc bootpart' command (from the 'mmc-utils' package) or via JTAG by specifying the '--partconf' cmdline parameter to the mkimage_jtag script used to create a JTAG image
     61
     62To determine what hardware partition is currently being used:
     63 - if using the latest boot firmware U-Boot SPL will announce the hardware partition such as 'Trying to boot from eMMC boot0'. If the hardware partition (boot0, boot1, user) is not shown then you are using an older boot firmware
     64 - use the U-Boot 'mmc partconf 2' command (2 is the eMMC device for Venice) and examine the 'BOOT_PARTITION_ENABLE' field. If using a using a newer boot firmware it will show both the numeric value as well as what that value represents, for example 'BOOT_PARTITION_ENABLE: 0x1 (boot0)' (and if just the number is shown you are using an older boot firmware). Note the possible values for BOOT_PARTITION_ENABLE are: 0x1 (boot0), 0x2 (boot1), 0x7 (user).
     65 - use the Linux 'mmc extcsd read' command and look at the PARTITION_CONFIG register {{{bits[5:3]}}}
     66
     67
     68Examples:
     69 * show the current eMMC boot partition:
     70  - from U-Boot:
     71{{{#!bash
     72u-boot=> mmc partconf 2
     73EXT_CSD[179], PARTITION_CONFIG:
     74BOOT_ACK: 0x0
     75BOOT_PARTITION_ENABLE: 0x1 (boot0)
     76PARTITION_ACCESS: 0x0
     77}}}
     78   - BOOT_PARTITION_ENABLE 0x1 represents boot0 (0x1=boot0, 0x2=boot1, 0x7=user)
     79  - from Linux:
     80{{{#!bash
     81root@jammy-venice:~# mmc extcsd read /dev/mmcblk2 | grep PARTITION_CONFIG
     82Boot configuration bytes [PARTITION_CONFIG: 0x08]
     83root@jammy-venice:~# echo $(($((0x08 >> 3)) & 0x7)) # show bits[5:3]
     841
     85root@jammy-venice:~# echo $(($(( $(mmc extcsd read /dev/mmcblk2 | sed -n 's/.*PARTITION_CONFIG: \(.*\)]/\1/p') >> 3)) & 0x7)) # 1-line version
     861
     87}}}
     88  - BOOT_PARTITION_ENABLE is represented by {{{bits[5:3]}}} of PARTITION_CONFIG which can be read from the EXT CSD register 179 named 'PARTITION_CONFIG' (1=boot0, 2=boot1, 7=user)
     89 * IMX8MM: Program boot firmware to user:
     90  - from U-Boot
     91{{{#!bash
     92# fetch flash.bin boot firmware
     93tftpboot $loadaddr $dir/venice-$soc-flash.bin
     94# set blkcnt to $filesize/512 (convert to 512 byte blocks)
     95setexpr blkcnt $filesize + 0x1ff && setexpr blkcnt $blkcnt / 0x200
     96# select the emmc (dev=2) user hardware partition (part=0)
     97mmc dev 2 0
     98# write to 33K (which is 0x42 hex 512 byte blocks)
     99mmc write $loadaddr 0x42 $blkcnt
     100# set PARTITION_CONFIG to BOOT_ACK=1 BOOT_PARTITION_ENABLE=7 to boot from user
     101mmc partconf 2 1 7 0
     102}}}
     103  - from Linux
     104{{{#!bash
     105# fetch flash.bin boot firmware
     106wget https://dev.gateworks.com/venice/boot_firmware/venice-imx8mm-flash.bin
     107# write it to mmcblk2 (user) at offset 33KB
     108dd if=venice-imx8mm-flash.bin of=/dev/mmcblk2 bs=1k seek=33 conv=notrunc
     109# set BOOT_PARTITION_ENABLE to 7 for mmcblk2 (eMMC)
     110mmc bootpart enable 7 0 /dev/mmcblk2
     111}}}
     112  - via JTAG:
     113{{{#!bash
     114# start with soc-specific position-independent boot firmware binary
     115wget https://dev.gateworks.com/venice/boot_firmware/venice-imx8mm-flash.bin
     116# create a 4MB file and copy the position-independent boot firmware to where the BOOT ROM expects it (33K in this case)
     117truncate -s 4M firmware.img
     118dd if=venice-imx8mm-flash.bin of=firwmare.img bs=1k seek=33 conv=notrunc
     119# use the mkimage_jtag script to create a JTAG binary that flashes this image and sets the PARTITION_CONFIG register
     120./mkimage_jtag --soc imx8mm --emmc -s --partconf=user \
     121    firmware.img@user:erase_part:0-8192 \
     122    > firmware-venice-imx8mm.bin
     123}}}
     124 * IMX8MM: Program boot firmware to boot0:
     125  - from U-Boot
     126{{{#!bash
     127# fetch flash.bin boot firmware
     128tftpboot $loadaddr $dir/venice-$soc-flash.bin
     129# set blkcnt to $filesize/512 (convert to 512 byte blocks)
     130setexpr blkcnt $filesize + 0x1ff && setexpr blkcnt $blkcnt / 0x200
     131# select the emmc (dev=2) boot0 hardware partition (part=1)
     132mmc dev 2 1
     133# write to 33K (which is 0x42 hex 512 byte blocks)
     134mmc write $loadaddr 0x42 $blkcnt
     135# set PARTITION_CONFIG to BOOT_ACK=1 BOOT_PARTITION_ENABLE=1 to boot from boot0
     136mmc partconf 2 1 1 0
     137}}}
     138  - from Linux
     139{{{#!bash
     140# fetch flash.bin boot firmware
     141wget https://dev.gateworks.com/venice/boot_firmware/venice-imx8mm-flash.bin
     142# write it to mmcblk2boot0 at offset 33KB
     143echo 0 > /sys/class/block/mmcblk2boot0/force_ro
     144dd if=venice-imx8mm-flash.bin of=/dev/mmcblk2boot0 bs=1k seek=33 conv=notrunc
     145# set BOOT_PARTITION_ENABLE to 1 for mmcblk2 (eMMC)
     146mmc bootpart enable 1 0 /dev/mmcblk2
     147}}}
     148  - via JTAG:
     149{{{#!bash
     150# start with soc-specific position-independent boot firmware binary
     151wget https://dev.gateworks.com/venice/boot_firmware/venice-imx8mm-flash.bin
     152# create a 4MB file and copy the position-independent boot firmware to where the BOOT ROM expects it (33K in this case)
     153truncate -s 4M firmware.img
     154dd if=venice-imx8mm-flash.bin of=firmware.img bs=1k seek=33 conv=notrunc
     155# use the mkimage_jtag script to create a JTAG binary that flashes this image and sets the PARTITION_CONFIG register
     156./mkimage_jtag --soc imx8mm --emmc -s --partconf=boot0 \
     157    firmware.img@boot0:erase_part:0-8192 \
     158    > firmware-venice-imx8mm.bin
     159}}}
     160 * IMX8MP: Program boot firmware to user:
     161  - from U-Boot
     162{{{#!bash
     163# fetch flash.bin boot firmware
     164tftpboot $loadaddr $dir/venice-$soc-flash.bin
     165# set blkcnt to $filesize/512 (convert to 512 byte blocks)
     166setexpr blkcnt $filesize + 0x1ff && setexpr blkcnt $blkcnt / 0x200
     167# select the emmc (dev=2) user hardware partition (part=0)
     168mmc dev 2 0
     169# write to 32K (which is 0x40 hex 512 byte blocks)
     170mmc write $loadaddr 0x40 $blkcnt
     171# set PARTITION_CONFIG
     172mmc partconf 2 1 user user
     173}}}
     174  - from Linux
     175{{{#!bash
     176# fetch flash.bin boot firmware
     177wget https://dev.gateworks.com/venice/boot_firmware/venice-imx8mp-flash.bin
     178# write it to mmcblk2 (user) at offset 32KB
     179dd if=venice-imx8mp-flash.bin of=/dev/mmcblk2 bs=1k seek=32 conv=notrunc
     180# set BOOT_PARTITION_ENABLE to 7 for mmcblk2 (eMMC)
     181mmc bootpart enable 7 0 /dev/mmcblk2
     182}}}
     183  - via JTAG:
     184{{{#!bash
     185# start with soc-specific position-independent boot firmware binary
     186wget https://dev.gateworks.com/venice/boot_firmware/venice-imx8mp-flash.bin
     187# create a 4MB file and copy the position-independent boot firmware to where the BOOT ROM expects it (32K in this case)
     188truncate -s 4M firmware.img
     189dd if=venice-imx8mp-flash.bin of=firmware.img bs=1k seek=32 conv=notrunc
     190# use the mkimage_jtag script to create a JTAG binary that flashes this image and sets the PARTITION_CONFIG register
     191./mkimage_jtag --soc imx8mp --emmc -s --partconf=user \
     192    firmware.img@user:erase_part:0-8192 \
     193    > firmware-venice-imx8mp.bin
     194}}}
     195 * IMX8MM: Program boot firmware to boot0:
     196  - from U-Boot
     197{{{#!bash
     198# fetch flash.bin boot firmware
     199tftpboot $loadaddr $dir/venice-$soc-flash.bin
     200# set blkcnt to $filesize/512 (conver to 512 byte blocks)
     201setexpr blkcnt $filesize + 0x1ff && setexpr blkcnt $blkcnt / 0x200
     202# select the emmc (dev=2) boot0 hardware partition (part=1)
     203mmc dev 2 1
     204# write to 0K
     205mmc write $loadaddr 0x0 $blkcnt
     206# set PARTITION_CONFIG to BOOT_ACK=1 BOOT_PARTITION_ENABLE=1 to boot from boot0
     207mmc partconf 2 1 1 0
     208}}}
     209  - from Linux
     210{{{#!bash
     211# fetch flash.bin boot firmware
     212wget https://dev.gateworks.com/venice/boot_firmware/venice-imx8mp-flash.bin
     213# write it to mmcblk2boot0 at offset 0KB
     214echo 0 > /sys/class/block/mmcblk2boot0/force_ro
     215dd if=venice-imx8mp-flash.bin of=/dev/mmcblk2boot0 bs=1k seek=0 conv=notrunc
     216# set BOOT_PARTITION_ENABLE to 1 (boot0) for mmcblk2 (eMMC)
     217mmc bootpart enable 1 0 /dev/mmcblk2
     218}}}
     219  - via JTAG:
     220{{{#!bash
     221# start with soc-specific position-independent boot firmware binary
     222wget https://dev.gateworks.com/venice/boot_firmware/venice-imx8mp-flash.bin
     223# create a 4MB file and copy the position-independent boot firmware to where the BOOT ROM expects it (0K in this case)
     224truncate -s 4M firmware.img
     225dd if=venice-imx8mp-flash.bin of=firmware.img bs=1k seek=0 conv=notrunc
     226# use the mkimage_jtag script to create a JTAG binary that flashes this image and sets the PARTITION_CONFIG register
     227./mkimage_jtag --soc imx8mp --emmc -s --partconf=boot0 \
     228    firmware.img@boot0:erase_part:0-8192 \
     229    > firmware-venice-imx8mp.bin
     230}}}
     231
     232The examples above start with the position-independent boot firmware therefore they do not contain the U-Boot environment area which is always stored at the top of the 4MB boundary of the eMMC hardware partition that U-Boot boots from. You can create and update this environment data via:
     233 * Create environment data:
     234  - from Gateworks default firmware image:
     235{{{#!bash
     236wget https://dev.gateworks.com/venice/images/firmware-venice-imx8mm.img
     237dd if=firmware-venice-imx8mm.img of=env.bin bs=1k skip=4032 count=128
     238}}}
     239 * Update U-Boot env (to $bootpart) from U-Boot
     240{{{#!bash
     241tftpboot $loadaddr env.bin && mmc dev $dev $bootpart && mmc write $loadaddr 0x1f80 0x80
     242}}}
     243 * Update U-Boot env to user from Linux
     244{{{#!bash
     245dd if=env.bin of=/dev/mmcblk2 bs=1k seek=4032 conv=notrunc
     246}}}
     247 * Update U-Boot env to boot0 from Linux
     248{{{#!bash
     249echo 0 > /sys/class/block/mmcblk2boot0/force_ro
     250dd if=env.bin of=/dev/mmcblk2boot0 bs=1k seek=4032 conv=notrunc
     251}}}
     252
     253
     254
    49255== Legacy Boot Firmware Image
    50256The original Gateworks IMX8MM Boot Firmware (now considered legacy) was installed to the eMMC user hardware partition.