FIT images and device tree on x86
v2 cover FIT images and device tree on x86
This little series adds support for booting FITs on x86. A FIT is a single file that can contain a kernel, device tree and ramdisk.
x86 kernels require a setup.bin file to boot. Rather than try to pack this into the image in a clever way, this series just adds it as another image in the FIT. At present compression is not supported for the setup binary.
The kernel image can be compressed using FIT's normal compression options, such as bzip2 and lzo. U-Boot will decompress it as part of the 'bootm' command.
More work is needed to make this implementation also support a zImage (which contains a setup.bin and a compressed kernel in a single image), and to pass the correct device tree binary to the kernel.
Changes in v2:
- Fix checkpatch warning about a string spanning two lines
- Rebase to master
Simon Glass (4):
x86: Enable LMB and RAMDISK_HIGH by default
x86: Rewrite bootm.c to make it similar to ARM
x86: Allow cmdline setup in setup_zimage() to be optional
x86: Support loading kernel setup from a FIT
arch/x86/include/asm/bootm.h | 24 ++++++ arch/x86/include/asm/config.h | 2 + arch/x86/lib/bootm.c | 153 ++++++++++++++++++++++++++-------- arch/x86/lib/zimage.c | 41 ++++----- common/cmd_bootm.c | 23 ++++- common/image-fit.c | 22 +++++ common/image.c | 11 +++ doc/uImage.FIT/kernel.its | 50 +++++++++++ doc/uImage.FIT/source_file_format.txt | 23 ++--- include/bootstage.h | 3 + include/image.h | 13 +++ 11 files changed, 291 insertions(+), 74 deletions(-) create mode 100644 arch/x86/include/asm/bootm.h
Signature · 1 line
1.8.4.1
PATCH v2 1/4 x86: Enable LMB and RAMDISK_HIGH by default
These options are used by the image code. To allow us to use the generic code more easily, define these for x86.
---
Changes in v2: None
arch/x86/include/asm/config.h | 2 ++ 1 file changed, 2 insertions(+)
arch/x86/include/asm/config.h +2 -0
@@ -8,4 +8,6 @@#define _ASM_CONFIG_H_#define CONFIG_SYS_GENERIC_BOARD +#define CONFIG_LMB +#define CONFIG_SYS_BOOT_RAMDISK_HIGH #endif
Signature · 1 line
1.8.4.1
PATCH v2 2/4 x86: Rewrite bootm.c to make it similar to ARM
In reply to Simon GlassThe x86 bootm code is quite special, and geared to zimage. Adjust it to support device tree and make it more like the ARM code, with separate bootm stages and functions for each stage.
Create a function announce_and_cleanup() to handle printing the "Starting kernel ..." message and put it in bootm so it is in one place and can be used by any loading code. Also move the board_final_cleanup() function into bootm.
---
Changes in v2:
- Fix checkpatch warning about a string spanning two lines
arch/x86/include/asm/bootm.h | 24 +++++++ arch/x86/lib/bootm.c | 153 +++++++++++++++++++++++++++++++++---------- arch/x86/lib/zimage.c | 20 +----- 3 files changed, 144 insertions(+), 53 deletions(-) create mode 100644 arch/x86/include/asm/bootm.h
arch/x86/include/asm/bootm.h new file +24 -0
@@ -0,0 +1,24 @@ +/* +* Copyright (c) 2013, Google Inc. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +*/ +#ifndef ARM_BOOTM_H +#define ARM_BOOTM_H + +void bootm_announce_and_cleanup (void ); + +#endif
arch/x86/lib/bootm.c +118 -35
198 lines not on this page · raw message
arch/x86/lib/zimage.c +2 -18
@@ -18,6 +18,7 @@#include <asm/ptrace.h> #include <asm/zimage.h> #include <asm/byteorder.h> +#include <asm/bootm.h> #include <asm/bootparam.h> #ifdef CONFIG_SYS_COREBOOT #include <asm/arch/timestamp.h>
@@ -257,26 +258,9 @@ int setup_zimage(struct boot_params *setup_base, char *cmd_line, int auto_boot,return 0 ; } -/* -* Implement a weak default function for boards that optionally -* need to clean up the system before jumping to the kernel. -*/ -__weak void board_final_cleanup (void ) -{ -} -void boot_zimage (void *setup_base,void *load_address) { -debug ("## Transferring control to Linux (at address %08x) ...\n" , - (u32 )setup_base); - -bootstage_mark_name (BOOTSTAGE_ID_BOOTM_HANDOFF ,"start_kernel" ); -#ifdef CONFIG_BOOTSTAGE_REPORT -bootstage_report (); -#endif -board_final_cleanup (); - -printf ("\nStarting kernel ...\n\n" ); +bootm_announce_and_cleanup ();#ifdef CONFIG_SYS_COREBOOT timestamp_add_now (TS_U_BOOT_START_KERNEL );
Signature · 1 line
1.8.4.1
PATCH v2 3/4 x86: Allow cmdline setup in setup_zimage() to be optional
In reply to Simon GlassIf we are passing this using the device tree then we may not want to set this up here. TBD.
---
Changes in v2: None
arch/x86/lib/zimage.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-)
arch/x86/lib/zimage.c +12 -9
@@ -243,18 +243,21 @@ int setup_zimage(struct boot_params *setup_base, char *cmd_line, int auto_boot, hdr->loadflags |=HEAP_FLAG ; } -if (bootproto >=0x0202 ) { - hdr->cmd_line_ptr = (uintptr_t )cmd_line; - }else if (bootproto >=0x0200 ) { - setup_base->screen_info.cl_magic =COMMAND_LINE_MAGIC ; - setup_base->screen_info.cl_offset = - (uintptr_t )cmd_line - (uintptr_t )setup_base; +if (cmd_line) { +if (bootproto >=0x0202 ) { + hdr->cmd_line_ptr = (uintptr_t )cmd_line; + }else if (bootproto >=0x0200 ) { + setup_base->screen_info.cl_magic =COMMAND_LINE_MAGIC ; + setup_base->screen_info.cl_offset = + (uintptr_t )cmd_line - (uintptr_t )setup_base; + + hdr->setup_move_size =0x9100 ; + } - hdr->setup_move_size =0x9100 ; +/* build command line at COMMAND_LINE_OFFSET */ +build_command_line (cmd_line, auto_boot); } -/* build command line at COMMAND_LINE_OFFSET */ -build_command_line (cmd_line, auto_boot);return 0 ; }
Signature · 1 line
1.8.4.1
PATCH v2 4/4 x86: Support loading kernel setup from a FIT
In reply to Simon GlassAdd a new setup@ section to the FIT which can be used to provide a setup binary for booting Linux on x86. This makes it possible to boot x86 from a FIT.
---
Changes in v2:
- Rebase to master
common/cmd_bootm.c | 23 ++++++++++++++-- common/image-fit.c | 22 +++++++++++++++ common/image.c | 11 ++++++++ doc/uImage.FIT/kernel.its | 50 +++++++++++++++++++++++++++++++++++ doc/uImage.FIT/source_file_format.txt | 23 +++++++++------- include/bootstage.h | 3 +++ include/image.h | 13 +++++++++ 7 files changed, 133 insertions(+), 12 deletions(-)
common/cmd_bootm.c +21 -2
@@ -20,6 +20,7 @@#include <lmb.h> #include <linux/ctype.h> #include <asm/byteorder.h> +#include <asm/errno.h> #include <asm/io.h> #include <linux/compiler.h>
@@ -207,6 +208,7 @@ static int bootm_find_os(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) {const void *os_hdr; +int ret;/* get kernel image header, start address and length */ os_hdr = boot_get_kernel(cmdtp, flag, argc, argv,
@@ -225,6 +227,7 @@ static int bootm_find_os(cmd_tbl_t *cmdtp, int flag, int argc, images.os.end =image_get_image_end (os_hdr); images.os.load =image_get_load (os_hdr); + images.os.arch =image_get_arch (os_hdr);break ;#if defined(CONFIG_FIT )case IMAGE_FORMAT_FIT :
@@ -249,6 +252,12 @@ static int bootm_find_os(cmd_tbl_t *cmdtp, int flag, int argc,return 1 ; } +if (fit_image_get_arch (images.fit_hdr_os, + images.fit_noffset_os, &images.os.arch)) { +puts ("Can't get image ARCH!\n" ); +return 1 ; + } + images.os.end =fit_get_end (images.fit_hdr_os); if (fit_image_get_load(images.fit_hdr_os, images.fit_noffset_os,
@@ -264,8 +273,18 @@ static int bootm_find_os(cmd_tbl_t *cmdtp, int flag, int argc,return 1 ; } -/* find kernel entry point */ -if (images.legacy_hdr_valid) { +/* If we have a valid setup.bin, we will use that for entry (x86) */ +if (images.os.arch ==IH_ARCH_I386 ) { +ulong len; + +puts ("Looking for setup\n" ); + ret =boot_get_setup (&images,IH_ARCH_I386 , &images.ep, &len); +if (ret <0 && ret != -ENOENT ) { +puts ("Could not find a valid setup.bin for x86n" ); +return 1 ; + } +/* Kernel entry point is the setup.bin */ + }else if (images.legacy_hdr_valid) { images.ep =image_get_ep (&images.legacy_hdr_os_copy);#if defined(CONFIG_FIT ) } else if (images.fit_uname_os) {
common/image-fit.c +22 -0
@@ -1559,11 +1559,13 @@ int fit_image_load(bootm_headers_t *images, const char *prop_name, ulong addr, }bootstage_mark (bootstage_id +BOOTSTAGE_SUB_CHECK_ARCH ); +#ifndef CONFIG_SANDBOX if (!fit_image_check_target_arch (fit, noffset)) {puts ("Unsupported Architecture\n" );bootstage_error (bootstage_id +BOOTSTAGE_SUB_CHECK_ARCH );return -ENOEXEC ; } +#endif if (image_type ==IH_TYPE_FLATDT && !fit_image_check_comp (fit, noffset,IH_COMP_NONE )) {
@@ -1660,3 +1662,23 @@ int fit_image_load(bootm_headers_t *images, const char *prop_name, ulong addr,return noffset; } + +int boot_get_setup_fit (bootm_headers_t *images,uint8_t arch, +ulong *setup_start,ulong *setup_len) +{ +int noffset; +ulong addr; +ulong len; +int ret; + + addr =map_to_sysmem (images->fit_hdr_os); + noffset =fit_get_node_from_config (images,FIT_SETUP_PROP , addr); +if (noffset <0 ) +return noffset; + + ret =fit_image_load (images,FIT_SETUP_PROP , addr,NULL ,NULL , + arch,IH_TYPE_X86_SETUP ,BOOTSTAGE_ID_FIT_SETUP_START , +FIT_LOAD_REQUIRED , setup_start, &len); + +return ret; +}
common/image.c +11 -0
@@ -136,6 +136,7 @@ static const table_entry_t uimage_type[] = { { IH_TYPE_STANDALONE, "standalone", "Standalone Program", }, { IH_TYPE_UBLIMAGE, "ublimage", "Davinci UBL image",}, { IH_TYPE_MXSIMAGE, "mxsimage", "Freescale MXS Boot Image",}, + { IH_TYPE_X86_SETUP, "x86_setup", "x86 setup.bin", }, { -1, "", "", }, };
@@ -1051,6 +1052,16 @@ error: }#endif /* CONFIG_SYS_BOOT_RAMDISK_HIGH */ +int boot_get_setup (bootm_headers_t *images,uint8_t arch, +ulong *setup_start,ulong *setup_len) +{ +#if defined(CONFIG_FIT ) +return boot_get_setup_fit (images, arch, setup_start, setup_len); +#else +return -ENOENT ; +#endif +} +#ifdef CONFIG_SYS_BOOT_GET_CMDLINE /** * boot_get_cmdline - allocate and initialize kernel cmdline
doc/uImage.FIT/kernel.its +50 -0
53 lines not on this page · raw message
doc/uImage.FIT/source_file_format.txt +13 -10
@@ -55,7 +55,7 @@ FIT is formally a flattened device tree (in the libfdt meaning), which conforms to bindings defined in this document. .its - image tree source -.itb - image tree blob +.fit - flattened image tree blob c) Image building procedure
@@ -101,15 +101,15 @@ Root node of the uImage Tree should have the following layout: | o images | | - | o img at 1 {...} - | o img at 2 {...} + | o image at 1 {...} + | o image at 2 {...} | ... | o configurations - |- default = "cfg at 1" + |- default = "conf at 1" | - o cfg at 1 {...} - o cfg at 2 {...} + o conf at 1 {...} + o conf at 2 {...} ...
@@ -159,11 +159,11 @@ the '/images' node should have the following layout: - description : Textual description of the component sub-image - type : Name of component sub-image type, supported types are: "standalone", "kernel", "ramdisk", "firmware", "script", "filesystem", - "fdt". + "fdt" and others (see uimage_type in common/images.c). - data : Path to the external file which contains this node's binary data. - compression : Compression used by included data. Supported compressions - are "gzip" and "bzip2". If no compression is used compression property - should be set to "none". + include "gzip" and "bzip2" (see uimage_comp in common/images.c). If no + compression is used, the compression property should be set to "none". Conditionally mandatory property: - os : OS name, mandatory for type="kernel", valid OS names are: "openbsd",
@@ -173,7 +173,8 @@ the '/images' node should have the following layout: - arch : Architecture name, mandatory for types: "standalone", "kernel", "firmware", "ramdisk" and "fdt". Valid architecture names are: "alpha", "arm", "i386", "ia64", "mips", "mips64", "ppc", "s390", "sh", "sparc", - "sparc64", "m68k", "microblaze", "nios2", "blackfin", "avr32", "st200". + "sparc64", "m68k", "microblaze", "nios2", "blackfin", "avr32", "st200", + "sandbox". - entry : entry point address, address size is determined by '#address-cells' property of the root node. Mandatory for for types: "standalone" and "kernel".
@@ -246,6 +247,8 @@ o config at 1 node of a "ramdisk" type). - fdt : Unit name of the corresponding fdt blob (component image node of a "fdt type"). + - setup : Unit name of the corresponding setup binary (used for booting + an x86 kernel). This contains the setup.bin file built by the kernel. The FDT blob is required to properly boot FDT based kernel, so the minimal configuration for 2.6 FDT kernel is (kernel, fdt) pair.
include/bootstage.h +3 -0
@@ -159,6 +159,9 @@ enum bootstage_id {/* Next 10 IDs used by BOOTSTAGE_SUB_... */ BOOTSTAGE_ID_FIT_RD_START =120 ,/* Ramdisk stages */ +/* Next 10 IDs used by BOOTSTAGE_SUB_... */ +BOOTSTAGE_ID_FIT_SETUP_START =130 ,/* x86 setup stages */ +BOOTSTAGE_ID_IDE_FIT_READ =140 , BOOTSTAGE_ID_IDE_FIT_READ_OK,
include/image.h +13 -0
@@ -213,6 +213,7 @@ struct lmb;#define IH_TYPE_KERNEL_NOLOAD 14/* OS Kernel Image, can run from any load address */ #define IH_TYPE_PBLIMAGE 15/* Freescale PBL Boot Image */ #define IH_TYPE_MXSIMAGE 16/* Freescale MXSBoot Image */ +#define IH_TYPE_X86_SETUP 17/* x86 setup.bin Image */ /* * Compression Types
@@ -253,6 +254,7 @@ typedef struct image_info {ulong image_start, image_len;/* start of image within blob, len of image */ ulong load;/* load addr for the image */ uint8_t comp, type, os;/* compression, type of image, os type */ +uint8_t arch;/* CPU architecture */ } image_info_t;/*
@@ -283,6 +285,10 @@ typedef struct bootm_headers {void *fit_hdr_fdt;/* FDT blob FIT image header */ const char *fit_uname_fdt;/* FDT blob subimage node unit name */ int fit_noffset_fdt;/* FDT blob subimage node offset */ + +void *fit_hdr_setup;/* x86 setup FIT image header */ +const char *fit_uname_setup;/* x86 setup subimage node name */ +int fit_noffset_setup;/* x86 setup subimage node offset */ #endif #ifndef USE_HOSTCC
@@ -396,6 +402,9 @@ enum fit_load_op { FIT_LOAD_REQUIRED, /* Must be provided */ }; +int boot_get_setup (bootm_headers_t *images,uint8_t arch,ulong *setup_start, +ulong *setup_len); +#ifndef USE_HOSTCC /* Image format types, returned by _get_format() routine */ #define IMAGE_FORMAT_INVALID 0x00
@@ -409,6 +418,9 @@ ulong genimg_get_image(ulong img_addr);int boot_get_ramdisk (int argc,char *const argv[],bootm_headers_t *images,uint8_t arch,ulong *rd_start,ulong *rd_end); +int boot_get_setup_fit (bootm_headers_t *images,uint8_t arch, +ulong *setup_start,ulong *setup_len); +/** * fit_image_load() - load an image from a FIT *
@@ -689,6 +701,7 @@ int bootz_setup(ulong image, ulong *start, ulong *end);#define FIT_RAMDISK_PROP "ramdisk"#define FIT_FDT_PROP "fdt"#define FIT_DEFAULT_PROP "default" +#define FIT_SETUP_PROP "setup"#define FIT_MAX_HASH_LEN 20/* max(crc32_len(4), sha1_len(20)) */
Signature · 1 line
1.8.4.1