162306a36Sopenharmony_ci========================
262306a36Sopenharmony_ciThe PowerPC boot wrapper
362306a36Sopenharmony_ci========================
462306a36Sopenharmony_ci
562306a36Sopenharmony_ciCopyright (C) Secret Lab Technologies Ltd.
662306a36Sopenharmony_ci
762306a36Sopenharmony_ciPowerPC image targets compresses and wraps the kernel image (vmlinux) with
862306a36Sopenharmony_cia boot wrapper to make it usable by the system firmware.  There is no
962306a36Sopenharmony_cistandard PowerPC firmware interface, so the boot wrapper is designed to
1062306a36Sopenharmony_cibe adaptable for each kind of image that needs to be built.
1162306a36Sopenharmony_ci
1262306a36Sopenharmony_ciThe boot wrapper can be found in the arch/powerpc/boot/ directory.  The
1362306a36Sopenharmony_ciMakefile in that directory has targets for all the available image types.
1462306a36Sopenharmony_ciThe different image types are used to support all of the various firmware
1562306a36Sopenharmony_ciinterfaces found on PowerPC platforms.  OpenFirmware is the most commonly
1662306a36Sopenharmony_ciused firmware type on general purpose PowerPC systems from Apple, IBM and
1762306a36Sopenharmony_ciothers.  U-Boot is typically found on embedded PowerPC hardware, but there
1862306a36Sopenharmony_ciare a handful of other firmware implementations which are also popular.  Each
1962306a36Sopenharmony_cifirmware interface requires a different image format.
2062306a36Sopenharmony_ci
2162306a36Sopenharmony_ciThe boot wrapper is built from the makefile in arch/powerpc/boot/Makefile and
2262306a36Sopenharmony_ciit uses the wrapper script (arch/powerpc/boot/wrapper) to generate target
2362306a36Sopenharmony_ciimage.  The details of the build system is discussed in the next section.
2462306a36Sopenharmony_ciCurrently, the following image format targets exist:
2562306a36Sopenharmony_ci
2662306a36Sopenharmony_ci   ==================== ========================================================
2762306a36Sopenharmony_ci   cuImage.%:		Backwards compatible uImage for older version of
2862306a36Sopenharmony_ci			U-Boot (for versions that don't understand the device
2962306a36Sopenharmony_ci			tree).  This image embeds a device tree blob inside
3062306a36Sopenharmony_ci			the image.  The boot wrapper, kernel and device tree
3162306a36Sopenharmony_ci			are all embedded inside the U-Boot uImage file format
3262306a36Sopenharmony_ci			with boot wrapper code that extracts data from the old
3362306a36Sopenharmony_ci			bd_info structure and loads the data into the device
3462306a36Sopenharmony_ci			tree before jumping into the kernel.
3562306a36Sopenharmony_ci
3662306a36Sopenharmony_ci			Because of the series of #ifdefs found in the
3762306a36Sopenharmony_ci			bd_info structure used in the old U-Boot interfaces,
3862306a36Sopenharmony_ci			cuImages are platform specific.  Each specific
3962306a36Sopenharmony_ci			U-Boot platform has a different platform init file
4062306a36Sopenharmony_ci			which populates the embedded device tree with data
4162306a36Sopenharmony_ci			from the platform specific bd_info file.  The platform
4262306a36Sopenharmony_ci			specific cuImage platform init code can be found in
4362306a36Sopenharmony_ci			`arch/powerpc/boot/cuboot.*.c`. Selection of the correct
4462306a36Sopenharmony_ci			cuImage init code for a specific board can be found in
4562306a36Sopenharmony_ci			the wrapper structure.
4662306a36Sopenharmony_ci
4762306a36Sopenharmony_ci   dtbImage.%:		Similar to zImage, except device tree blob is embedded
4862306a36Sopenharmony_ci			inside the image instead of provided by firmware.  The
4962306a36Sopenharmony_ci			output image file can be either an elf file or a flat
5062306a36Sopenharmony_ci			binary depending on the platform.
5162306a36Sopenharmony_ci
5262306a36Sopenharmony_ci			dtbImages are used on systems which do not have an
5362306a36Sopenharmony_ci			interface for passing a device tree directly.
5462306a36Sopenharmony_ci			dtbImages are similar to simpleImages except that
5562306a36Sopenharmony_ci			dtbImages have platform specific code for extracting
5662306a36Sopenharmony_ci			data from the board firmware, but simpleImages do not
5762306a36Sopenharmony_ci			talk to the firmware at all.
5862306a36Sopenharmony_ci
5962306a36Sopenharmony_ci			PlayStation 3 support uses dtbImage.  So do Embedded
6062306a36Sopenharmony_ci			Planet boards using the PlanetCore firmware.  Board
6162306a36Sopenharmony_ci			specific initialization code is typically found in a
6262306a36Sopenharmony_ci			file named arch/powerpc/boot/<platform>.c; but this
6362306a36Sopenharmony_ci			can be overridden by the wrapper script.
6462306a36Sopenharmony_ci
6562306a36Sopenharmony_ci   simpleImage.%:	Firmware independent compressed image that does not
6662306a36Sopenharmony_ci			depend on any particular firmware interface and embeds
6762306a36Sopenharmony_ci			a device tree blob.  This image is a flat binary that
6862306a36Sopenharmony_ci			can be loaded to any location in RAM and jumped to.
6962306a36Sopenharmony_ci			Firmware cannot pass any configuration data to the
7062306a36Sopenharmony_ci			kernel with this image type and it depends entirely on
7162306a36Sopenharmony_ci			the embedded device tree for all information.
7262306a36Sopenharmony_ci
7362306a36Sopenharmony_ci   treeImage.%;		Image format for used with OpenBIOS firmware found
7462306a36Sopenharmony_ci			on some ppc4xx hardware.  This image embeds a device
7562306a36Sopenharmony_ci			tree blob inside the image.
7662306a36Sopenharmony_ci
7762306a36Sopenharmony_ci   uImage:		Native image format used by U-Boot.  The uImage target
7862306a36Sopenharmony_ci			does not add any boot code.  It just wraps a compressed
7962306a36Sopenharmony_ci			vmlinux in the uImage data structure.  This image
8062306a36Sopenharmony_ci			requires a version of U-Boot that is able to pass
8162306a36Sopenharmony_ci			a device tree to the kernel at boot.  If using an older
8262306a36Sopenharmony_ci			version of U-Boot, then you need to use a cuImage
8362306a36Sopenharmony_ci			instead.
8462306a36Sopenharmony_ci
8562306a36Sopenharmony_ci   zImage.%:		Image format which does not embed a device tree.
8662306a36Sopenharmony_ci			Used by OpenFirmware and other firmware interfaces
8762306a36Sopenharmony_ci			which are able to supply a device tree.  This image
8862306a36Sopenharmony_ci			expects firmware to provide the device tree at boot.
8962306a36Sopenharmony_ci			Typically, if you have general purpose PowerPC
9062306a36Sopenharmony_ci			hardware then you want this image format.
9162306a36Sopenharmony_ci   ==================== ========================================================
9262306a36Sopenharmony_ci
9362306a36Sopenharmony_ciImage types which embed a device tree blob (simpleImage, dtbImage, treeImage,
9462306a36Sopenharmony_ciand cuImage) all generate the device tree blob from a file in the
9562306a36Sopenharmony_ciarch/powerpc/boot/dts/ directory.  The Makefile selects the correct device
9662306a36Sopenharmony_citree source based on the name of the target.  Therefore, if the kernel is
9762306a36Sopenharmony_cibuilt with 'make treeImage.walnut', then the build system will use
9862306a36Sopenharmony_ciarch/powerpc/boot/dts/walnut.dts to build treeImage.walnut.
9962306a36Sopenharmony_ci
10062306a36Sopenharmony_ciTwo special targets called 'zImage' and 'zImage.initrd' also exist.  These
10162306a36Sopenharmony_citargets build all the default images as selected by the kernel configuration.
10262306a36Sopenharmony_ciDefault images are selected by the boot wrapper Makefile
10362306a36Sopenharmony_ci(arch/powerpc/boot/Makefile) by adding targets to the $image-y variable.  Look
10462306a36Sopenharmony_ciat the Makefile to see which default image targets are available.
10562306a36Sopenharmony_ci
10662306a36Sopenharmony_ciHow it is built
10762306a36Sopenharmony_ci---------------
10862306a36Sopenharmony_ciarch/powerpc is designed to support multiplatform kernels, which means
10962306a36Sopenharmony_cithat a single vmlinux image can be booted on many different target boards.
11062306a36Sopenharmony_ciIt also means that the boot wrapper must be able to wrap for many kinds of
11162306a36Sopenharmony_ciimages on a single build.  The design decision was made to not use any
11262306a36Sopenharmony_ciconditional compilation code (#ifdef, etc) in the boot wrapper source code.
11362306a36Sopenharmony_ciAll of the boot wrapper pieces are buildable at any time regardless of the
11462306a36Sopenharmony_cikernel configuration.  Building all the wrapper bits on every kernel build
11562306a36Sopenharmony_cialso ensures that obscure parts of the wrapper are at the very least compile
11662306a36Sopenharmony_citested in a large variety of environments.
11762306a36Sopenharmony_ci
11862306a36Sopenharmony_ciThe wrapper is adapted for different image types at link time by linking in
11962306a36Sopenharmony_cijust the wrapper bits that are appropriate for the image type.  The 'wrapper
12062306a36Sopenharmony_ciscript' (found in arch/powerpc/boot/wrapper) is called by the Makefile and
12162306a36Sopenharmony_ciis responsible for selecting the correct wrapper bits for the image type.
12262306a36Sopenharmony_ciThe arguments are well documented in the script's comment block, so they
12362306a36Sopenharmony_ciare not repeated here.  However, it is worth mentioning that the script
12462306a36Sopenharmony_ciuses the -p (platform) argument as the main method of deciding which wrapper
12562306a36Sopenharmony_cibits to compile in.  Look for the large 'case "$platform" in' block in the
12662306a36Sopenharmony_cimiddle of the script.  This is also the place where platform specific fixups
12762306a36Sopenharmony_cican be selected by changing the link order.
12862306a36Sopenharmony_ci
12962306a36Sopenharmony_ciIn particular, care should be taken when working with cuImages.  cuImage
13062306a36Sopenharmony_ciwrapper bits are very board specific and care should be taken to make sure
13162306a36Sopenharmony_cithe target you are trying to build is supported by the wrapper bits.
132