1bf7fd50bSSimon Glass# SPDX-License-Identifier: GPL-2.0+ 283d290c5STom Rini# Copyright (c) 2016 Google, Inc 3bf7fd50bSSimon Glass 4bf7fd50bSSimon GlassIntroduction 5bf7fd50bSSimon Glass------------ 6bf7fd50bSSimon Glass 7bf7fd50bSSimon GlassFirmware often consists of several components which must be packaged together. 8bf7fd50bSSimon GlassFor example, we may have SPL, U-Boot, a device tree and an environment area 9bf7fd50bSSimon Glassgrouped together and placed in MMC flash. When the system starts, it must be 10bf7fd50bSSimon Glassable to find these pieces. 11bf7fd50bSSimon Glass 12bf7fd50bSSimon GlassSo far U-Boot has not provided a way to handle creating such images in a 13bf7fd50bSSimon Glassgeneral way. Each SoC does what it needs to build an image, often packing or 14bf7fd50bSSimon Glassconcatenating images in the U-Boot build system. 15bf7fd50bSSimon Glass 16bf7fd50bSSimon GlassBinman aims to provide a mechanism for building images, from simple 17bf7fd50bSSimon GlassSPL + U-Boot combinations, to more complex arrangements with many parts. 18bf7fd50bSSimon Glass 19bf7fd50bSSimon Glass 20bf7fd50bSSimon GlassWhat it does 21bf7fd50bSSimon Glass------------ 22bf7fd50bSSimon Glass 23bf7fd50bSSimon GlassBinman reads your board's device tree and finds a node which describes the 24bf7fd50bSSimon Glassrequired image layout. It uses this to work out what to place where. The 25bf7fd50bSSimon Glassoutput file normally contains the device tree, so it is in principle possible 26bf7fd50bSSimon Glassto read an image and extract its constituent parts. 27bf7fd50bSSimon Glass 28bf7fd50bSSimon Glass 29bf7fd50bSSimon GlassFeatures 30bf7fd50bSSimon Glass-------- 31bf7fd50bSSimon Glass 32bf7fd50bSSimon GlassSo far binman is pretty simple. It supports binary blobs, such as 'u-boot', 33bf7fd50bSSimon Glass'spl' and 'fdt'. It supports empty entries (such as setting to 0xff). It can 34bf7fd50bSSimon Glassplace entries at a fixed location in the image, or fit them together with 35bf7fd50bSSimon Glasssuitable padding and alignment. It provides a way to process binaries before 36bf7fd50bSSimon Glassthey are included, by adding a Python plug-in. The device tree is available 37bf7fd50bSSimon Glassto U-Boot at run-time so that the images can be interpreted. 38bf7fd50bSSimon Glass 39bf7fd50bSSimon GlassBinman does not yet update the device tree with the final location of 40bf7fd50bSSimon Glasseverything when it is done. A simple C structure could be generated for 41bf7fd50bSSimon Glassconstrained environments like SPL (using dtoc) but this is also not 42bf7fd50bSSimon Glassimplemented. 43bf7fd50bSSimon Glass 44bf7fd50bSSimon GlassBinman can also support incorporating filesystems in the image if required. 45bf7fd50bSSimon GlassFor example x86 platforms may use CBFS in some cases. 46bf7fd50bSSimon Glass 47bf7fd50bSSimon GlassBinman is intended for use with U-Boot but is designed to be general enough 48bf7fd50bSSimon Glassto be useful in other image-packaging situations. 49bf7fd50bSSimon Glass 50bf7fd50bSSimon Glass 51bf7fd50bSSimon GlassMotivation 52bf7fd50bSSimon Glass---------- 53bf7fd50bSSimon Glass 54bf7fd50bSSimon GlassPackaging of firmware is quite a different task from building the various 55bf7fd50bSSimon Glassparts. In many cases the various binaries which go into the image come from 56bf7fd50bSSimon Glassseparate build systems. For example, ARM Trusted Firmware is used on ARMv8 57bf7fd50bSSimon Glassdevices but is not built in the U-Boot tree. If a Linux kernel is included 58bf7fd50bSSimon Glassin the firmware image, it is built elsewhere. 59bf7fd50bSSimon Glass 60bf7fd50bSSimon GlassIt is of course possible to add more and more build rules to the U-Boot 61bf7fd50bSSimon Glassbuild system to cover these cases. It can shell out to other Makefiles and 62bf7fd50bSSimon Glassbuild scripts. But it seems better to create a clear divide between building 63bf7fd50bSSimon Glasssoftware and packaging it. 64bf7fd50bSSimon Glass 65bf7fd50bSSimon GlassAt present this is handled by manual instructions, different for each board, 66bf7fd50bSSimon Glasson how to create images that will boot. By turning these instructions into a 67bf7fd50bSSimon Glassstandard format, we can support making valid images for any board without 68bf7fd50bSSimon Glassmanual effort, lots of READMEs, etc. 69bf7fd50bSSimon Glass 70bf7fd50bSSimon GlassBenefits: 71bf7fd50bSSimon Glass- Each binary can have its own build system and tool chain without creating 72bf7fd50bSSimon Glassany dependencies between them 73bf7fd50bSSimon Glass- Avoids the need for a single-shot build: individual parts can be updated 74bf7fd50bSSimon Glassand brought in as needed 75bf7fd50bSSimon Glass- Provides for a standard image description available in the build and at 76bf7fd50bSSimon Glassrun-time 77bf7fd50bSSimon Glass- SoC-specific image-signing tools can be accomodated 78bf7fd50bSSimon Glass- Avoids cluttering the U-Boot build system with image-building code 79bf7fd50bSSimon Glass- The image description is automatically available at run-time in U-Boot, 80bf7fd50bSSimon GlassSPL. It can be made available to other software also 81bf7fd50bSSimon Glass- The image description is easily readable (it's a text file in device-tree 82bf7fd50bSSimon Glassformat) and permits flexible packing of binaries 83bf7fd50bSSimon Glass 84bf7fd50bSSimon Glass 85bf7fd50bSSimon GlassTerminology 86bf7fd50bSSimon Glass----------- 87bf7fd50bSSimon Glass 88bf7fd50bSSimon GlassBinman uses the following terms: 89bf7fd50bSSimon Glass 90bf7fd50bSSimon Glass- image - an output file containing a firmware image 91bf7fd50bSSimon Glass- binary - an input binary that goes into the image 92bf7fd50bSSimon Glass 93bf7fd50bSSimon Glass 94bf7fd50bSSimon GlassRelationship to FIT 95bf7fd50bSSimon Glass------------------- 96bf7fd50bSSimon Glass 97bf7fd50bSSimon GlassFIT is U-Boot's official image format. It supports multiple binaries with 98bf7fd50bSSimon Glassload / execution addresses, compression. It also supports verification 99bf7fd50bSSimon Glassthrough hashing and RSA signatures. 100bf7fd50bSSimon Glass 101bf7fd50bSSimon GlassFIT was originally designed to support booting a Linux kernel (with an 102bf7fd50bSSimon Glassoptional ramdisk) and device tree chosen from various options in the FIT. 103bf7fd50bSSimon GlassNow that U-Boot supports configuration via device tree, it is possible to 104bf7fd50bSSimon Glassload U-Boot from a FIT, with the device tree chosen by SPL. 105bf7fd50bSSimon Glass 106bf7fd50bSSimon GlassBinman considers FIT to be one of the binaries it can place in the image. 107bf7fd50bSSimon Glass 108bf7fd50bSSimon GlassWhere possible it is best to put as much as possible in the FIT, with binman 109bf7fd50bSSimon Glassused to deal with cases not covered by FIT. Examples include initial 110bf7fd50bSSimon Glassexecution (since FIT itself does not have an executable header) and dealing 111bf7fd50bSSimon Glasswith device boundaries, such as the read-only/read-write separation in SPI 112bf7fd50bSSimon Glassflash. 113bf7fd50bSSimon Glass 114bf7fd50bSSimon GlassFor U-Boot, binman should not be used to create ad-hoc images in place of 115bf7fd50bSSimon GlassFIT. 116bf7fd50bSSimon Glass 117bf7fd50bSSimon Glass 118bf7fd50bSSimon GlassRelationship to mkimage 119bf7fd50bSSimon Glass----------------------- 120bf7fd50bSSimon Glass 121bf7fd50bSSimon GlassThe mkimage tool provides a means to create a FIT. Traditionally it has 122bf7fd50bSSimon Glassneeded an image description file: a device tree, like binman, but in a 123bf7fd50bSSimon Glassdifferent format. More recently it has started to support a '-f auto' mode 124bf7fd50bSSimon Glasswhich can generate that automatically. 125bf7fd50bSSimon Glass 126bf7fd50bSSimon GlassMore relevant to binman, mkimage also permits creation of many SoC-specific 127bf7fd50bSSimon Glassimage types. These can be listed by running 'mkimage -T list'. Examples 128bf7fd50bSSimon Glassinclude 'rksd', the Rockchip SD/MMC boot format. The mkimage tool is often 129bf7fd50bSSimon Glasscalled from the U-Boot build system for this reason. 130bf7fd50bSSimon Glass 131bf7fd50bSSimon GlassBinman considers the output files created by mkimage to be binary blobs 132bf7fd50bSSimon Glasswhich it can place in an image. Binman does not replace the mkimage tool or 133*383d2568SMichael Heimpoldthis purpose. It would be possible in some situations to create a new entry 134bf7fd50bSSimon Glasstype for the images in mkimage, but this would not add functionality. It 135*383d2568SMichael Heimpoldseems better to use the mkimage tool to generate binaries and avoid blurring 136bf7fd50bSSimon Glassthe boundaries between building input files (mkimage) and packaging then 137bf7fd50bSSimon Glassinto a final image (binman). 138bf7fd50bSSimon Glass 139bf7fd50bSSimon Glass 140bf7fd50bSSimon GlassExample use of binman in U-Boot 141bf7fd50bSSimon Glass------------------------------- 142bf7fd50bSSimon Glass 143bf7fd50bSSimon GlassBinman aims to replace some of the ad-hoc image creation in the U-Boot 144bf7fd50bSSimon Glassbuild system. 145bf7fd50bSSimon Glass 146bf7fd50bSSimon GlassConsider sunxi. It has the following steps: 147bf7fd50bSSimon Glass 148bf7fd50bSSimon Glass1. It uses a custom mksunxiboot tool to build an SPL image called 149bf7fd50bSSimon Glasssunxi-spl.bin. This should probably move into mkimage. 150bf7fd50bSSimon Glass 151bf7fd50bSSimon Glass2. It uses mkimage to package U-Boot into a legacy image file (so that it can 152bf7fd50bSSimon Glasshold the load and execution address) called u-boot.img. 153bf7fd50bSSimon Glass 154bf7fd50bSSimon Glass3. It builds a final output image called u-boot-sunxi-with-spl.bin which 155bf7fd50bSSimon Glassconsists of sunxi-spl.bin, some padding and u-boot.img. 156bf7fd50bSSimon Glass 157bf7fd50bSSimon GlassBinman is intended to replace the last step. The U-Boot build system builds 158bf7fd50bSSimon Glassu-boot.bin and sunxi-spl.bin. Binman can then take over creation of 159bf7fd50bSSimon Glasssunxi-spl.bin (by calling mksunxiboot, or hopefully one day mkimage). In any 160bf7fd50bSSimon Glasscase, it would then create the image from the component parts. 161bf7fd50bSSimon Glass 162bf7fd50bSSimon GlassThis simplifies the U-Boot Makefile somewhat, since various pieces of logic 163bf7fd50bSSimon Glasscan be replaced by a call to binman. 164bf7fd50bSSimon Glass 165bf7fd50bSSimon Glass 166bf7fd50bSSimon GlassExample use of binman for x86 167bf7fd50bSSimon Glass----------------------------- 168bf7fd50bSSimon Glass 169bf7fd50bSSimon GlassIn most cases x86 images have a lot of binary blobs, 'black-box' code 170bf7fd50bSSimon Glassprovided by Intel which must be run for the platform to work. Typically 171bf7fd50bSSimon Glassthese blobs are not relocatable and must be placed at fixed areas in the 172*383d2568SMichael Heimpoldfirmware image. 173bf7fd50bSSimon Glass 174bf7fd50bSSimon GlassCurrently this is handled by ifdtool, which places microcode, FSP, MRC, VGA 175bf7fd50bSSimon GlassBIOS, reference code and Intel ME binaries into a u-boot.rom file. 176bf7fd50bSSimon Glass 177bf7fd50bSSimon GlassBinman is intended to replace all of this, with ifdtool left to handle only 178bf7fd50bSSimon Glassthe configuration of the Intel-format descriptor. 179bf7fd50bSSimon Glass 180bf7fd50bSSimon Glass 181bf7fd50bSSimon GlassRunning binman 182bf7fd50bSSimon Glass-------------- 183bf7fd50bSSimon Glass 184bf7fd50bSSimon GlassType: 185bf7fd50bSSimon Glass 186bf7fd50bSSimon Glass binman -b <board_name> 187bf7fd50bSSimon Glass 188bf7fd50bSSimon Glassto build an image for a board. The board name is the same name used when 189bf7fd50bSSimon Glassconfiguring U-Boot (e.g. for sandbox_defconfig the board name is 'sandbox'). 190bf7fd50bSSimon GlassBinman assumes that the input files for the build are in ../b/<board_name>. 191bf7fd50bSSimon Glass 192bf7fd50bSSimon GlassOr you can specify this explicitly: 193bf7fd50bSSimon Glass 194bf7fd50bSSimon Glass binman -I <build_path> 195bf7fd50bSSimon Glass 196bf7fd50bSSimon Glasswhere <build_path> is the build directory containing the output of the U-Boot 197bf7fd50bSSimon Glassbuild. 198bf7fd50bSSimon Glass 199bf7fd50bSSimon Glass(Future work will make this more configurable) 200bf7fd50bSSimon Glass 201bf7fd50bSSimon GlassIn either case, binman picks up the device tree file (u-boot.dtb) and looks 202bf7fd50bSSimon Glassfor its instructions in the 'binman' node. 203bf7fd50bSSimon Glass 204bf7fd50bSSimon GlassBinman has a few other options which you can see by running 'binman -h'. 205bf7fd50bSSimon Glass 206bf7fd50bSSimon Glass 2079c0a8b1fSSimon GlassEnabling binman for a board 2089c0a8b1fSSimon Glass--------------------------- 2099c0a8b1fSSimon Glass 2109c0a8b1fSSimon GlassAt present binman is invoked from a rule in the main Makefile. Typically you 2119c0a8b1fSSimon Glasswill have a rule like: 2129c0a8b1fSSimon Glass 2139c0a8b1fSSimon Glassifneq ($(CONFIG_ARCH_<something>),) 2149c0a8b1fSSimon Glassu-boot-<your_suffix>.bin: <input_file_1> <input_file_2> checkbinman FORCE 2159c0a8b1fSSimon Glass $(call if_changed,binman) 2169c0a8b1fSSimon Glassendif 2179c0a8b1fSSimon Glass 2189c0a8b1fSSimon GlassThis assumes that u-boot-<your_suffix>.bin is a target, and is the final file 2199c0a8b1fSSimon Glassthat you need to produce. You can make it a target by adding it to ALL-y 2209c0a8b1fSSimon Glasseither in the main Makefile or in a config.mk file in your arch subdirectory. 2219c0a8b1fSSimon Glass 2229c0a8b1fSSimon GlassOnce binman is executed it will pick up its instructions from a device-tree 2239c0a8b1fSSimon Glassfile, typically <soc>-u-boot.dtsi, where <soc> is your CONFIG_SYS_SOC value. 2249c0a8b1fSSimon GlassYou can use other, more specific CONFIG options - see 'Automatic .dtsi 2259c0a8b1fSSimon Glassinclusion' below. 2269c0a8b1fSSimon Glass 2279c0a8b1fSSimon Glass 228bf7fd50bSSimon GlassImage description format 229bf7fd50bSSimon Glass------------------------ 230bf7fd50bSSimon Glass 231bf7fd50bSSimon GlassThe binman node is called 'binman'. An example image description is shown 232bf7fd50bSSimon Glassbelow: 233bf7fd50bSSimon Glass 234bf7fd50bSSimon Glass binman { 235bf7fd50bSSimon Glass filename = "u-boot-sunxi-with-spl.bin"; 236bf7fd50bSSimon Glass pad-byte = <0xff>; 237bf7fd50bSSimon Glass blob { 238bf7fd50bSSimon Glass filename = "spl/sunxi-spl.bin"; 239bf7fd50bSSimon Glass }; 240bf7fd50bSSimon Glass u-boot { 2413ab9598dSSimon Glass offset = <CONFIG_SPL_PAD_TO>; 242bf7fd50bSSimon Glass }; 243bf7fd50bSSimon Glass }; 244bf7fd50bSSimon Glass 245bf7fd50bSSimon Glass 246bf7fd50bSSimon GlassThis requests binman to create an image file called u-boot-sunxi-with-spl.bin 247bf7fd50bSSimon Glassconsisting of a specially formatted SPL (spl/sunxi-spl.bin, built by the 248bf7fd50bSSimon Glassnormal U-Boot Makefile), some 0xff padding, and a U-Boot legacy image. The 249bf7fd50bSSimon Glasspadding comes from the fact that the second binary is placed at 250bf7fd50bSSimon GlassCONFIG_SPL_PAD_TO. If that line were omitted then the U-Boot binary would 251bf7fd50bSSimon Glassimmediately follow the SPL binary. 252bf7fd50bSSimon Glass 253bf7fd50bSSimon GlassThe binman node describes an image. The sub-nodes describe entries in the 254bf7fd50bSSimon Glassimage. Each entry represents a region within the overall image. The name of 255bf7fd50bSSimon Glassthe entry (blob, u-boot) tells binman what to put there. For 'blob' we must 256bf7fd50bSSimon Glassprovide a filename. For 'u-boot', binman knows that this means 'u-boot.bin'. 257bf7fd50bSSimon Glass 258bf7fd50bSSimon GlassEntries are normally placed into the image sequentially, one after the other. 259bf7fd50bSSimon GlassThe image size is the total size of all entries. As you can see, you can 2603ab9598dSSimon Glassspecify the start offset of an entry using the 'offset' property. 261bf7fd50bSSimon Glass 262bf7fd50bSSimon GlassNote that due to a device tree requirement, all entries must have a unique 263bf7fd50bSSimon Glassname. If you want to put the same binary in the image multiple times, you can 264bf7fd50bSSimon Glassuse any unique name, with the 'type' property providing the type. 265bf7fd50bSSimon Glass 266bf7fd50bSSimon GlassThe attributes supported for entries are described below. 267bf7fd50bSSimon Glass 2683ab9598dSSimon Glassoffset: 2693ab9598dSSimon Glass This sets the offset of an entry within the image or section containing 2703ab9598dSSimon Glass it. The first byte of the image is normally at offset 0. If 'offset' is 2713ab9598dSSimon Glass not provided, binman sets it to the end of the previous region, or the 2723ab9598dSSimon Glass start of the image's entry area (normally 0) if there is no previous 2733ab9598dSSimon Glass region. 274bf7fd50bSSimon Glass 275bf7fd50bSSimon Glassalign: 2763ab9598dSSimon Glass This sets the alignment of the entry. The entry offset is adjusted 277bf7fd50bSSimon Glass so that the entry starts on an aligned boundary within the image. For 278bf7fd50bSSimon Glass example 'align = <16>' means that the entry will start on a 16-byte 279bf7fd50bSSimon Glass boundary. Alignment shold be a power of 2. If 'align' is not 280bf7fd50bSSimon Glass provided, no alignment is performed. 281bf7fd50bSSimon Glass 282bf7fd50bSSimon Glasssize: 283bf7fd50bSSimon Glass This sets the size of the entry. The contents will be padded out to 284bf7fd50bSSimon Glass this size. If this is not provided, it will be set to the size of the 285bf7fd50bSSimon Glass contents. 286bf7fd50bSSimon Glass 287bf7fd50bSSimon Glasspad-before: 288bf7fd50bSSimon Glass Padding before the contents of the entry. Normally this is 0, meaning 289bf7fd50bSSimon Glass that the contents start at the beginning of the entry. This can be 290bf7fd50bSSimon Glass offset the entry contents a little. Defaults to 0. 291bf7fd50bSSimon Glass 292bf7fd50bSSimon Glasspad-after: 293bf7fd50bSSimon Glass Padding after the contents of the entry. Normally this is 0, meaning 294bf7fd50bSSimon Glass that the entry ends at the last byte of content (unless adjusted by 295bf7fd50bSSimon Glass other properties). This allows room to be created in the image for 296bf7fd50bSSimon Glass this entry to expand later. Defaults to 0. 297bf7fd50bSSimon Glass 298bf7fd50bSSimon Glassalign-size: 299bf7fd50bSSimon Glass This sets the alignment of the entry size. For example, to ensure 300bf7fd50bSSimon Glass that the size of an entry is a multiple of 64 bytes, set this to 64. 301bf7fd50bSSimon Glass If 'align-size' is not provided, no alignment is performed. 302bf7fd50bSSimon Glass 303bf7fd50bSSimon Glassalign-end: 304bf7fd50bSSimon Glass This sets the alignment of the end of an entry. Some entries require 305bf7fd50bSSimon Glass that they end on an alignment boundary, regardless of where they 306844e5b20SSimon Glass start. This does not move the start of the entry, so the contents of 307844e5b20SSimon Glass the entry will still start at the beginning. But there may be padding 308844e5b20SSimon Glass at the end. If 'align-end' is not provided, no alignment is performed. 309bf7fd50bSSimon Glass 310bf7fd50bSSimon Glassfilename: 311bf7fd50bSSimon Glass For 'blob' types this provides the filename containing the binary to 312bf7fd50bSSimon Glass put into the entry. If binman knows about the entry type (like 313bf7fd50bSSimon Glass u-boot-bin), then there is no need to specify this. 314bf7fd50bSSimon Glass 315bf7fd50bSSimon Glasstype: 316bf7fd50bSSimon Glass Sets the type of an entry. This defaults to the entry name, but it is 317bf7fd50bSSimon Glass possible to use any name, and then add (for example) 'type = "u-boot"' 318bf7fd50bSSimon Glass to specify the type. 319bf7fd50bSSimon Glass 3203ab9598dSSimon Glassoffset-unset: 3213ab9598dSSimon Glass Indicates that the offset of this entry should not be set by placing 322258fb0e6SSimon Glass it immediately after the entry before. Instead, is set by another 323258fb0e6SSimon Glass entry which knows where this entry should go. When this boolean 324258fb0e6SSimon Glass property is present, binman will give an error if another entry does 3253ab9598dSSimon Glass not set the offset (with the GetOffsets() method). 326258fb0e6SSimon Glass 327dbf6be9fSSimon Glassimage-pos: 328dbf6be9fSSimon Glass This cannot be set on entry (or at least it is ignored if it is), but 329dbf6be9fSSimon Glass with the -u option, binman will set it to the absolute image position 330dbf6be9fSSimon Glass for each entry. This makes it easy to find out exactly where the entry 331dbf6be9fSSimon Glass ended up in the image, regardless of parent sections, etc. 332dbf6be9fSSimon Glass 333bf7fd50bSSimon Glass 334bf7fd50bSSimon GlassThe attributes supported for images are described below. Several are similar 335bf7fd50bSSimon Glassto those for entries. 336bf7fd50bSSimon Glass 337bf7fd50bSSimon Glasssize: 338bf7fd50bSSimon Glass Sets the image size in bytes, for example 'size = <0x100000>' for a 339bf7fd50bSSimon Glass 1MB image. 340bf7fd50bSSimon Glass 341bf7fd50bSSimon Glassalign-size: 342bf7fd50bSSimon Glass This sets the alignment of the image size. For example, to ensure 343bf7fd50bSSimon Glass that the image ends on a 512-byte boundary, use 'align-size = <512>'. 344bf7fd50bSSimon Glass If 'align-size' is not provided, no alignment is performed. 345bf7fd50bSSimon Glass 346bf7fd50bSSimon Glasspad-before: 347bf7fd50bSSimon Glass This sets the padding before the image entries. The first entry will 3483ab9598dSSimon Glass be positioned after the padding. This defaults to 0. 349bf7fd50bSSimon Glass 350bf7fd50bSSimon Glasspad-after: 351bf7fd50bSSimon Glass This sets the padding after the image entries. The padding will be 352bf7fd50bSSimon Glass placed after the last entry. This defaults to 0. 353bf7fd50bSSimon Glass 354bf7fd50bSSimon Glasspad-byte: 355bf7fd50bSSimon Glass This specifies the pad byte to use when padding in the image. It 356bf7fd50bSSimon Glass defaults to 0. To use 0xff, you would add 'pad-byte = <0xff>'. 357bf7fd50bSSimon Glass 358bf7fd50bSSimon Glassfilename: 359bf7fd50bSSimon Glass This specifies the image filename. It defaults to 'image.bin'. 360bf7fd50bSSimon Glass 3613ab9598dSSimon Glasssort-by-offset: 362bf7fd50bSSimon Glass This causes binman to reorder the entries as needed to make sure they 363bf7fd50bSSimon Glass are in increasing positional order. This can be used when your entry 364bf7fd50bSSimon Glass order may not match the positional order. A common situation is where 3653ab9598dSSimon Glass the 'offset' properties are set by CONFIG options, so their ordering is 366bf7fd50bSSimon Glass not known a priori. 367bf7fd50bSSimon Glass 368bf7fd50bSSimon Glass This is a boolean property so needs no value. To enable it, add a 3693ab9598dSSimon Glass line 'sort-by-offset;' to your description. 370bf7fd50bSSimon Glass 371bf7fd50bSSimon Glassmultiple-images: 372bf7fd50bSSimon Glass Normally only a single image is generated. To create more than one 373bf7fd50bSSimon Glass image, put this property in the binman node. For example, this will 374bf7fd50bSSimon Glass create image1.bin containing u-boot.bin, and image2.bin containing 375bf7fd50bSSimon Glass both spl/u-boot-spl.bin and u-boot.bin: 376bf7fd50bSSimon Glass 377bf7fd50bSSimon Glass binman { 378bf7fd50bSSimon Glass multiple-images; 379bf7fd50bSSimon Glass image1 { 380bf7fd50bSSimon Glass u-boot { 381bf7fd50bSSimon Glass }; 382bf7fd50bSSimon Glass }; 383bf7fd50bSSimon Glass 384bf7fd50bSSimon Glass image2 { 385bf7fd50bSSimon Glass spl { 386bf7fd50bSSimon Glass }; 387bf7fd50bSSimon Glass u-boot { 388bf7fd50bSSimon Glass }; 389bf7fd50bSSimon Glass }; 390bf7fd50bSSimon Glass }; 391bf7fd50bSSimon Glass 392bf7fd50bSSimon Glassend-at-4gb: 3933ab9598dSSimon Glass For x86 machines the ROM offsets start just before 4GB and extend 394bf7fd50bSSimon Glass up so that the image finished at the 4GB boundary. This boolean 395bf7fd50bSSimon Glass option can be enabled to support this. The image size must be 396bf7fd50bSSimon Glass provided so that binman knows when the image should start. For an 3973ab9598dSSimon Glass 8MB ROM, the offset of the first entry would be 0xfff80000 with 398bf7fd50bSSimon Glass this option, instead of 0 without this option. 399bf7fd50bSSimon Glass 400bf7fd50bSSimon Glass 401bf7fd50bSSimon GlassExamples of the above options can be found in the tests. See the 402bf7fd50bSSimon Glasstools/binman/test directory. 403bf7fd50bSSimon Glass 404dd57c13bSSimon GlassIt is possible to have the same binary appear multiple times in the image, 405dd57c13bSSimon Glasseither by using a unit number suffix (u-boot@0, u-boot@1) or by using a 406dd57c13bSSimon Glassdifferent name for each and specifying the type with the 'type' attribute. 407dd57c13bSSimon Glass 408bf7fd50bSSimon Glass 409*383d2568SMichael HeimpoldSections and hierachical images 4101854695bSSimon Glass------------------------------- 4111854695bSSimon Glass 4121854695bSSimon GlassSometimes it is convenient to split an image into several pieces, each of which 4131854695bSSimon Glasscontains its own set of binaries. An example is a flash device where part of 4141854695bSSimon Glassthe image is read-only and part is read-write. We can set up sections for each 4151854695bSSimon Glassof these, and place binaries in them independently. The image is still produced 4161854695bSSimon Glassas a single output file. 4171854695bSSimon Glass 4181854695bSSimon GlassThis feature provides a way of creating hierarchical images. For example here 4197ae5f315SSimon Glassis an example image with two copies of U-Boot. One is read-only (ro), intended 4207ae5f315SSimon Glassto be written only in the factory. Another is read-write (rw), so that it can be 4211854695bSSimon Glassupgraded in the field. The sizes are fixed so that the ro/rw boundary is known 4221854695bSSimon Glassand can be programmed: 4231854695bSSimon Glass 4241854695bSSimon Glass binman { 4251854695bSSimon Glass section@0 { 4261854695bSSimon Glass read-only; 427c8d48efbSSimon Glass name-prefix = "ro-"; 4281854695bSSimon Glass size = <0x100000>; 4291854695bSSimon Glass u-boot { 4301854695bSSimon Glass }; 4311854695bSSimon Glass }; 4321854695bSSimon Glass section@1 { 433c8d48efbSSimon Glass name-prefix = "rw-"; 4341854695bSSimon Glass size = <0x100000>; 4351854695bSSimon Glass u-boot { 4361854695bSSimon Glass }; 4371854695bSSimon Glass }; 4381854695bSSimon Glass }; 4391854695bSSimon Glass 4401854695bSSimon GlassThis image could be placed into a SPI flash chip, with the protection boundary 4411854695bSSimon Glassset at 1MB. 4421854695bSSimon Glass 4431854695bSSimon GlassA few special properties are provided for sections: 4441854695bSSimon Glass 4451854695bSSimon Glassread-only: 4461854695bSSimon Glass Indicates that this section is read-only. This has no impact on binman's 4471854695bSSimon Glass operation, but his property can be read at run time. 4481854695bSSimon Glass 449c8d48efbSSimon Glassname-prefix: 450c8d48efbSSimon Glass This string is prepended to all the names of the binaries in the 451c8d48efbSSimon Glass section. In the example above, the 'u-boot' binaries which actually be 452c8d48efbSSimon Glass renamed to 'ro-u-boot' and 'rw-u-boot'. This can be useful to 453c8d48efbSSimon Glass distinguish binaries with otherwise identical names. 454c8d48efbSSimon Glass 4551854695bSSimon Glass 4565a5da7ceSSimon GlassEntry Documentation 4575a5da7ceSSimon Glass------------------- 4585a5da7ceSSimon Glass 4595a5da7ceSSimon GlassFor details on the various entry types supported by binman and how to use them, 4605a5da7ceSSimon Glasssee README.entries. This is generated from the source code using: 4615a5da7ceSSimon Glass 4625a5da7ceSSimon Glass binman -E >tools/binman/README.entries 4635a5da7ceSSimon Glass 4645a5da7ceSSimon Glass 465e0ff8551SSimon GlassSpecial properties 466e0ff8551SSimon Glass------------------ 467e0ff8551SSimon Glass 468e0ff8551SSimon GlassSome entries support special properties, documented here: 469e0ff8551SSimon Glass 470e0ff8551SSimon Glassu-boot-with-ucode-ptr: 471e0ff8551SSimon Glass optional-ucode: boolean property to make microcode optional. If the 472e0ff8551SSimon Glass u-boot.bin image does not include microcode, no error will 473e0ff8551SSimon Glass be generated. 474e0ff8551SSimon Glass 475e0ff8551SSimon Glass 476bf7fd50bSSimon GlassOrder of image creation 477bf7fd50bSSimon Glass----------------------- 478bf7fd50bSSimon Glass 479bf7fd50bSSimon GlassImage creation proceeds in the following order, for each entry in the image. 480bf7fd50bSSimon Glass 481078ab1a2SSimon Glass1. AddMissingProperties() - binman can add calculated values to the device 4823ab9598dSSimon Glasstree as part of its processing, for example the offset and size of each 483078ab1a2SSimon Glassentry. This method adds any properties associated with this, expanding the 484078ab1a2SSimon Glassdevice tree as needed. These properties can have placeholder values which are 485078ab1a2SSimon Glassset later by SetCalculatedProperties(). By that stage the size of sections 486078ab1a2SSimon Glasscannot be changed (since it would cause the images to need to be repacked), 487078ab1a2SSimon Glassbut the correct values can be inserted. 488078ab1a2SSimon Glass 489078ab1a2SSimon Glass2. ProcessFdt() - process the device tree information as required by the 490ecab8973SSimon Glassparticular entry. This may involve adding or deleting properties. If the 491ecab8973SSimon Glassprocessing is complete, this method should return True. If the processing 492ecab8973SSimon Glasscannot complete because it needs the ProcessFdt() method of another entry to 493ecab8973SSimon Glassrun first, this method should return False, in which case it will be called 494ecab8973SSimon Glassagain later. 495ecab8973SSimon Glass 496078ab1a2SSimon Glass3. GetEntryContents() - the contents of each entry are obtained, normally by 497bf7fd50bSSimon Glassreading from a file. This calls the Entry.ObtainContents() to read the 498bf7fd50bSSimon Glasscontents. The default version of Entry.ObtainContents() calls 499bf7fd50bSSimon GlassEntry.GetDefaultFilename() and then reads that file. So a common mechanism 500bf7fd50bSSimon Glassto select a file to read is to override that function in the subclass. The 501bf7fd50bSSimon Glassfunctions must return True when they have read the contents. Binman will 502bf7fd50bSSimon Glassretry calling the functions a few times if False is returned, allowing 503bf7fd50bSSimon Glassdependencies between the contents of different entries. 504bf7fd50bSSimon Glass 5053ab9598dSSimon Glass4. GetEntryOffsets() - calls Entry.GetOffsets() for each entry. This can 506bf7fd50bSSimon Glassreturn a dict containing entries that need updating. The key should be the 5073ab9598dSSimon Glassentry name and the value is a tuple (offset, size). This allows an entry to 5083ab9598dSSimon Glassprovide the offset and size for other entries. The default implementation 5093ab9598dSSimon Glassof GetEntryOffsets() returns {}. 510bf7fd50bSSimon Glass 5113ab9598dSSimon Glass5. PackEntries() - calls Entry.Pack() which figures out the offset and 5123ab9598dSSimon Glasssize of an entry. The 'current' image offset is passed in, and the function 5133ab9598dSSimon Glassreturns the offset immediately after the entry being packed. The default 514bf7fd50bSSimon Glassimplementation of Pack() is usually sufficient. 515bf7fd50bSSimon Glass 516078ab1a2SSimon Glass6. CheckSize() - checks that the contents of all the entries fits within 517bf7fd50bSSimon Glassthe image size. If the image does not have a defined size, the size is set 518bf7fd50bSSimon Glasslarge enough to hold all the entries. 519bf7fd50bSSimon Glass 520078ab1a2SSimon Glass7. CheckEntries() - checks that the entries do not overlap, nor extend 521bf7fd50bSSimon Glassoutside the image. 522bf7fd50bSSimon Glass 523078ab1a2SSimon Glass8. SetCalculatedProperties() - update any calculated properties in the device 5243ab9598dSSimon Glasstree. This sets the correct 'offset' and 'size' vaues, for example. 525078ab1a2SSimon Glass 526078ab1a2SSimon Glass9. ProcessEntryContents() - this calls Entry.ProcessContents() on each entry. 527bf7fd50bSSimon GlassThe default implementatoin does nothing. This can be overriden to adjust the 528bf7fd50bSSimon Glasscontents of an entry in some way. For example, it would be possible to create 529bf7fd50bSSimon Glassan entry containing a hash of the contents of some other entries. At this 5303ab9598dSSimon Glassstage the offset and size of entries should not be adjusted. 531bf7fd50bSSimon Glass 532078ab1a2SSimon Glass10. WriteSymbols() - write the value of symbols into the U-Boot SPL binary. 5333ab9598dSSimon GlassSee 'Access to binman entry offsets at run time' below for a description of 5340a4357c4SSimon Glasswhat happens in this stage. 53539c1502cSSimon Glass 536078ab1a2SSimon Glass11. BuildImage() - builds the image and writes it to a file. This is the final 537bf7fd50bSSimon Glassstep. 538bf7fd50bSSimon Glass 539bf7fd50bSSimon Glass 5406d427c6bSSimon GlassAutomatic .dtsi inclusion 5416d427c6bSSimon Glass------------------------- 5426d427c6bSSimon Glass 5436d427c6bSSimon GlassIt is sometimes inconvenient to add a 'binman' node to the .dts file for each 5446d427c6bSSimon Glassboard. This can be done by using #include to bring in a common file. Another 5456d427c6bSSimon Glassapproach supported by the U-Boot build system is to automatically include 5466d427c6bSSimon Glassa common header. You can then put the binman node (and anything else that is 5476d427c6bSSimon Glassspecific to U-Boot, such as u-boot,dm-pre-reloc properies) in that header 5486d427c6bSSimon Glassfile. 5496d427c6bSSimon Glass 5506d427c6bSSimon GlassBinman will search for the following files in arch/<arch>/dts: 5516d427c6bSSimon Glass 5526d427c6bSSimon Glass <dts>-u-boot.dtsi where <dts> is the base name of the .dts file 5536d427c6bSSimon Glass <CONFIG_SYS_SOC>-u-boot.dtsi 5546d427c6bSSimon Glass <CONFIG_SYS_CPU>-u-boot.dtsi 5556d427c6bSSimon Glass <CONFIG_SYS_VENDOR>-u-boot.dtsi 5566d427c6bSSimon Glass u-boot.dtsi 5576d427c6bSSimon Glass 5586d427c6bSSimon GlassU-Boot will only use the first one that it finds. If you need to include a 5596d427c6bSSimon Glassmore general file you can do that from the more specific file using #include. 5606d427c6bSSimon GlassIf you are having trouble figuring out what is going on, you can uncomment 5616d427c6bSSimon Glassthe 'warning' line in scripts/Makefile.lib to see what it has found: 5626d427c6bSSimon Glass 5636d427c6bSSimon Glass # Uncomment for debugging 564511fd0b2SSimon Glass # This shows all the files that were considered and the one that we chose. 565511fd0b2SSimon Glass # u_boot_dtsi_options_debug = $(u_boot_dtsi_options_raw) 5666d427c6bSSimon Glass 5676d427c6bSSimon Glass 568dbf6be9fSSimon GlassAccess to binman entry offsets at run time (symbols) 569dbf6be9fSSimon Glass---------------------------------------------------- 57039c1502cSSimon Glass 57139c1502cSSimon GlassBinman assembles images and determines where each entry is placed in the image. 57239c1502cSSimon GlassThis information may be useful to U-Boot at run time. For example, in SPL it 57339c1502cSSimon Glassis useful to be able to find the location of U-Boot so that it can be executed 57439c1502cSSimon Glasswhen SPL is finished. 57539c1502cSSimon Glass 57639c1502cSSimon GlassBinman allows you to declare symbols in the SPL image which are filled in 57739c1502cSSimon Glasswith their correct values during the build. For example: 57839c1502cSSimon Glass 5793ab9598dSSimon Glass binman_sym_declare(ulong, u_boot_any, offset); 58039c1502cSSimon Glass 5813ab9598dSSimon Glassdeclares a ulong value which will be assigned to the offset of any U-Boot 58239c1502cSSimon Glassimage (u-boot.bin, u-boot.img, u-boot-nodtb.bin) that is present in the image. 58339c1502cSSimon GlassYou can access this value with something like: 58439c1502cSSimon Glass 5853ab9598dSSimon Glass ulong u_boot_offset = binman_sym(ulong, u_boot_any, offset); 58639c1502cSSimon Glass 5873ab9598dSSimon GlassThus u_boot_offset will be set to the offset of U-Boot in memory, assuming that 58839c1502cSSimon Glassthe whole image has been loaded, or is available in flash. You can then jump to 58939c1502cSSimon Glassthat address to start U-Boot. 59039c1502cSSimon Glass 59139c1502cSSimon GlassAt present this feature is only supported in SPL. In principle it is possible 59239c1502cSSimon Glassto fill in such symbols in U-Boot proper, as well. 59339c1502cSSimon Glass 59439c1502cSSimon Glass 595dbf6be9fSSimon GlassAccess to binman entry offsets at run time (fdt) 596dbf6be9fSSimon Glass------------------------------------------------ 597dbf6be9fSSimon Glass 598dbf6be9fSSimon GlassBinman can update the U-Boot FDT to include the final position and size of 599dbf6be9fSSimon Glasseach entry in the images it processes. The option to enable this is -u and it 600dbf6be9fSSimon Glasscauses binman to make sure that the 'offset', 'image-pos' and 'size' properties 601dbf6be9fSSimon Glassare set correctly for every entry. Since it is not necessary to specify these in 602dbf6be9fSSimon Glassthe image definition, binman calculates the final values and writes these to 603dbf6be9fSSimon Glassthe device tree. These can be used by U-Boot at run-time to find the location 604dbf6be9fSSimon Glassof each entry. 605dbf6be9fSSimon Glass 606dbf6be9fSSimon Glass 6073b0c3821SSimon GlassMap files 6083b0c3821SSimon Glass--------- 6093b0c3821SSimon Glass 6103b0c3821SSimon GlassThe -m option causes binman to output a .map file for each image that it 6113ab9598dSSimon Glassgenerates. This shows the offset and size of each entry. For example: 6123b0c3821SSimon Glass 6133ab9598dSSimon Glass Offset Size Name 6148122f396SSimon Glass 00000000 00000028 main-section 6153b0c3821SSimon Glass 00000000 00000010 section@0 6163b0c3821SSimon Glass 00000000 00000004 u-boot 6173b0c3821SSimon Glass 00000010 00000010 section@1 6183b0c3821SSimon Glass 00000000 00000004 u-boot 6193b0c3821SSimon Glass 6203b0c3821SSimon GlassThis shows a hierarchical image with two sections, each with a single entry. The 6213ab9598dSSimon Glassoffsets of the sections are absolute hex byte offsets within the image. The 6223ab9598dSSimon Glassoffsets of the entries are relative to their respective sections. The size of 6233b0c3821SSimon Glasseach entry is also shown, in bytes (hex). The indentation shows the entries 6243b0c3821SSimon Glassnested inside their sections. 6253b0c3821SSimon Glass 6263b0c3821SSimon Glass 62753af22a9SSimon GlassPassing command-line arguments to entries 62853af22a9SSimon Glass----------------------------------------- 62953af22a9SSimon Glass 63053af22a9SSimon GlassSometimes it is useful to pass binman the value of an entry property from the 63153af22a9SSimon Glasscommand line. For example some entries need access to files and it is not 63253af22a9SSimon Glassalways convenient to put these filenames in the image definition (device tree). 63353af22a9SSimon Glass 63453af22a9SSimon GlassThe-a option supports this: 63553af22a9SSimon Glass 63653af22a9SSimon Glass -a<prop>=<value> 63753af22a9SSimon Glass 63853af22a9SSimon Glasswhere 63953af22a9SSimon Glass 64053af22a9SSimon Glass <prop> is the property to set 64153af22a9SSimon Glass <value> is the value to set it to 64253af22a9SSimon Glass 64353af22a9SSimon GlassNot all properties can be provided this way. Only some entries support it, 64453af22a9SSimon Glasstypically for filenames. 64553af22a9SSimon Glass 64653af22a9SSimon Glass 6476d427c6bSSimon GlassCode coverage 6486d427c6bSSimon Glass------------- 6496d427c6bSSimon Glass 6506d427c6bSSimon GlassBinman is a critical tool and is designed to be very testable. Entry 6516d427c6bSSimon Glassimplementations target 100% test coverage. Run 'binman -T' to check this. 6526d427c6bSSimon Glass 6536d427c6bSSimon GlassTo enable Python test coverage on Debian-type distributions (e.g. Ubuntu): 6546d427c6bSSimon Glass 65516d836cdSTom Rini $ sudo apt-get install python-coverage python-pytest 6566d427c6bSSimon Glass 6576d427c6bSSimon Glass 658bf7fd50bSSimon GlassAdvanced Features / Technical docs 659bf7fd50bSSimon Glass---------------------------------- 660bf7fd50bSSimon Glass 661bf7fd50bSSimon GlassThe behaviour of entries is defined by the Entry class. All other entries are 662bf7fd50bSSimon Glassa subclass of this. An important subclass is Entry_blob which takes binary 663bf7fd50bSSimon Glassdata from a file and places it in the entry. In fact most entry types are 664bf7fd50bSSimon Glasssubclasses of Entry_blob. 665bf7fd50bSSimon Glass 666bf7fd50bSSimon GlassEach entry type is a separate file in the tools/binman/etype directory. Each 667bf7fd50bSSimon Glassfile contains a class called Entry_<type> where <type> is the entry type. 668bf7fd50bSSimon GlassNew entry types can be supported by adding new files in that directory. 669bf7fd50bSSimon GlassThese will automatically be detected by binman when needed. 670bf7fd50bSSimon Glass 671bf7fd50bSSimon GlassEntry properties are documented in entry.py. The entry subclasses are free 672bf7fd50bSSimon Glassto change the values of properties to support special behaviour. For example, 673bf7fd50bSSimon Glasswhen Entry_blob loads a file, it sets content_size to the size of the file. 674bf7fd50bSSimon GlassEntry classes can adjust other entries. For example, an entry that knows 6753ab9598dSSimon Glasswhere other entries should be positioned can set up those entries' offsets 676bf7fd50bSSimon Glassso they don't need to be set in the binman decription. It can also adjust 677bf7fd50bSSimon Glassentry contents. 678bf7fd50bSSimon Glass 679bf7fd50bSSimon GlassMost of the time such essoteric behaviour is not needed, but it can be 680bf7fd50bSSimon Glassessential for complex images. 681bf7fd50bSSimon Glass 6823ed0de31SSimon GlassIf you need to specify a particular device-tree compiler to use, you can define 6833ed0de31SSimon Glassthe DTC environment variable. This can be useful when the system dtc is too 6843ed0de31SSimon Glassold. 6853ed0de31SSimon Glass 686bf7fd50bSSimon Glass 687bf7fd50bSSimon GlassHistory / Credits 688bf7fd50bSSimon Glass----------------- 689bf7fd50bSSimon Glass 690bf7fd50bSSimon GlassBinman takes a lot of inspiration from a Chrome OS tool called 691bf7fd50bSSimon Glass'cros_bundle_firmware', which I wrote some years ago. That tool was based on 692bf7fd50bSSimon Glassa reasonably simple and sound design but has expanded greatly over the 693bf7fd50bSSimon Glassyears. In particular its handling of x86 images is convoluted. 694bf7fd50bSSimon Glass 6957ae5f315SSimon GlassQuite a few lessons have been learned which are hopefully applied here. 696bf7fd50bSSimon Glass 697bf7fd50bSSimon Glass 698bf7fd50bSSimon GlassDesign notes 699bf7fd50bSSimon Glass------------ 700bf7fd50bSSimon Glass 701bf7fd50bSSimon GlassOn the face of it, a tool to create firmware images should be fairly simple: 702bf7fd50bSSimon Glassjust find all the input binaries and place them at the right place in the 703bf7fd50bSSimon Glassimage. The difficulty comes from the wide variety of input types (simple 704bf7fd50bSSimon Glassflat binaries containing code, packaged data with various headers), packing 705bf7fd50bSSimon Glassrequirments (alignment, spacing, device boundaries) and other required 706bf7fd50bSSimon Glassfeatures such as hierarchical images. 707bf7fd50bSSimon Glass 708bf7fd50bSSimon GlassThe design challenge is to make it easy to create simple images, while 709bf7fd50bSSimon Glassallowing the more complex cases to be supported. For example, for most 710bf7fd50bSSimon Glassimages we don't much care exactly where each binary ends up, so we should 711bf7fd50bSSimon Glassnot have to specify that unnecessarily. 712bf7fd50bSSimon Glass 713bf7fd50bSSimon GlassNew entry types should aim to provide simple usage where possible. If new 714bf7fd50bSSimon Glasscore features are needed, they can be added in the Entry base class. 715bf7fd50bSSimon Glass 716bf7fd50bSSimon Glass 717bf7fd50bSSimon GlassTo do 718bf7fd50bSSimon Glass----- 719bf7fd50bSSimon Glass 720bf7fd50bSSimon GlassSome ideas: 721bf7fd50bSSimon Glass- Use of-platdata to make the information available to code that is unable 722bf7fd50bSSimon Glass to use device tree (such as a very small SPL image) 723bf7fd50bSSimon Glass- Allow easy building of images by specifying just the board name 72416b8d6b7SSimon Glass- Produce a full Python binding for libfdt (for upstream). This is nearing 72516b8d6b7SSimon Glass completion but some work remains 726bf7fd50bSSimon Glass- Add an option to decode an image into the constituent binaries 727bf7fd50bSSimon Glass- Support building an image for a board (-b) more completely, with a 728bf7fd50bSSimon Glass configurable build directory 729bf7fd50bSSimon Glass- Consider making binman work with buildman, although if it is used in the 730bf7fd50bSSimon Glass Makefile, this will be automatic 731bf7fd50bSSimon Glass 732bf7fd50bSSimon Glass-- 733bf7fd50bSSimon GlassSimon Glass <sjg@chromium.org> 734bf7fd50bSSimon Glass7/7/2016 735