1bf7fd50bSSimon Glass# Copyright (c) 2016 Google, Inc 2bf7fd50bSSimon Glass# 3bf7fd50bSSimon Glass# SPDX-License-Identifier: GPL-2.0+ 4bf7fd50bSSimon Glass# 5bf7fd50bSSimon Glass 6bf7fd50bSSimon GlassIntroduction 7bf7fd50bSSimon Glass------------ 8bf7fd50bSSimon Glass 9bf7fd50bSSimon GlassFirmware often consists of several components which must be packaged together. 10bf7fd50bSSimon GlassFor example, we may have SPL, U-Boot, a device tree and an environment area 11bf7fd50bSSimon Glassgrouped together and placed in MMC flash. When the system starts, it must be 12bf7fd50bSSimon Glassable to find these pieces. 13bf7fd50bSSimon Glass 14bf7fd50bSSimon GlassSo far U-Boot has not provided a way to handle creating such images in a 15bf7fd50bSSimon Glassgeneral way. Each SoC does what it needs to build an image, often packing or 16bf7fd50bSSimon Glassconcatenating images in the U-Boot build system. 17bf7fd50bSSimon Glass 18bf7fd50bSSimon GlassBinman aims to provide a mechanism for building images, from simple 19bf7fd50bSSimon GlassSPL + U-Boot combinations, to more complex arrangements with many parts. 20bf7fd50bSSimon Glass 21bf7fd50bSSimon Glass 22bf7fd50bSSimon GlassWhat it does 23bf7fd50bSSimon Glass------------ 24bf7fd50bSSimon Glass 25bf7fd50bSSimon GlassBinman reads your board's device tree and finds a node which describes the 26bf7fd50bSSimon Glassrequired image layout. It uses this to work out what to place where. The 27bf7fd50bSSimon Glassoutput file normally contains the device tree, so it is in principle possible 28bf7fd50bSSimon Glassto read an image and extract its constituent parts. 29bf7fd50bSSimon Glass 30bf7fd50bSSimon Glass 31bf7fd50bSSimon GlassFeatures 32bf7fd50bSSimon Glass-------- 33bf7fd50bSSimon Glass 34bf7fd50bSSimon GlassSo far binman is pretty simple. It supports binary blobs, such as 'u-boot', 35bf7fd50bSSimon Glass'spl' and 'fdt'. It supports empty entries (such as setting to 0xff). It can 36bf7fd50bSSimon Glassplace entries at a fixed location in the image, or fit them together with 37bf7fd50bSSimon Glasssuitable padding and alignment. It provides a way to process binaries before 38bf7fd50bSSimon Glassthey are included, by adding a Python plug-in. The device tree is available 39bf7fd50bSSimon Glassto U-Boot at run-time so that the images can be interpreted. 40bf7fd50bSSimon Glass 41bf7fd50bSSimon GlassBinman does not yet update the device tree with the final location of 42bf7fd50bSSimon Glasseverything when it is done. A simple C structure could be generated for 43bf7fd50bSSimon Glassconstrained environments like SPL (using dtoc) but this is also not 44bf7fd50bSSimon Glassimplemented. 45bf7fd50bSSimon Glass 46bf7fd50bSSimon GlassBinman can also support incorporating filesystems in the image if required. 47bf7fd50bSSimon GlassFor example x86 platforms may use CBFS in some cases. 48bf7fd50bSSimon Glass 49bf7fd50bSSimon GlassBinman is intended for use with U-Boot but is designed to be general enough 50bf7fd50bSSimon Glassto be useful in other image-packaging situations. 51bf7fd50bSSimon Glass 52bf7fd50bSSimon Glass 53bf7fd50bSSimon GlassMotivation 54bf7fd50bSSimon Glass---------- 55bf7fd50bSSimon Glass 56bf7fd50bSSimon GlassPackaging of firmware is quite a different task from building the various 57bf7fd50bSSimon Glassparts. In many cases the various binaries which go into the image come from 58bf7fd50bSSimon Glassseparate build systems. For example, ARM Trusted Firmware is used on ARMv8 59bf7fd50bSSimon Glassdevices but is not built in the U-Boot tree. If a Linux kernel is included 60bf7fd50bSSimon Glassin the firmware image, it is built elsewhere. 61bf7fd50bSSimon Glass 62bf7fd50bSSimon GlassIt is of course possible to add more and more build rules to the U-Boot 63bf7fd50bSSimon Glassbuild system to cover these cases. It can shell out to other Makefiles and 64bf7fd50bSSimon Glassbuild scripts. But it seems better to create a clear divide between building 65bf7fd50bSSimon Glasssoftware and packaging it. 66bf7fd50bSSimon Glass 67bf7fd50bSSimon GlassAt present this is handled by manual instructions, different for each board, 68bf7fd50bSSimon Glasson how to create images that will boot. By turning these instructions into a 69bf7fd50bSSimon Glassstandard format, we can support making valid images for any board without 70bf7fd50bSSimon Glassmanual effort, lots of READMEs, etc. 71bf7fd50bSSimon Glass 72bf7fd50bSSimon GlassBenefits: 73bf7fd50bSSimon Glass- Each binary can have its own build system and tool chain without creating 74bf7fd50bSSimon Glassany dependencies between them 75bf7fd50bSSimon Glass- Avoids the need for a single-shot build: individual parts can be updated 76bf7fd50bSSimon Glassand brought in as needed 77bf7fd50bSSimon Glass- Provides for a standard image description available in the build and at 78bf7fd50bSSimon Glassrun-time 79bf7fd50bSSimon Glass- SoC-specific image-signing tools can be accomodated 80bf7fd50bSSimon Glass- Avoids cluttering the U-Boot build system with image-building code 81bf7fd50bSSimon Glass- The image description is automatically available at run-time in U-Boot, 82bf7fd50bSSimon GlassSPL. It can be made available to other software also 83bf7fd50bSSimon Glass- The image description is easily readable (it's a text file in device-tree 84bf7fd50bSSimon Glassformat) and permits flexible packing of binaries 85bf7fd50bSSimon Glass 86bf7fd50bSSimon Glass 87bf7fd50bSSimon GlassTerminology 88bf7fd50bSSimon Glass----------- 89bf7fd50bSSimon Glass 90bf7fd50bSSimon GlassBinman uses the following terms: 91bf7fd50bSSimon Glass 92bf7fd50bSSimon Glass- image - an output file containing a firmware image 93bf7fd50bSSimon Glass- binary - an input binary that goes into the image 94bf7fd50bSSimon Glass 95bf7fd50bSSimon Glass 96bf7fd50bSSimon GlassRelationship to FIT 97bf7fd50bSSimon Glass------------------- 98bf7fd50bSSimon Glass 99bf7fd50bSSimon GlassFIT is U-Boot's official image format. It supports multiple binaries with 100bf7fd50bSSimon Glassload / execution addresses, compression. It also supports verification 101bf7fd50bSSimon Glassthrough hashing and RSA signatures. 102bf7fd50bSSimon Glass 103bf7fd50bSSimon GlassFIT was originally designed to support booting a Linux kernel (with an 104bf7fd50bSSimon Glassoptional ramdisk) and device tree chosen from various options in the FIT. 105bf7fd50bSSimon GlassNow that U-Boot supports configuration via device tree, it is possible to 106bf7fd50bSSimon Glassload U-Boot from a FIT, with the device tree chosen by SPL. 107bf7fd50bSSimon Glass 108bf7fd50bSSimon GlassBinman considers FIT to be one of the binaries it can place in the image. 109bf7fd50bSSimon Glass 110bf7fd50bSSimon GlassWhere possible it is best to put as much as possible in the FIT, with binman 111bf7fd50bSSimon Glassused to deal with cases not covered by FIT. Examples include initial 112bf7fd50bSSimon Glassexecution (since FIT itself does not have an executable header) and dealing 113bf7fd50bSSimon Glasswith device boundaries, such as the read-only/read-write separation in SPI 114bf7fd50bSSimon Glassflash. 115bf7fd50bSSimon Glass 116bf7fd50bSSimon GlassFor U-Boot, binman should not be used to create ad-hoc images in place of 117bf7fd50bSSimon GlassFIT. 118bf7fd50bSSimon Glass 119bf7fd50bSSimon Glass 120bf7fd50bSSimon GlassRelationship to mkimage 121bf7fd50bSSimon Glass----------------------- 122bf7fd50bSSimon Glass 123bf7fd50bSSimon GlassThe mkimage tool provides a means to create a FIT. Traditionally it has 124bf7fd50bSSimon Glassneeded an image description file: a device tree, like binman, but in a 125bf7fd50bSSimon Glassdifferent format. More recently it has started to support a '-f auto' mode 126bf7fd50bSSimon Glasswhich can generate that automatically. 127bf7fd50bSSimon Glass 128bf7fd50bSSimon GlassMore relevant to binman, mkimage also permits creation of many SoC-specific 129bf7fd50bSSimon Glassimage types. These can be listed by running 'mkimage -T list'. Examples 130bf7fd50bSSimon Glassinclude 'rksd', the Rockchip SD/MMC boot format. The mkimage tool is often 131bf7fd50bSSimon Glasscalled from the U-Boot build system for this reason. 132bf7fd50bSSimon Glass 133bf7fd50bSSimon GlassBinman considers the output files created by mkimage to be binary blobs 134bf7fd50bSSimon Glasswhich it can place in an image. Binman does not replace the mkimage tool or 135bf7fd50bSSimon Glassthis purpose. It would be possible in some situtions to create a new entry 136bf7fd50bSSimon Glasstype for the images in mkimage, but this would not add functionality. It 137bf7fd50bSSimon Glassseems better to use the mkiamge tool to generate binaries and avoid blurring 138bf7fd50bSSimon Glassthe boundaries between building input files (mkimage) and packaging then 139bf7fd50bSSimon Glassinto a final image (binman). 140bf7fd50bSSimon Glass 141bf7fd50bSSimon Glass 142bf7fd50bSSimon GlassExample use of binman in U-Boot 143bf7fd50bSSimon Glass------------------------------- 144bf7fd50bSSimon Glass 145bf7fd50bSSimon GlassBinman aims to replace some of the ad-hoc image creation in the U-Boot 146bf7fd50bSSimon Glassbuild system. 147bf7fd50bSSimon Glass 148bf7fd50bSSimon GlassConsider sunxi. It has the following steps: 149bf7fd50bSSimon Glass 150bf7fd50bSSimon Glass1. It uses a custom mksunxiboot tool to build an SPL image called 151bf7fd50bSSimon Glasssunxi-spl.bin. This should probably move into mkimage. 152bf7fd50bSSimon Glass 153bf7fd50bSSimon Glass2. It uses mkimage to package U-Boot into a legacy image file (so that it can 154bf7fd50bSSimon Glasshold the load and execution address) called u-boot.img. 155bf7fd50bSSimon Glass 156bf7fd50bSSimon Glass3. It builds a final output image called u-boot-sunxi-with-spl.bin which 157bf7fd50bSSimon Glassconsists of sunxi-spl.bin, some padding and u-boot.img. 158bf7fd50bSSimon Glass 159bf7fd50bSSimon GlassBinman is intended to replace the last step. The U-Boot build system builds 160bf7fd50bSSimon Glassu-boot.bin and sunxi-spl.bin. Binman can then take over creation of 161bf7fd50bSSimon Glasssunxi-spl.bin (by calling mksunxiboot, or hopefully one day mkimage). In any 162bf7fd50bSSimon Glasscase, it would then create the image from the component parts. 163bf7fd50bSSimon Glass 164bf7fd50bSSimon GlassThis simplifies the U-Boot Makefile somewhat, since various pieces of logic 165bf7fd50bSSimon Glasscan be replaced by a call to binman. 166bf7fd50bSSimon Glass 167bf7fd50bSSimon Glass 168bf7fd50bSSimon GlassExample use of binman for x86 169bf7fd50bSSimon Glass----------------------------- 170bf7fd50bSSimon Glass 171bf7fd50bSSimon GlassIn most cases x86 images have a lot of binary blobs, 'black-box' code 172bf7fd50bSSimon Glassprovided by Intel which must be run for the platform to work. Typically 173bf7fd50bSSimon Glassthese blobs are not relocatable and must be placed at fixed areas in the 174bf7fd50bSSimon Glassfirmare image. 175bf7fd50bSSimon Glass 176bf7fd50bSSimon GlassCurrently this is handled by ifdtool, which places microcode, FSP, MRC, VGA 177bf7fd50bSSimon GlassBIOS, reference code and Intel ME binaries into a u-boot.rom file. 178bf7fd50bSSimon Glass 179bf7fd50bSSimon GlassBinman is intended to replace all of this, with ifdtool left to handle only 180bf7fd50bSSimon Glassthe configuration of the Intel-format descriptor. 181bf7fd50bSSimon Glass 182bf7fd50bSSimon Glass 183bf7fd50bSSimon GlassRunning binman 184bf7fd50bSSimon Glass-------------- 185bf7fd50bSSimon Glass 186bf7fd50bSSimon GlassType: 187bf7fd50bSSimon Glass 188bf7fd50bSSimon Glass binman -b <board_name> 189bf7fd50bSSimon Glass 190bf7fd50bSSimon Glassto build an image for a board. The board name is the same name used when 191bf7fd50bSSimon Glassconfiguring U-Boot (e.g. for sandbox_defconfig the board name is 'sandbox'). 192bf7fd50bSSimon GlassBinman assumes that the input files for the build are in ../b/<board_name>. 193bf7fd50bSSimon Glass 194bf7fd50bSSimon GlassOr you can specify this explicitly: 195bf7fd50bSSimon Glass 196bf7fd50bSSimon Glass binman -I <build_path> 197bf7fd50bSSimon Glass 198bf7fd50bSSimon Glasswhere <build_path> is the build directory containing the output of the U-Boot 199bf7fd50bSSimon Glassbuild. 200bf7fd50bSSimon Glass 201bf7fd50bSSimon Glass(Future work will make this more configurable) 202bf7fd50bSSimon Glass 203bf7fd50bSSimon GlassIn either case, binman picks up the device tree file (u-boot.dtb) and looks 204bf7fd50bSSimon Glassfor its instructions in the 'binman' node. 205bf7fd50bSSimon Glass 206bf7fd50bSSimon GlassBinman has a few other options which you can see by running 'binman -h'. 207bf7fd50bSSimon Glass 208bf7fd50bSSimon Glass 209bf7fd50bSSimon GlassImage description format 210bf7fd50bSSimon Glass------------------------ 211bf7fd50bSSimon Glass 212bf7fd50bSSimon GlassThe binman node is called 'binman'. An example image description is shown 213bf7fd50bSSimon Glassbelow: 214bf7fd50bSSimon Glass 215bf7fd50bSSimon Glass binman { 216bf7fd50bSSimon Glass filename = "u-boot-sunxi-with-spl.bin"; 217bf7fd50bSSimon Glass pad-byte = <0xff>; 218bf7fd50bSSimon Glass blob { 219bf7fd50bSSimon Glass filename = "spl/sunxi-spl.bin"; 220bf7fd50bSSimon Glass }; 221bf7fd50bSSimon Glass u-boot { 222bf7fd50bSSimon Glass pos = <CONFIG_SPL_PAD_TO>; 223bf7fd50bSSimon Glass }; 224bf7fd50bSSimon Glass }; 225bf7fd50bSSimon Glass 226bf7fd50bSSimon Glass 227bf7fd50bSSimon GlassThis requests binman to create an image file called u-boot-sunxi-with-spl.bin 228bf7fd50bSSimon Glassconsisting of a specially formatted SPL (spl/sunxi-spl.bin, built by the 229bf7fd50bSSimon Glassnormal U-Boot Makefile), some 0xff padding, and a U-Boot legacy image. The 230bf7fd50bSSimon Glasspadding comes from the fact that the second binary is placed at 231bf7fd50bSSimon GlassCONFIG_SPL_PAD_TO. If that line were omitted then the U-Boot binary would 232bf7fd50bSSimon Glassimmediately follow the SPL binary. 233bf7fd50bSSimon Glass 234bf7fd50bSSimon GlassThe binman node describes an image. The sub-nodes describe entries in the 235bf7fd50bSSimon Glassimage. Each entry represents a region within the overall image. The name of 236bf7fd50bSSimon Glassthe entry (blob, u-boot) tells binman what to put there. For 'blob' we must 237bf7fd50bSSimon Glassprovide a filename. For 'u-boot', binman knows that this means 'u-boot.bin'. 238bf7fd50bSSimon Glass 239bf7fd50bSSimon GlassEntries are normally placed into the image sequentially, one after the other. 240bf7fd50bSSimon GlassThe image size is the total size of all entries. As you can see, you can 241bf7fd50bSSimon Glassspecify the start position of an entry using the 'pos' property. 242bf7fd50bSSimon Glass 243bf7fd50bSSimon GlassNote that due to a device tree requirement, all entries must have a unique 244bf7fd50bSSimon Glassname. If you want to put the same binary in the image multiple times, you can 245bf7fd50bSSimon Glassuse any unique name, with the 'type' property providing the type. 246bf7fd50bSSimon Glass 247bf7fd50bSSimon GlassThe attributes supported for entries are described below. 248bf7fd50bSSimon Glass 249bf7fd50bSSimon Glasspos: 250bf7fd50bSSimon Glass This sets the position of an entry within the image. The first byte 251bf7fd50bSSimon Glass of the image is normally at position 0. If 'pos' is not provided, 252bf7fd50bSSimon Glass binman sets it to the end of the previous region, or the start of 253bf7fd50bSSimon Glass the image's entry area (normally 0) if there is no previous region. 254bf7fd50bSSimon Glass 255bf7fd50bSSimon Glassalign: 256bf7fd50bSSimon Glass This sets the alignment of the entry. The entry position is adjusted 257bf7fd50bSSimon Glass so that the entry starts on an aligned boundary within the image. For 258bf7fd50bSSimon Glass example 'align = <16>' means that the entry will start on a 16-byte 259bf7fd50bSSimon Glass boundary. Alignment shold be a power of 2. If 'align' is not 260bf7fd50bSSimon Glass provided, no alignment is performed. 261bf7fd50bSSimon Glass 262bf7fd50bSSimon Glasssize: 263bf7fd50bSSimon Glass This sets the size of the entry. The contents will be padded out to 264bf7fd50bSSimon Glass this size. If this is not provided, it will be set to the size of the 265bf7fd50bSSimon Glass contents. 266bf7fd50bSSimon Glass 267bf7fd50bSSimon Glasspad-before: 268bf7fd50bSSimon Glass Padding before the contents of the entry. Normally this is 0, meaning 269bf7fd50bSSimon Glass that the contents start at the beginning of the entry. This can be 270bf7fd50bSSimon Glass offset the entry contents a little. Defaults to 0. 271bf7fd50bSSimon Glass 272bf7fd50bSSimon Glasspad-after: 273bf7fd50bSSimon Glass Padding after the contents of the entry. Normally this is 0, meaning 274bf7fd50bSSimon Glass that the entry ends at the last byte of content (unless adjusted by 275bf7fd50bSSimon Glass other properties). This allows room to be created in the image for 276bf7fd50bSSimon Glass this entry to expand later. Defaults to 0. 277bf7fd50bSSimon Glass 278bf7fd50bSSimon Glassalign-size: 279bf7fd50bSSimon Glass This sets the alignment of the entry size. For example, to ensure 280bf7fd50bSSimon Glass that the size of an entry is a multiple of 64 bytes, set this to 64. 281bf7fd50bSSimon Glass If 'align-size' is not provided, no alignment is performed. 282bf7fd50bSSimon Glass 283bf7fd50bSSimon Glassalign-end: 284bf7fd50bSSimon Glass This sets the alignment of the end of an entry. Some entries require 285bf7fd50bSSimon Glass that they end on an alignment boundary, regardless of where they 286bf7fd50bSSimon Glass start. If 'align-end' is not provided, no alignment is performed. 287bf7fd50bSSimon Glass 288bf7fd50bSSimon Glass Note: This is not yet implemented in binman. 289bf7fd50bSSimon Glass 290bf7fd50bSSimon Glassfilename: 291bf7fd50bSSimon Glass For 'blob' types this provides the filename containing the binary to 292bf7fd50bSSimon Glass put into the entry. If binman knows about the entry type (like 293bf7fd50bSSimon Glass u-boot-bin), then there is no need to specify this. 294bf7fd50bSSimon Glass 295bf7fd50bSSimon Glasstype: 296bf7fd50bSSimon Glass Sets the type of an entry. This defaults to the entry name, but it is 297bf7fd50bSSimon Glass possible to use any name, and then add (for example) 'type = "u-boot"' 298bf7fd50bSSimon Glass to specify the type. 299bf7fd50bSSimon Glass 300bf7fd50bSSimon Glass 301bf7fd50bSSimon GlassThe attributes supported for images are described below. Several are similar 302bf7fd50bSSimon Glassto those for entries. 303bf7fd50bSSimon Glass 304bf7fd50bSSimon Glasssize: 305bf7fd50bSSimon Glass Sets the image size in bytes, for example 'size = <0x100000>' for a 306bf7fd50bSSimon Glass 1MB image. 307bf7fd50bSSimon Glass 308bf7fd50bSSimon Glassalign-size: 309bf7fd50bSSimon Glass This sets the alignment of the image size. For example, to ensure 310bf7fd50bSSimon Glass that the image ends on a 512-byte boundary, use 'align-size = <512>'. 311bf7fd50bSSimon Glass If 'align-size' is not provided, no alignment is performed. 312bf7fd50bSSimon Glass 313bf7fd50bSSimon Glasspad-before: 314bf7fd50bSSimon Glass This sets the padding before the image entries. The first entry will 315bf7fd50bSSimon Glass be positionad after the padding. This defaults to 0. 316bf7fd50bSSimon Glass 317bf7fd50bSSimon Glasspad-after: 318bf7fd50bSSimon Glass This sets the padding after the image entries. The padding will be 319bf7fd50bSSimon Glass placed after the last entry. This defaults to 0. 320bf7fd50bSSimon Glass 321bf7fd50bSSimon Glasspad-byte: 322bf7fd50bSSimon Glass This specifies the pad byte to use when padding in the image. It 323bf7fd50bSSimon Glass defaults to 0. To use 0xff, you would add 'pad-byte = <0xff>'. 324bf7fd50bSSimon Glass 325bf7fd50bSSimon Glassfilename: 326bf7fd50bSSimon Glass This specifies the image filename. It defaults to 'image.bin'. 327bf7fd50bSSimon Glass 328bf7fd50bSSimon Glasssort-by-pos: 329bf7fd50bSSimon Glass This causes binman to reorder the entries as needed to make sure they 330bf7fd50bSSimon Glass are in increasing positional order. This can be used when your entry 331bf7fd50bSSimon Glass order may not match the positional order. A common situation is where 332bf7fd50bSSimon Glass the 'pos' properties are set by CONFIG options, so their ordering is 333bf7fd50bSSimon Glass not known a priori. 334bf7fd50bSSimon Glass 335bf7fd50bSSimon Glass This is a boolean property so needs no value. To enable it, add a 336bf7fd50bSSimon Glass line 'sort-by-pos;' to your description. 337bf7fd50bSSimon Glass 338bf7fd50bSSimon Glassmultiple-images: 339bf7fd50bSSimon Glass Normally only a single image is generated. To create more than one 340bf7fd50bSSimon Glass image, put this property in the binman node. For example, this will 341bf7fd50bSSimon Glass create image1.bin containing u-boot.bin, and image2.bin containing 342bf7fd50bSSimon Glass both spl/u-boot-spl.bin and u-boot.bin: 343bf7fd50bSSimon Glass 344bf7fd50bSSimon Glass binman { 345bf7fd50bSSimon Glass multiple-images; 346bf7fd50bSSimon Glass image1 { 347bf7fd50bSSimon Glass u-boot { 348bf7fd50bSSimon Glass }; 349bf7fd50bSSimon Glass }; 350bf7fd50bSSimon Glass 351bf7fd50bSSimon Glass image2 { 352bf7fd50bSSimon Glass spl { 353bf7fd50bSSimon Glass }; 354bf7fd50bSSimon Glass u-boot { 355bf7fd50bSSimon Glass }; 356bf7fd50bSSimon Glass }; 357bf7fd50bSSimon Glass }; 358bf7fd50bSSimon Glass 359bf7fd50bSSimon Glassend-at-4gb: 360bf7fd50bSSimon Glass For x86 machines the ROM positions start just before 4GB and extend 361bf7fd50bSSimon Glass up so that the image finished at the 4GB boundary. This boolean 362bf7fd50bSSimon Glass option can be enabled to support this. The image size must be 363bf7fd50bSSimon Glass provided so that binman knows when the image should start. For an 364bf7fd50bSSimon Glass 8MB ROM, the position of the first entry would be 0xfff80000 with 365bf7fd50bSSimon Glass this option, instead of 0 without this option. 366bf7fd50bSSimon Glass 367bf7fd50bSSimon Glass 368bf7fd50bSSimon GlassExamples of the above options can be found in the tests. See the 369bf7fd50bSSimon Glasstools/binman/test directory. 370bf7fd50bSSimon Glass 371bf7fd50bSSimon Glass 372e0ff8551SSimon GlassSpecial properties 373e0ff8551SSimon Glass------------------ 374e0ff8551SSimon Glass 375e0ff8551SSimon GlassSome entries support special properties, documented here: 376e0ff8551SSimon Glass 377e0ff8551SSimon Glassu-boot-with-ucode-ptr: 378e0ff8551SSimon Glass optional-ucode: boolean property to make microcode optional. If the 379e0ff8551SSimon Glass u-boot.bin image does not include microcode, no error will 380e0ff8551SSimon Glass be generated. 381e0ff8551SSimon Glass 382e0ff8551SSimon Glass 383bf7fd50bSSimon GlassOrder of image creation 384bf7fd50bSSimon Glass----------------------- 385bf7fd50bSSimon Glass 386bf7fd50bSSimon GlassImage creation proceeds in the following order, for each entry in the image. 387bf7fd50bSSimon Glass 388bf7fd50bSSimon Glass1. GetEntryContents() - the contents of each entry are obtained, normally by 389bf7fd50bSSimon Glassreading from a file. This calls the Entry.ObtainContents() to read the 390bf7fd50bSSimon Glasscontents. The default version of Entry.ObtainContents() calls 391bf7fd50bSSimon GlassEntry.GetDefaultFilename() and then reads that file. So a common mechanism 392bf7fd50bSSimon Glassto select a file to read is to override that function in the subclass. The 393bf7fd50bSSimon Glassfunctions must return True when they have read the contents. Binman will 394bf7fd50bSSimon Glassretry calling the functions a few times if False is returned, allowing 395bf7fd50bSSimon Glassdependencies between the contents of different entries. 396bf7fd50bSSimon Glass 397bf7fd50bSSimon Glass2. GetEntryPositions() - calls Entry.GetPositions() for each entry. This can 398bf7fd50bSSimon Glassreturn a dict containing entries that need updating. The key should be the 399bf7fd50bSSimon Glassentry name and the value is a tuple (pos, size). This allows an entry to 400bf7fd50bSSimon Glassprovide the position and size for other entries. The default implementation 401bf7fd50bSSimon Glassof GetEntryPositions() returns {}. 402bf7fd50bSSimon Glass 403bf7fd50bSSimon Glass3. PackEntries() - calls Entry.Pack() which figures out the position and 404bf7fd50bSSimon Glasssize of an entry. The 'current' image position is passed in, and the function 405bf7fd50bSSimon Glassreturns the position immediately after the entry being packed. The default 406bf7fd50bSSimon Glassimplementation of Pack() is usually sufficient. 407bf7fd50bSSimon Glass 408bf7fd50bSSimon Glass4. CheckSize() - checks that the contents of all the entries fits within 409bf7fd50bSSimon Glassthe image size. If the image does not have a defined size, the size is set 410bf7fd50bSSimon Glasslarge enough to hold all the entries. 411bf7fd50bSSimon Glass 412bf7fd50bSSimon Glass5. CheckEntries() - checks that the entries do not overlap, nor extend 413bf7fd50bSSimon Glassoutside the image. 414bf7fd50bSSimon Glass 415bf7fd50bSSimon Glass6. ProcessEntryContents() - this calls Entry.ProcessContents() on each entry. 416bf7fd50bSSimon GlassThe default implementatoin does nothing. This can be overriden to adjust the 417bf7fd50bSSimon Glasscontents of an entry in some way. For example, it would be possible to create 418bf7fd50bSSimon Glassan entry containing a hash of the contents of some other entries. At this 419bf7fd50bSSimon Glassstage the position and size of entries should not be adjusted. 420bf7fd50bSSimon Glass 421bf7fd50bSSimon Glass7. BuildImage() - builds the image and writes it to a file. This is the final 422bf7fd50bSSimon Glassstep. 423bf7fd50bSSimon Glass 424bf7fd50bSSimon Glass 425*6d427c6bSSimon GlassAutomatic .dtsi inclusion 426*6d427c6bSSimon Glass------------------------- 427*6d427c6bSSimon Glass 428*6d427c6bSSimon GlassIt is sometimes inconvenient to add a 'binman' node to the .dts file for each 429*6d427c6bSSimon Glassboard. This can be done by using #include to bring in a common file. Another 430*6d427c6bSSimon Glassapproach supported by the U-Boot build system is to automatically include 431*6d427c6bSSimon Glassa common header. You can then put the binman node (and anything else that is 432*6d427c6bSSimon Glassspecific to U-Boot, such as u-boot,dm-pre-reloc properies) in that header 433*6d427c6bSSimon Glassfile. 434*6d427c6bSSimon Glass 435*6d427c6bSSimon GlassBinman will search for the following files in arch/<arch>/dts: 436*6d427c6bSSimon Glass 437*6d427c6bSSimon Glass <dts>-u-boot.dtsi where <dts> is the base name of the .dts file 438*6d427c6bSSimon Glass <CONFIG_SYS_SOC>-u-boot.dtsi 439*6d427c6bSSimon Glass <CONFIG_SYS_CPU>-u-boot.dtsi 440*6d427c6bSSimon Glass <CONFIG_SYS_VENDOR>-u-boot.dtsi 441*6d427c6bSSimon Glass u-boot.dtsi 442*6d427c6bSSimon Glass 443*6d427c6bSSimon GlassU-Boot will only use the first one that it finds. If you need to include a 444*6d427c6bSSimon Glassmore general file you can do that from the more specific file using #include. 445*6d427c6bSSimon GlassIf you are having trouble figuring out what is going on, you can uncomment 446*6d427c6bSSimon Glassthe 'warning' line in scripts/Makefile.lib to see what it has found: 447*6d427c6bSSimon Glass 448*6d427c6bSSimon Glass # Uncomment for debugging 449*6d427c6bSSimon Glass # $(warning binman_dtsi_options: $(binman_dtsi_options)) 450*6d427c6bSSimon Glass 451*6d427c6bSSimon Glass 452*6d427c6bSSimon GlassCode coverage 453*6d427c6bSSimon Glass------------- 454*6d427c6bSSimon Glass 455*6d427c6bSSimon GlassBinman is a critical tool and is designed to be very testable. Entry 456*6d427c6bSSimon Glassimplementations target 100% test coverage. Run 'binman -T' to check this. 457*6d427c6bSSimon Glass 458*6d427c6bSSimon GlassTo enable Python test coverage on Debian-type distributions (e.g. Ubuntu): 459*6d427c6bSSimon Glass 460*6d427c6bSSimon Glass $ sudo apt-get install python-pip python-pytest 461*6d427c6bSSimon Glass $ sudo pip install coverage 462*6d427c6bSSimon Glass 463*6d427c6bSSimon Glass 464bf7fd50bSSimon GlassAdvanced Features / Technical docs 465bf7fd50bSSimon Glass---------------------------------- 466bf7fd50bSSimon Glass 467bf7fd50bSSimon GlassThe behaviour of entries is defined by the Entry class. All other entries are 468bf7fd50bSSimon Glassa subclass of this. An important subclass is Entry_blob which takes binary 469bf7fd50bSSimon Glassdata from a file and places it in the entry. In fact most entry types are 470bf7fd50bSSimon Glasssubclasses of Entry_blob. 471bf7fd50bSSimon Glass 472bf7fd50bSSimon GlassEach entry type is a separate file in the tools/binman/etype directory. Each 473bf7fd50bSSimon Glassfile contains a class called Entry_<type> where <type> is the entry type. 474bf7fd50bSSimon GlassNew entry types can be supported by adding new files in that directory. 475bf7fd50bSSimon GlassThese will automatically be detected by binman when needed. 476bf7fd50bSSimon Glass 477bf7fd50bSSimon GlassEntry properties are documented in entry.py. The entry subclasses are free 478bf7fd50bSSimon Glassto change the values of properties to support special behaviour. For example, 479bf7fd50bSSimon Glasswhen Entry_blob loads a file, it sets content_size to the size of the file. 480bf7fd50bSSimon GlassEntry classes can adjust other entries. For example, an entry that knows 481bf7fd50bSSimon Glasswhere other entries should be positioned can set up those entries' positions 482bf7fd50bSSimon Glassso they don't need to be set in the binman decription. It can also adjust 483bf7fd50bSSimon Glassentry contents. 484bf7fd50bSSimon Glass 485bf7fd50bSSimon GlassMost of the time such essoteric behaviour is not needed, but it can be 486bf7fd50bSSimon Glassessential for complex images. 487bf7fd50bSSimon Glass 488bf7fd50bSSimon Glass 489bf7fd50bSSimon GlassHistory / Credits 490bf7fd50bSSimon Glass----------------- 491bf7fd50bSSimon Glass 492bf7fd50bSSimon GlassBinman takes a lot of inspiration from a Chrome OS tool called 493bf7fd50bSSimon Glass'cros_bundle_firmware', which I wrote some years ago. That tool was based on 494bf7fd50bSSimon Glassa reasonably simple and sound design but has expanded greatly over the 495bf7fd50bSSimon Glassyears. In particular its handling of x86 images is convoluted. 496bf7fd50bSSimon Glass 497bf7fd50bSSimon GlassQuite a few lessons have been learned which are hopefully be applied here. 498bf7fd50bSSimon Glass 499bf7fd50bSSimon Glass 500bf7fd50bSSimon GlassDesign notes 501bf7fd50bSSimon Glass------------ 502bf7fd50bSSimon Glass 503bf7fd50bSSimon GlassOn the face of it, a tool to create firmware images should be fairly simple: 504bf7fd50bSSimon Glassjust find all the input binaries and place them at the right place in the 505bf7fd50bSSimon Glassimage. The difficulty comes from the wide variety of input types (simple 506bf7fd50bSSimon Glassflat binaries containing code, packaged data with various headers), packing 507bf7fd50bSSimon Glassrequirments (alignment, spacing, device boundaries) and other required 508bf7fd50bSSimon Glassfeatures such as hierarchical images. 509bf7fd50bSSimon Glass 510bf7fd50bSSimon GlassThe design challenge is to make it easy to create simple images, while 511bf7fd50bSSimon Glassallowing the more complex cases to be supported. For example, for most 512bf7fd50bSSimon Glassimages we don't much care exactly where each binary ends up, so we should 513bf7fd50bSSimon Glassnot have to specify that unnecessarily. 514bf7fd50bSSimon Glass 515bf7fd50bSSimon GlassNew entry types should aim to provide simple usage where possible. If new 516bf7fd50bSSimon Glasscore features are needed, they can be added in the Entry base class. 517bf7fd50bSSimon Glass 518bf7fd50bSSimon Glass 519bf7fd50bSSimon GlassTo do 520bf7fd50bSSimon Glass----- 521bf7fd50bSSimon Glass 522bf7fd50bSSimon GlassSome ideas: 523bf7fd50bSSimon Glass- Fill out the device tree to include the final position and size of each 524bf7fd50bSSimon Glass entry (since the input file may not always specify these) 525bf7fd50bSSimon Glass- Use of-platdata to make the information available to code that is unable 526bf7fd50bSSimon Glass to use device tree (such as a very small SPL image) 527bf7fd50bSSimon Glass- Write an image map to a text file 528bf7fd50bSSimon Glass- Allow easy building of images by specifying just the board name 529bf7fd50bSSimon Glass- Produce a full Python binding for libfdt (for upstream) 530bf7fd50bSSimon Glass- Add an option to decode an image into the constituent binaries 531bf7fd50bSSimon Glass- Suppoort hierarchical images (packing of binaries into another binary 532bf7fd50bSSimon Glass which is then placed in the image) 533bf7fd50bSSimon Glass- Support building an image for a board (-b) more completely, with a 534bf7fd50bSSimon Glass configurable build directory 535bf7fd50bSSimon Glass- Consider making binman work with buildman, although if it is used in the 536bf7fd50bSSimon Glass Makefile, this will be automatic 537bf7fd50bSSimon Glass- Implement align-end 538bf7fd50bSSimon Glass 539bf7fd50bSSimon Glass-- 540bf7fd50bSSimon GlassSimon Glass <sjg@chromium.org> 541bf7fd50bSSimon Glass7/7/2016 542