1bf7fd50bSSimon Glass# SPDX-License-Identifier: GPL-2.0+ 2*83d290c5STom 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 { 241bf7fd50bSSimon Glass pos = <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 260bf7fd50bSSimon Glassspecify the start position of an entry using the 'pos' 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 268bf7fd50bSSimon Glasspos: 269bf7fd50bSSimon Glass This sets the position of an entry within the image. The first byte 270bf7fd50bSSimon Glass of the image is normally at position 0. If 'pos' is not provided, 271bf7fd50bSSimon Glass binman sets it to the end of the previous region, or the start of 272bf7fd50bSSimon Glass the image's entry area (normally 0) if there is no previous region. 273bf7fd50bSSimon Glass 274bf7fd50bSSimon Glassalign: 275bf7fd50bSSimon Glass This sets the alignment of the entry. The entry position is adjusted 276bf7fd50bSSimon Glass so that the entry starts on an aligned boundary within the image. For 277bf7fd50bSSimon Glass example 'align = <16>' means that the entry will start on a 16-byte 278bf7fd50bSSimon Glass boundary. Alignment shold be a power of 2. If 'align' is not 279bf7fd50bSSimon Glass provided, no alignment is performed. 280bf7fd50bSSimon Glass 281bf7fd50bSSimon Glasssize: 282bf7fd50bSSimon Glass This sets the size of the entry. The contents will be padded out to 283bf7fd50bSSimon Glass this size. If this is not provided, it will be set to the size of the 284bf7fd50bSSimon Glass contents. 285bf7fd50bSSimon Glass 286bf7fd50bSSimon Glasspad-before: 287bf7fd50bSSimon Glass Padding before the contents of the entry. Normally this is 0, meaning 288bf7fd50bSSimon Glass that the contents start at the beginning of the entry. This can be 289bf7fd50bSSimon Glass offset the entry contents a little. Defaults to 0. 290bf7fd50bSSimon Glass 291bf7fd50bSSimon Glasspad-after: 292bf7fd50bSSimon Glass Padding after the contents of the entry. Normally this is 0, meaning 293bf7fd50bSSimon Glass that the entry ends at the last byte of content (unless adjusted by 294bf7fd50bSSimon Glass other properties). This allows room to be created in the image for 295bf7fd50bSSimon Glass this entry to expand later. Defaults to 0. 296bf7fd50bSSimon Glass 297bf7fd50bSSimon Glassalign-size: 298bf7fd50bSSimon Glass This sets the alignment of the entry size. For example, to ensure 299bf7fd50bSSimon Glass that the size of an entry is a multiple of 64 bytes, set this to 64. 300bf7fd50bSSimon Glass If 'align-size' is not provided, no alignment is performed. 301bf7fd50bSSimon Glass 302bf7fd50bSSimon Glassalign-end: 303bf7fd50bSSimon Glass This sets the alignment of the end of an entry. Some entries require 304bf7fd50bSSimon Glass that they end on an alignment boundary, regardless of where they 305bf7fd50bSSimon Glass start. If 'align-end' is not provided, no alignment is performed. 306bf7fd50bSSimon Glass 307bf7fd50bSSimon Glass Note: This is not yet implemented in binman. 308bf7fd50bSSimon Glass 309bf7fd50bSSimon Glassfilename: 310bf7fd50bSSimon Glass For 'blob' types this provides the filename containing the binary to 311bf7fd50bSSimon Glass put into the entry. If binman knows about the entry type (like 312bf7fd50bSSimon Glass u-boot-bin), then there is no need to specify this. 313bf7fd50bSSimon Glass 314bf7fd50bSSimon Glasstype: 315bf7fd50bSSimon Glass Sets the type of an entry. This defaults to the entry name, but it is 316bf7fd50bSSimon Glass possible to use any name, and then add (for example) 'type = "u-boot"' 317bf7fd50bSSimon Glass to specify the type. 318bf7fd50bSSimon Glass 319bf7fd50bSSimon Glass 320bf7fd50bSSimon GlassThe attributes supported for images are described below. Several are similar 321bf7fd50bSSimon Glassto those for entries. 322bf7fd50bSSimon Glass 323bf7fd50bSSimon Glasssize: 324bf7fd50bSSimon Glass Sets the image size in bytes, for example 'size = <0x100000>' for a 325bf7fd50bSSimon Glass 1MB image. 326bf7fd50bSSimon Glass 327bf7fd50bSSimon Glassalign-size: 328bf7fd50bSSimon Glass This sets the alignment of the image size. For example, to ensure 329bf7fd50bSSimon Glass that the image ends on a 512-byte boundary, use 'align-size = <512>'. 330bf7fd50bSSimon Glass If 'align-size' is not provided, no alignment is performed. 331bf7fd50bSSimon Glass 332bf7fd50bSSimon Glasspad-before: 333bf7fd50bSSimon Glass This sets the padding before the image entries. The first entry will 334bf7fd50bSSimon Glass be positionad after the padding. This defaults to 0. 335bf7fd50bSSimon Glass 336bf7fd50bSSimon Glasspad-after: 337bf7fd50bSSimon Glass This sets the padding after the image entries. The padding will be 338bf7fd50bSSimon Glass placed after the last entry. This defaults to 0. 339bf7fd50bSSimon Glass 340bf7fd50bSSimon Glasspad-byte: 341bf7fd50bSSimon Glass This specifies the pad byte to use when padding in the image. It 342bf7fd50bSSimon Glass defaults to 0. To use 0xff, you would add 'pad-byte = <0xff>'. 343bf7fd50bSSimon Glass 344bf7fd50bSSimon Glassfilename: 345bf7fd50bSSimon Glass This specifies the image filename. It defaults to 'image.bin'. 346bf7fd50bSSimon Glass 347bf7fd50bSSimon Glasssort-by-pos: 348bf7fd50bSSimon Glass This causes binman to reorder the entries as needed to make sure they 349bf7fd50bSSimon Glass are in increasing positional order. This can be used when your entry 350bf7fd50bSSimon Glass order may not match the positional order. A common situation is where 351bf7fd50bSSimon Glass the 'pos' properties are set by CONFIG options, so their ordering is 352bf7fd50bSSimon Glass not known a priori. 353bf7fd50bSSimon Glass 354bf7fd50bSSimon Glass This is a boolean property so needs no value. To enable it, add a 355bf7fd50bSSimon Glass line 'sort-by-pos;' to your description. 356bf7fd50bSSimon Glass 357bf7fd50bSSimon Glassmultiple-images: 358bf7fd50bSSimon Glass Normally only a single image is generated. To create more than one 359bf7fd50bSSimon Glass image, put this property in the binman node. For example, this will 360bf7fd50bSSimon Glass create image1.bin containing u-boot.bin, and image2.bin containing 361bf7fd50bSSimon Glass both spl/u-boot-spl.bin and u-boot.bin: 362bf7fd50bSSimon Glass 363bf7fd50bSSimon Glass binman { 364bf7fd50bSSimon Glass multiple-images; 365bf7fd50bSSimon Glass image1 { 366bf7fd50bSSimon Glass u-boot { 367bf7fd50bSSimon Glass }; 368bf7fd50bSSimon Glass }; 369bf7fd50bSSimon Glass 370bf7fd50bSSimon Glass image2 { 371bf7fd50bSSimon Glass spl { 372bf7fd50bSSimon Glass }; 373bf7fd50bSSimon Glass u-boot { 374bf7fd50bSSimon Glass }; 375bf7fd50bSSimon Glass }; 376bf7fd50bSSimon Glass }; 377bf7fd50bSSimon Glass 378bf7fd50bSSimon Glassend-at-4gb: 379bf7fd50bSSimon Glass For x86 machines the ROM positions start just before 4GB and extend 380bf7fd50bSSimon Glass up so that the image finished at the 4GB boundary. This boolean 381bf7fd50bSSimon Glass option can be enabled to support this. The image size must be 382bf7fd50bSSimon Glass provided so that binman knows when the image should start. For an 383bf7fd50bSSimon Glass 8MB ROM, the position of the first entry would be 0xfff80000 with 384bf7fd50bSSimon Glass this option, instead of 0 without this option. 385bf7fd50bSSimon Glass 386bf7fd50bSSimon Glass 387bf7fd50bSSimon GlassExamples of the above options can be found in the tests. See the 388bf7fd50bSSimon Glasstools/binman/test directory. 389bf7fd50bSSimon Glass 390bf7fd50bSSimon Glass 391e0ff8551SSimon GlassSpecial properties 392e0ff8551SSimon Glass------------------ 393e0ff8551SSimon Glass 394e0ff8551SSimon GlassSome entries support special properties, documented here: 395e0ff8551SSimon Glass 396e0ff8551SSimon Glassu-boot-with-ucode-ptr: 397e0ff8551SSimon Glass optional-ucode: boolean property to make microcode optional. If the 398e0ff8551SSimon Glass u-boot.bin image does not include microcode, no error will 399e0ff8551SSimon Glass be generated. 400e0ff8551SSimon Glass 401e0ff8551SSimon Glass 402bf7fd50bSSimon GlassOrder of image creation 403bf7fd50bSSimon Glass----------------------- 404bf7fd50bSSimon Glass 405bf7fd50bSSimon GlassImage creation proceeds in the following order, for each entry in the image. 406bf7fd50bSSimon Glass 407bf7fd50bSSimon Glass1. GetEntryContents() - the contents of each entry are obtained, normally by 408bf7fd50bSSimon Glassreading from a file. This calls the Entry.ObtainContents() to read the 409bf7fd50bSSimon Glasscontents. The default version of Entry.ObtainContents() calls 410bf7fd50bSSimon GlassEntry.GetDefaultFilename() and then reads that file. So a common mechanism 411bf7fd50bSSimon Glassto select a file to read is to override that function in the subclass. The 412bf7fd50bSSimon Glassfunctions must return True when they have read the contents. Binman will 413bf7fd50bSSimon Glassretry calling the functions a few times if False is returned, allowing 414bf7fd50bSSimon Glassdependencies between the contents of different entries. 415bf7fd50bSSimon Glass 416bf7fd50bSSimon Glass2. GetEntryPositions() - calls Entry.GetPositions() for each entry. This can 417bf7fd50bSSimon Glassreturn a dict containing entries that need updating. The key should be the 418bf7fd50bSSimon Glassentry name and the value is a tuple (pos, size). This allows an entry to 419bf7fd50bSSimon Glassprovide the position and size for other entries. The default implementation 420bf7fd50bSSimon Glassof GetEntryPositions() returns {}. 421bf7fd50bSSimon Glass 422bf7fd50bSSimon Glass3. PackEntries() - calls Entry.Pack() which figures out the position and 423bf7fd50bSSimon Glasssize of an entry. The 'current' image position is passed in, and the function 424bf7fd50bSSimon Glassreturns the position immediately after the entry being packed. The default 425bf7fd50bSSimon Glassimplementation of Pack() is usually sufficient. 426bf7fd50bSSimon Glass 427bf7fd50bSSimon Glass4. CheckSize() - checks that the contents of all the entries fits within 428bf7fd50bSSimon Glassthe image size. If the image does not have a defined size, the size is set 429bf7fd50bSSimon Glasslarge enough to hold all the entries. 430bf7fd50bSSimon Glass 431bf7fd50bSSimon Glass5. CheckEntries() - checks that the entries do not overlap, nor extend 432bf7fd50bSSimon Glassoutside the image. 433bf7fd50bSSimon Glass 434bf7fd50bSSimon Glass6. ProcessEntryContents() - this calls Entry.ProcessContents() on each entry. 435bf7fd50bSSimon GlassThe default implementatoin does nothing. This can be overriden to adjust the 436bf7fd50bSSimon Glasscontents of an entry in some way. For example, it would be possible to create 437bf7fd50bSSimon Glassan entry containing a hash of the contents of some other entries. At this 438bf7fd50bSSimon Glassstage the position and size of entries should not be adjusted. 439bf7fd50bSSimon Glass 44039c1502cSSimon Glass6. WriteEntryInfo() 44139c1502cSSimon Glass 442bf7fd50bSSimon Glass7. BuildImage() - builds the image and writes it to a file. This is the final 443bf7fd50bSSimon Glassstep. 444bf7fd50bSSimon Glass 445bf7fd50bSSimon Glass 4466d427c6bSSimon GlassAutomatic .dtsi inclusion 4476d427c6bSSimon Glass------------------------- 4486d427c6bSSimon Glass 4496d427c6bSSimon GlassIt is sometimes inconvenient to add a 'binman' node to the .dts file for each 4506d427c6bSSimon Glassboard. This can be done by using #include to bring in a common file. Another 4516d427c6bSSimon Glassapproach supported by the U-Boot build system is to automatically include 4526d427c6bSSimon Glassa common header. You can then put the binman node (and anything else that is 4536d427c6bSSimon Glassspecific to U-Boot, such as u-boot,dm-pre-reloc properies) in that header 4546d427c6bSSimon Glassfile. 4556d427c6bSSimon Glass 4566d427c6bSSimon GlassBinman will search for the following files in arch/<arch>/dts: 4576d427c6bSSimon Glass 4586d427c6bSSimon Glass <dts>-u-boot.dtsi where <dts> is the base name of the .dts file 4596d427c6bSSimon Glass <CONFIG_SYS_SOC>-u-boot.dtsi 4606d427c6bSSimon Glass <CONFIG_SYS_CPU>-u-boot.dtsi 4616d427c6bSSimon Glass <CONFIG_SYS_VENDOR>-u-boot.dtsi 4626d427c6bSSimon Glass u-boot.dtsi 4636d427c6bSSimon Glass 4646d427c6bSSimon GlassU-Boot will only use the first one that it finds. If you need to include a 4656d427c6bSSimon Glassmore general file you can do that from the more specific file using #include. 4666d427c6bSSimon GlassIf you are having trouble figuring out what is going on, you can uncomment 4676d427c6bSSimon Glassthe 'warning' line in scripts/Makefile.lib to see what it has found: 4686d427c6bSSimon Glass 4696d427c6bSSimon Glass # Uncomment for debugging 470511fd0b2SSimon Glass # This shows all the files that were considered and the one that we chose. 471511fd0b2SSimon Glass # u_boot_dtsi_options_debug = $(u_boot_dtsi_options_raw) 4726d427c6bSSimon Glass 4736d427c6bSSimon Glass 47439c1502cSSimon GlassAccess to binman entry positions at run time 47539c1502cSSimon Glass-------------------------------------------- 47639c1502cSSimon Glass 47739c1502cSSimon GlassBinman assembles images and determines where each entry is placed in the image. 47839c1502cSSimon GlassThis information may be useful to U-Boot at run time. For example, in SPL it 47939c1502cSSimon Glassis useful to be able to find the location of U-Boot so that it can be executed 48039c1502cSSimon Glasswhen SPL is finished. 48139c1502cSSimon Glass 48239c1502cSSimon GlassBinman allows you to declare symbols in the SPL image which are filled in 48339c1502cSSimon Glasswith their correct values during the build. For example: 48439c1502cSSimon Glass 48539c1502cSSimon Glass binman_sym_declare(ulong, u_boot_any, pos); 48639c1502cSSimon Glass 48739c1502cSSimon Glassdeclares a ulong value which will be assigned to the position of any U-Boot 48839c1502cSSimon Glassimage (u-boot.bin, u-boot.img, u-boot-nodtb.bin) that is present in the image. 48939c1502cSSimon GlassYou can access this value with something like: 49039c1502cSSimon Glass 49139c1502cSSimon Glass ulong u_boot_pos = binman_sym(ulong, u_boot_any, pos); 49239c1502cSSimon Glass 49339c1502cSSimon GlassThus u_boot_pos will be set to the position of U-Boot in memory, assuming that 49439c1502cSSimon Glassthe whole image has been loaded, or is available in flash. You can then jump to 49539c1502cSSimon Glassthat address to start U-Boot. 49639c1502cSSimon Glass 49739c1502cSSimon GlassAt present this feature is only supported in SPL. In principle it is possible 49839c1502cSSimon Glassto fill in such symbols in U-Boot proper, as well. 49939c1502cSSimon Glass 50039c1502cSSimon Glass 5016d427c6bSSimon GlassCode coverage 5026d427c6bSSimon Glass------------- 5036d427c6bSSimon Glass 5046d427c6bSSimon GlassBinman is a critical tool and is designed to be very testable. Entry 5056d427c6bSSimon Glassimplementations target 100% test coverage. Run 'binman -T' to check this. 5066d427c6bSSimon Glass 5076d427c6bSSimon GlassTo enable Python test coverage on Debian-type distributions (e.g. Ubuntu): 5086d427c6bSSimon Glass 5096d427c6bSSimon Glass $ sudo apt-get install python-pip python-pytest 5106d427c6bSSimon Glass $ sudo pip install coverage 5116d427c6bSSimon Glass 5126d427c6bSSimon Glass 513bf7fd50bSSimon GlassAdvanced Features / Technical docs 514bf7fd50bSSimon Glass---------------------------------- 515bf7fd50bSSimon Glass 516bf7fd50bSSimon GlassThe behaviour of entries is defined by the Entry class. All other entries are 517bf7fd50bSSimon Glassa subclass of this. An important subclass is Entry_blob which takes binary 518bf7fd50bSSimon Glassdata from a file and places it in the entry. In fact most entry types are 519bf7fd50bSSimon Glasssubclasses of Entry_blob. 520bf7fd50bSSimon Glass 521bf7fd50bSSimon GlassEach entry type is a separate file in the tools/binman/etype directory. Each 522bf7fd50bSSimon Glassfile contains a class called Entry_<type> where <type> is the entry type. 523bf7fd50bSSimon GlassNew entry types can be supported by adding new files in that directory. 524bf7fd50bSSimon GlassThese will automatically be detected by binman when needed. 525bf7fd50bSSimon Glass 526bf7fd50bSSimon GlassEntry properties are documented in entry.py. The entry subclasses are free 527bf7fd50bSSimon Glassto change the values of properties to support special behaviour. For example, 528bf7fd50bSSimon Glasswhen Entry_blob loads a file, it sets content_size to the size of the file. 529bf7fd50bSSimon GlassEntry classes can adjust other entries. For example, an entry that knows 530bf7fd50bSSimon Glasswhere other entries should be positioned can set up those entries' positions 531bf7fd50bSSimon Glassso they don't need to be set in the binman decription. It can also adjust 532bf7fd50bSSimon Glassentry contents. 533bf7fd50bSSimon Glass 534bf7fd50bSSimon GlassMost of the time such essoteric behaviour is not needed, but it can be 535bf7fd50bSSimon Glassessential for complex images. 536bf7fd50bSSimon Glass 5373ed0de31SSimon GlassIf you need to specify a particular device-tree compiler to use, you can define 5383ed0de31SSimon Glassthe DTC environment variable. This can be useful when the system dtc is too 5393ed0de31SSimon Glassold. 5403ed0de31SSimon Glass 541bf7fd50bSSimon Glass 542bf7fd50bSSimon GlassHistory / Credits 543bf7fd50bSSimon Glass----------------- 544bf7fd50bSSimon Glass 545bf7fd50bSSimon GlassBinman takes a lot of inspiration from a Chrome OS tool called 546bf7fd50bSSimon Glass'cros_bundle_firmware', which I wrote some years ago. That tool was based on 547bf7fd50bSSimon Glassa reasonably simple and sound design but has expanded greatly over the 548bf7fd50bSSimon Glassyears. In particular its handling of x86 images is convoluted. 549bf7fd50bSSimon Glass 550bf7fd50bSSimon GlassQuite a few lessons have been learned which are hopefully be applied here. 551bf7fd50bSSimon Glass 552bf7fd50bSSimon Glass 553bf7fd50bSSimon GlassDesign notes 554bf7fd50bSSimon Glass------------ 555bf7fd50bSSimon Glass 556bf7fd50bSSimon GlassOn the face of it, a tool to create firmware images should be fairly simple: 557bf7fd50bSSimon Glassjust find all the input binaries and place them at the right place in the 558bf7fd50bSSimon Glassimage. The difficulty comes from the wide variety of input types (simple 559bf7fd50bSSimon Glassflat binaries containing code, packaged data with various headers), packing 560bf7fd50bSSimon Glassrequirments (alignment, spacing, device boundaries) and other required 561bf7fd50bSSimon Glassfeatures such as hierarchical images. 562bf7fd50bSSimon Glass 563bf7fd50bSSimon GlassThe design challenge is to make it easy to create simple images, while 564bf7fd50bSSimon Glassallowing the more complex cases to be supported. For example, for most 565bf7fd50bSSimon Glassimages we don't much care exactly where each binary ends up, so we should 566bf7fd50bSSimon Glassnot have to specify that unnecessarily. 567bf7fd50bSSimon Glass 568bf7fd50bSSimon GlassNew entry types should aim to provide simple usage where possible. If new 569bf7fd50bSSimon Glasscore features are needed, they can be added in the Entry base class. 570bf7fd50bSSimon Glass 571bf7fd50bSSimon Glass 572bf7fd50bSSimon GlassTo do 573bf7fd50bSSimon Glass----- 574bf7fd50bSSimon Glass 575bf7fd50bSSimon GlassSome ideas: 576bf7fd50bSSimon Glass- Fill out the device tree to include the final position and size of each 57739c1502cSSimon Glass entry (since the input file may not always specify these). See also 57839c1502cSSimon Glass 'Access to binman entry positions at run time' above 579bf7fd50bSSimon Glass- Use of-platdata to make the information available to code that is unable 580bf7fd50bSSimon Glass to use device tree (such as a very small SPL image) 581bf7fd50bSSimon Glass- Write an image map to a text file 582bf7fd50bSSimon Glass- Allow easy building of images by specifying just the board name 583bf7fd50bSSimon Glass- Produce a full Python binding for libfdt (for upstream) 584bf7fd50bSSimon Glass- Add an option to decode an image into the constituent binaries 585bf7fd50bSSimon Glass- Suppoort hierarchical images (packing of binaries into another binary 586bf7fd50bSSimon Glass which is then placed in the image) 587bf7fd50bSSimon Glass- Support building an image for a board (-b) more completely, with a 588bf7fd50bSSimon Glass configurable build directory 589bf7fd50bSSimon Glass- Consider making binman work with buildman, although if it is used in the 590bf7fd50bSSimon Glass Makefile, this will be automatic 591bf7fd50bSSimon Glass- Implement align-end 592bf7fd50bSSimon Glass 593bf7fd50bSSimon Glass-- 594bf7fd50bSSimon GlassSimon Glass <sjg@chromium.org> 595bf7fd50bSSimon Glass7/7/2016 596