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 133bf7fd50bSSimon Glassthis purpose. It would be possible in some situtions to create a new entry 134bf7fd50bSSimon Glasstype for the images in mkimage, but this would not add functionality. It 135bf7fd50bSSimon Glassseems better to use the mkiamge 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 172bf7fd50bSSimon Glassfirmare 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 327bf7fd50bSSimon Glass 328bf7fd50bSSimon GlassThe attributes supported for images are described below. Several are similar 329bf7fd50bSSimon Glassto those for entries. 330bf7fd50bSSimon Glass 331bf7fd50bSSimon Glasssize: 332bf7fd50bSSimon Glass Sets the image size in bytes, for example 'size = <0x100000>' for a 333bf7fd50bSSimon Glass 1MB image. 334bf7fd50bSSimon Glass 335bf7fd50bSSimon Glassalign-size: 336bf7fd50bSSimon Glass This sets the alignment of the image size. For example, to ensure 337bf7fd50bSSimon Glass that the image ends on a 512-byte boundary, use 'align-size = <512>'. 338bf7fd50bSSimon Glass If 'align-size' is not provided, no alignment is performed. 339bf7fd50bSSimon Glass 340bf7fd50bSSimon Glasspad-before: 341bf7fd50bSSimon Glass This sets the padding before the image entries. The first entry will 3423ab9598dSSimon Glass be positioned after the padding. This defaults to 0. 343bf7fd50bSSimon Glass 344bf7fd50bSSimon Glasspad-after: 345bf7fd50bSSimon Glass This sets the padding after the image entries. The padding will be 346bf7fd50bSSimon Glass placed after the last entry. This defaults to 0. 347bf7fd50bSSimon Glass 348bf7fd50bSSimon Glasspad-byte: 349bf7fd50bSSimon Glass This specifies the pad byte to use when padding in the image. It 350bf7fd50bSSimon Glass defaults to 0. To use 0xff, you would add 'pad-byte = <0xff>'. 351bf7fd50bSSimon Glass 352bf7fd50bSSimon Glassfilename: 353bf7fd50bSSimon Glass This specifies the image filename. It defaults to 'image.bin'. 354bf7fd50bSSimon Glass 3553ab9598dSSimon Glasssort-by-offset: 356bf7fd50bSSimon Glass This causes binman to reorder the entries as needed to make sure they 357bf7fd50bSSimon Glass are in increasing positional order. This can be used when your entry 358bf7fd50bSSimon Glass order may not match the positional order. A common situation is where 3593ab9598dSSimon Glass the 'offset' properties are set by CONFIG options, so their ordering is 360bf7fd50bSSimon Glass not known a priori. 361bf7fd50bSSimon Glass 362bf7fd50bSSimon Glass This is a boolean property so needs no value. To enable it, add a 3633ab9598dSSimon Glass line 'sort-by-offset;' to your description. 364bf7fd50bSSimon Glass 365bf7fd50bSSimon Glassmultiple-images: 366bf7fd50bSSimon Glass Normally only a single image is generated. To create more than one 367bf7fd50bSSimon Glass image, put this property in the binman node. For example, this will 368bf7fd50bSSimon Glass create image1.bin containing u-boot.bin, and image2.bin containing 369bf7fd50bSSimon Glass both spl/u-boot-spl.bin and u-boot.bin: 370bf7fd50bSSimon Glass 371bf7fd50bSSimon Glass binman { 372bf7fd50bSSimon Glass multiple-images; 373bf7fd50bSSimon Glass image1 { 374bf7fd50bSSimon Glass u-boot { 375bf7fd50bSSimon Glass }; 376bf7fd50bSSimon Glass }; 377bf7fd50bSSimon Glass 378bf7fd50bSSimon Glass image2 { 379bf7fd50bSSimon Glass spl { 380bf7fd50bSSimon Glass }; 381bf7fd50bSSimon Glass u-boot { 382bf7fd50bSSimon Glass }; 383bf7fd50bSSimon Glass }; 384bf7fd50bSSimon Glass }; 385bf7fd50bSSimon Glass 386bf7fd50bSSimon Glassend-at-4gb: 3873ab9598dSSimon Glass For x86 machines the ROM offsets start just before 4GB and extend 388bf7fd50bSSimon Glass up so that the image finished at the 4GB boundary. This boolean 389bf7fd50bSSimon Glass option can be enabled to support this. The image size must be 390bf7fd50bSSimon Glass provided so that binman knows when the image should start. For an 3913ab9598dSSimon Glass 8MB ROM, the offset of the first entry would be 0xfff80000 with 392bf7fd50bSSimon Glass this option, instead of 0 without this option. 393bf7fd50bSSimon Glass 394bf7fd50bSSimon Glass 395bf7fd50bSSimon GlassExamples of the above options can be found in the tests. See the 396bf7fd50bSSimon Glasstools/binman/test directory. 397bf7fd50bSSimon Glass 398dd57c13bSSimon GlassIt is possible to have the same binary appear multiple times in the image, 399dd57c13bSSimon Glasseither by using a unit number suffix (u-boot@0, u-boot@1) or by using a 400dd57c13bSSimon Glassdifferent name for each and specifying the type with the 'type' attribute. 401dd57c13bSSimon Glass 402bf7fd50bSSimon Glass 4031854695bSSimon GlassSections and hiearchical images 4041854695bSSimon Glass------------------------------- 4051854695bSSimon Glass 4061854695bSSimon GlassSometimes it is convenient to split an image into several pieces, each of which 4071854695bSSimon Glasscontains its own set of binaries. An example is a flash device where part of 4081854695bSSimon Glassthe image is read-only and part is read-write. We can set up sections for each 4091854695bSSimon Glassof these, and place binaries in them independently. The image is still produced 4101854695bSSimon Glassas a single output file. 4111854695bSSimon Glass 4121854695bSSimon GlassThis feature provides a way of creating hierarchical images. For example here 4137ae5f315SSimon Glassis an example image with two copies of U-Boot. One is read-only (ro), intended 4147ae5f315SSimon Glassto be written only in the factory. Another is read-write (rw), so that it can be 4151854695bSSimon Glassupgraded in the field. The sizes are fixed so that the ro/rw boundary is known 4161854695bSSimon Glassand can be programmed: 4171854695bSSimon Glass 4181854695bSSimon Glass binman { 4191854695bSSimon Glass section@0 { 4201854695bSSimon Glass read-only; 421c8d48efbSSimon Glass name-prefix = "ro-"; 4221854695bSSimon Glass size = <0x100000>; 4231854695bSSimon Glass u-boot { 4241854695bSSimon Glass }; 4251854695bSSimon Glass }; 4261854695bSSimon Glass section@1 { 427c8d48efbSSimon Glass name-prefix = "rw-"; 4281854695bSSimon Glass size = <0x100000>; 4291854695bSSimon Glass u-boot { 4301854695bSSimon Glass }; 4311854695bSSimon Glass }; 4321854695bSSimon Glass }; 4331854695bSSimon Glass 4341854695bSSimon GlassThis image could be placed into a SPI flash chip, with the protection boundary 4351854695bSSimon Glassset at 1MB. 4361854695bSSimon Glass 4371854695bSSimon GlassA few special properties are provided for sections: 4381854695bSSimon Glass 4391854695bSSimon Glassread-only: 4401854695bSSimon Glass Indicates that this section is read-only. This has no impact on binman's 4411854695bSSimon Glass operation, but his property can be read at run time. 4421854695bSSimon Glass 443c8d48efbSSimon Glassname-prefix: 444c8d48efbSSimon Glass This string is prepended to all the names of the binaries in the 445c8d48efbSSimon Glass section. In the example above, the 'u-boot' binaries which actually be 446c8d48efbSSimon Glass renamed to 'ro-u-boot' and 'rw-u-boot'. This can be useful to 447c8d48efbSSimon Glass distinguish binaries with otherwise identical names. 448c8d48efbSSimon Glass 4491854695bSSimon Glass 450e0ff8551SSimon GlassSpecial properties 451e0ff8551SSimon Glass------------------ 452e0ff8551SSimon Glass 453e0ff8551SSimon GlassSome entries support special properties, documented here: 454e0ff8551SSimon Glass 455e0ff8551SSimon Glassu-boot-with-ucode-ptr: 456e0ff8551SSimon Glass optional-ucode: boolean property to make microcode optional. If the 457e0ff8551SSimon Glass u-boot.bin image does not include microcode, no error will 458e0ff8551SSimon Glass be generated. 459e0ff8551SSimon Glass 460e0ff8551SSimon Glass 461bf7fd50bSSimon GlassOrder of image creation 462bf7fd50bSSimon Glass----------------------- 463bf7fd50bSSimon Glass 464bf7fd50bSSimon GlassImage creation proceeds in the following order, for each entry in the image. 465bf7fd50bSSimon Glass 466078ab1a2SSimon Glass1. AddMissingProperties() - binman can add calculated values to the device 4673ab9598dSSimon Glasstree as part of its processing, for example the offset and size of each 468078ab1a2SSimon Glassentry. This method adds any properties associated with this, expanding the 469078ab1a2SSimon Glassdevice tree as needed. These properties can have placeholder values which are 470078ab1a2SSimon Glassset later by SetCalculatedProperties(). By that stage the size of sections 471078ab1a2SSimon Glasscannot be changed (since it would cause the images to need to be repacked), 472078ab1a2SSimon Glassbut the correct values can be inserted. 473078ab1a2SSimon Glass 474078ab1a2SSimon Glass2. ProcessFdt() - process the device tree information as required by the 475ecab8973SSimon Glassparticular entry. This may involve adding or deleting properties. If the 476ecab8973SSimon Glassprocessing is complete, this method should return True. If the processing 477ecab8973SSimon Glasscannot complete because it needs the ProcessFdt() method of another entry to 478ecab8973SSimon Glassrun first, this method should return False, in which case it will be called 479ecab8973SSimon Glassagain later. 480ecab8973SSimon Glass 481078ab1a2SSimon Glass3. GetEntryContents() - the contents of each entry are obtained, normally by 482bf7fd50bSSimon Glassreading from a file. This calls the Entry.ObtainContents() to read the 483bf7fd50bSSimon Glasscontents. The default version of Entry.ObtainContents() calls 484bf7fd50bSSimon GlassEntry.GetDefaultFilename() and then reads that file. So a common mechanism 485bf7fd50bSSimon Glassto select a file to read is to override that function in the subclass. The 486bf7fd50bSSimon Glassfunctions must return True when they have read the contents. Binman will 487bf7fd50bSSimon Glassretry calling the functions a few times if False is returned, allowing 488bf7fd50bSSimon Glassdependencies between the contents of different entries. 489bf7fd50bSSimon Glass 4903ab9598dSSimon Glass4. GetEntryOffsets() - calls Entry.GetOffsets() for each entry. This can 491bf7fd50bSSimon Glassreturn a dict containing entries that need updating. The key should be the 4923ab9598dSSimon Glassentry name and the value is a tuple (offset, size). This allows an entry to 4933ab9598dSSimon Glassprovide the offset and size for other entries. The default implementation 4943ab9598dSSimon Glassof GetEntryOffsets() returns {}. 495bf7fd50bSSimon Glass 4963ab9598dSSimon Glass5. PackEntries() - calls Entry.Pack() which figures out the offset and 4973ab9598dSSimon Glasssize of an entry. The 'current' image offset is passed in, and the function 4983ab9598dSSimon Glassreturns the offset immediately after the entry being packed. The default 499bf7fd50bSSimon Glassimplementation of Pack() is usually sufficient. 500bf7fd50bSSimon Glass 501078ab1a2SSimon Glass6. CheckSize() - checks that the contents of all the entries fits within 502bf7fd50bSSimon Glassthe image size. If the image does not have a defined size, the size is set 503bf7fd50bSSimon Glasslarge enough to hold all the entries. 504bf7fd50bSSimon Glass 505078ab1a2SSimon Glass7. CheckEntries() - checks that the entries do not overlap, nor extend 506bf7fd50bSSimon Glassoutside the image. 507bf7fd50bSSimon Glass 508078ab1a2SSimon Glass8. SetCalculatedProperties() - update any calculated properties in the device 5093ab9598dSSimon Glasstree. This sets the correct 'offset' and 'size' vaues, for example. 510078ab1a2SSimon Glass 511078ab1a2SSimon Glass9. ProcessEntryContents() - this calls Entry.ProcessContents() on each entry. 512bf7fd50bSSimon GlassThe default implementatoin does nothing. This can be overriden to adjust the 513bf7fd50bSSimon Glasscontents of an entry in some way. For example, it would be possible to create 514bf7fd50bSSimon Glassan entry containing a hash of the contents of some other entries. At this 5153ab9598dSSimon Glassstage the offset and size of entries should not be adjusted. 516bf7fd50bSSimon Glass 517078ab1a2SSimon Glass10. WriteSymbols() - write the value of symbols into the U-Boot SPL binary. 5183ab9598dSSimon GlassSee 'Access to binman entry offsets at run time' below for a description of 5190a4357c4SSimon Glasswhat happens in this stage. 52039c1502cSSimon Glass 521078ab1a2SSimon Glass11. BuildImage() - builds the image and writes it to a file. This is the final 522bf7fd50bSSimon Glassstep. 523bf7fd50bSSimon Glass 524bf7fd50bSSimon Glass 5256d427c6bSSimon GlassAutomatic .dtsi inclusion 5266d427c6bSSimon Glass------------------------- 5276d427c6bSSimon Glass 5286d427c6bSSimon GlassIt is sometimes inconvenient to add a 'binman' node to the .dts file for each 5296d427c6bSSimon Glassboard. This can be done by using #include to bring in a common file. Another 5306d427c6bSSimon Glassapproach supported by the U-Boot build system is to automatically include 5316d427c6bSSimon Glassa common header. You can then put the binman node (and anything else that is 5326d427c6bSSimon Glassspecific to U-Boot, such as u-boot,dm-pre-reloc properies) in that header 5336d427c6bSSimon Glassfile. 5346d427c6bSSimon Glass 5356d427c6bSSimon GlassBinman will search for the following files in arch/<arch>/dts: 5366d427c6bSSimon Glass 5376d427c6bSSimon Glass <dts>-u-boot.dtsi where <dts> is the base name of the .dts file 5386d427c6bSSimon Glass <CONFIG_SYS_SOC>-u-boot.dtsi 5396d427c6bSSimon Glass <CONFIG_SYS_CPU>-u-boot.dtsi 5406d427c6bSSimon Glass <CONFIG_SYS_VENDOR>-u-boot.dtsi 5416d427c6bSSimon Glass u-boot.dtsi 5426d427c6bSSimon Glass 5436d427c6bSSimon GlassU-Boot will only use the first one that it finds. If you need to include a 5446d427c6bSSimon Glassmore general file you can do that from the more specific file using #include. 5456d427c6bSSimon GlassIf you are having trouble figuring out what is going on, you can uncomment 5466d427c6bSSimon Glassthe 'warning' line in scripts/Makefile.lib to see what it has found: 5476d427c6bSSimon Glass 5486d427c6bSSimon Glass # Uncomment for debugging 549511fd0b2SSimon Glass # This shows all the files that were considered and the one that we chose. 550511fd0b2SSimon Glass # u_boot_dtsi_options_debug = $(u_boot_dtsi_options_raw) 5516d427c6bSSimon Glass 5526d427c6bSSimon Glass 5533ab9598dSSimon GlassAccess to binman entry offsets at run time 5543ab9598dSSimon Glass------------------------------------------ 55539c1502cSSimon Glass 55639c1502cSSimon GlassBinman assembles images and determines where each entry is placed in the image. 55739c1502cSSimon GlassThis information may be useful to U-Boot at run time. For example, in SPL it 55839c1502cSSimon Glassis useful to be able to find the location of U-Boot so that it can be executed 55939c1502cSSimon Glasswhen SPL is finished. 56039c1502cSSimon Glass 56139c1502cSSimon GlassBinman allows you to declare symbols in the SPL image which are filled in 56239c1502cSSimon Glasswith their correct values during the build. For example: 56339c1502cSSimon Glass 5643ab9598dSSimon Glass binman_sym_declare(ulong, u_boot_any, offset); 56539c1502cSSimon Glass 5663ab9598dSSimon Glassdeclares a ulong value which will be assigned to the offset of any U-Boot 56739c1502cSSimon Glassimage (u-boot.bin, u-boot.img, u-boot-nodtb.bin) that is present in the image. 56839c1502cSSimon GlassYou can access this value with something like: 56939c1502cSSimon Glass 5703ab9598dSSimon Glass ulong u_boot_offset = binman_sym(ulong, u_boot_any, offset); 57139c1502cSSimon Glass 5723ab9598dSSimon GlassThus u_boot_offset will be set to the offset of U-Boot in memory, assuming that 57339c1502cSSimon Glassthe whole image has been loaded, or is available in flash. You can then jump to 57439c1502cSSimon Glassthat address to start U-Boot. 57539c1502cSSimon Glass 57639c1502cSSimon GlassAt present this feature is only supported in SPL. In principle it is possible 57739c1502cSSimon Glassto fill in such symbols in U-Boot proper, as well. 57839c1502cSSimon Glass 57939c1502cSSimon Glass 5803b0c3821SSimon GlassMap files 5813b0c3821SSimon Glass--------- 5823b0c3821SSimon Glass 5833b0c3821SSimon GlassThe -m option causes binman to output a .map file for each image that it 5843ab9598dSSimon Glassgenerates. This shows the offset and size of each entry. For example: 5853b0c3821SSimon Glass 5863ab9598dSSimon Glass Offset Size Name 587*8122f396SSimon Glass 00000000 00000028 main-section 5883b0c3821SSimon Glass 00000000 00000010 section@0 5893b0c3821SSimon Glass 00000000 00000004 u-boot 5903b0c3821SSimon Glass 00000010 00000010 section@1 5913b0c3821SSimon Glass 00000000 00000004 u-boot 5923b0c3821SSimon Glass 5933b0c3821SSimon GlassThis shows a hierarchical image with two sections, each with a single entry. The 5943ab9598dSSimon Glassoffsets of the sections are absolute hex byte offsets within the image. The 5953ab9598dSSimon Glassoffsets of the entries are relative to their respective sections. The size of 5963b0c3821SSimon Glasseach entry is also shown, in bytes (hex). The indentation shows the entries 5973b0c3821SSimon Glassnested inside their sections. 5983b0c3821SSimon Glass 5993b0c3821SSimon Glass 6006d427c6bSSimon GlassCode coverage 6016d427c6bSSimon Glass------------- 6026d427c6bSSimon Glass 6036d427c6bSSimon GlassBinman is a critical tool and is designed to be very testable. Entry 6046d427c6bSSimon Glassimplementations target 100% test coverage. Run 'binman -T' to check this. 6056d427c6bSSimon Glass 6066d427c6bSSimon GlassTo enable Python test coverage on Debian-type distributions (e.g. Ubuntu): 6076d427c6bSSimon Glass 60816d836cdSTom Rini $ sudo apt-get install python-coverage python-pytest 6096d427c6bSSimon Glass 6106d427c6bSSimon Glass 611bf7fd50bSSimon GlassAdvanced Features / Technical docs 612bf7fd50bSSimon Glass---------------------------------- 613bf7fd50bSSimon Glass 614bf7fd50bSSimon GlassThe behaviour of entries is defined by the Entry class. All other entries are 615bf7fd50bSSimon Glassa subclass of this. An important subclass is Entry_blob which takes binary 616bf7fd50bSSimon Glassdata from a file and places it in the entry. In fact most entry types are 617bf7fd50bSSimon Glasssubclasses of Entry_blob. 618bf7fd50bSSimon Glass 619bf7fd50bSSimon GlassEach entry type is a separate file in the tools/binman/etype directory. Each 620bf7fd50bSSimon Glassfile contains a class called Entry_<type> where <type> is the entry type. 621bf7fd50bSSimon GlassNew entry types can be supported by adding new files in that directory. 622bf7fd50bSSimon GlassThese will automatically be detected by binman when needed. 623bf7fd50bSSimon Glass 624bf7fd50bSSimon GlassEntry properties are documented in entry.py. The entry subclasses are free 625bf7fd50bSSimon Glassto change the values of properties to support special behaviour. For example, 626bf7fd50bSSimon Glasswhen Entry_blob loads a file, it sets content_size to the size of the file. 627bf7fd50bSSimon GlassEntry classes can adjust other entries. For example, an entry that knows 6283ab9598dSSimon Glasswhere other entries should be positioned can set up those entries' offsets 629bf7fd50bSSimon Glassso they don't need to be set in the binman decription. It can also adjust 630bf7fd50bSSimon Glassentry contents. 631bf7fd50bSSimon Glass 632bf7fd50bSSimon GlassMost of the time such essoteric behaviour is not needed, but it can be 633bf7fd50bSSimon Glassessential for complex images. 634bf7fd50bSSimon Glass 6353ed0de31SSimon GlassIf you need to specify a particular device-tree compiler to use, you can define 6363ed0de31SSimon Glassthe DTC environment variable. This can be useful when the system dtc is too 6373ed0de31SSimon Glassold. 6383ed0de31SSimon Glass 639bf7fd50bSSimon Glass 640bf7fd50bSSimon GlassHistory / Credits 641bf7fd50bSSimon Glass----------------- 642bf7fd50bSSimon Glass 643bf7fd50bSSimon GlassBinman takes a lot of inspiration from a Chrome OS tool called 644bf7fd50bSSimon Glass'cros_bundle_firmware', which I wrote some years ago. That tool was based on 645bf7fd50bSSimon Glassa reasonably simple and sound design but has expanded greatly over the 646bf7fd50bSSimon Glassyears. In particular its handling of x86 images is convoluted. 647bf7fd50bSSimon Glass 6487ae5f315SSimon GlassQuite a few lessons have been learned which are hopefully applied here. 649bf7fd50bSSimon Glass 650bf7fd50bSSimon Glass 651bf7fd50bSSimon GlassDesign notes 652bf7fd50bSSimon Glass------------ 653bf7fd50bSSimon Glass 654bf7fd50bSSimon GlassOn the face of it, a tool to create firmware images should be fairly simple: 655bf7fd50bSSimon Glassjust find all the input binaries and place them at the right place in the 656bf7fd50bSSimon Glassimage. The difficulty comes from the wide variety of input types (simple 657bf7fd50bSSimon Glassflat binaries containing code, packaged data with various headers), packing 658bf7fd50bSSimon Glassrequirments (alignment, spacing, device boundaries) and other required 659bf7fd50bSSimon Glassfeatures such as hierarchical images. 660bf7fd50bSSimon Glass 661bf7fd50bSSimon GlassThe design challenge is to make it easy to create simple images, while 662bf7fd50bSSimon Glassallowing the more complex cases to be supported. For example, for most 663bf7fd50bSSimon Glassimages we don't much care exactly where each binary ends up, so we should 664bf7fd50bSSimon Glassnot have to specify that unnecessarily. 665bf7fd50bSSimon Glass 666bf7fd50bSSimon GlassNew entry types should aim to provide simple usage where possible. If new 667bf7fd50bSSimon Glasscore features are needed, they can be added in the Entry base class. 668bf7fd50bSSimon Glass 669bf7fd50bSSimon Glass 670bf7fd50bSSimon GlassTo do 671bf7fd50bSSimon Glass----- 672bf7fd50bSSimon Glass 673bf7fd50bSSimon GlassSome ideas: 674bf7fd50bSSimon Glass- Use of-platdata to make the information available to code that is unable 675bf7fd50bSSimon Glass to use device tree (such as a very small SPL image) 676bf7fd50bSSimon Glass- Allow easy building of images by specifying just the board name 67716b8d6b7SSimon Glass- Produce a full Python binding for libfdt (for upstream). This is nearing 67816b8d6b7SSimon Glass completion but some work remains 679bf7fd50bSSimon Glass- Add an option to decode an image into the constituent binaries 680bf7fd50bSSimon Glass- Support building an image for a board (-b) more completely, with a 681bf7fd50bSSimon Glass configurable build directory 682bf7fd50bSSimon Glass- Consider making binman work with buildman, although if it is used in the 683bf7fd50bSSimon Glass Makefile, this will be automatic 684bf7fd50bSSimon Glass 685bf7fd50bSSimon Glass-- 686bf7fd50bSSimon GlassSimon Glass <sjg@chromium.org> 687bf7fd50bSSimon Glass7/7/2016 688