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