diff mbox series

[U-Boot,v3] x86: zImage: pass device tree setup data to the kernel

Message ID 20180317003226.GA56912@intel.com
State Superseded
Delegated to: Bin Meng
Headers show
Series [U-Boot,v3] x86: zImage: pass device tree setup data to the kernel | expand

Commit Message

Ivan Gorinov March 17, 2018, 12:32 a.m. UTC
On x86 platforms, U-Boot does not provide Device Tree data to the kernel.
This prevents the kernel from using the same hardware description.

Make a copy of DTB data with setup_data header and insert new item
into the the setup data linked list.

Signed-off-by: Ivan Gorinov <ivan.gorinov@intel.com>
---
 arch/x86/include/asm/bootparam.h |  7 +++++--
 arch/x86/lib/zimage.c            | 31 +++++++++++++++++++++++++++++++
 2 files changed, 36 insertions(+), 2 deletions(-)

Comments

Bin Meng March 19, 2018, 3:38 a.m. UTC | #1
Hi Ivan,

On Sat, Mar 17, 2018 at 8:32 AM, Ivan Gorinov <ivan.gorinov@intel.com> wrote:
> On x86 platforms, U-Boot does not provide Device Tree data to the kernel.
> This prevents the kernel from using the same hardware description.
>
> Make a copy of DTB data with setup_data header and insert new item
> into the the setup data linked list.
>

So this means the Linux kernel reuses the same DTB as what is used by
U-Boot. However U-Boot's DTB contains a lot of stuff which is only
useful for bootloader, like the microcode stuff.

Like other arch's bootm command, should we allow a separate DTB (which
is only used by the kernel) passed to the 'zboot' command?

> Signed-off-by: Ivan Gorinov <ivan.gorinov@intel.com>
> ---
>  arch/x86/include/asm/bootparam.h |  7 +++++--
>  arch/x86/lib/zimage.c            | 31 +++++++++++++++++++++++++++++++
>  2 files changed, 36 insertions(+), 2 deletions(-)
>
> diff --git a/arch/x86/include/asm/bootparam.h b/arch/x86/include/asm/bootparam.h
> index 90768a9..6aba614 100644
> --- a/arch/x86/include/asm/bootparam.h
> +++ b/arch/x86/include/asm/bootparam.h
> @@ -10,8 +10,11 @@
>  #include <asm/video/edid.h>
>
>  /* setup data types */
> -#define SETUP_NONE                     0
> -#define SETUP_E820_EXT                 1
> +enum {
> +       SETUP_NONE = 0,
> +       SETUP_E820_EXT,
> +       SETUP_DTB,
> +};
>
>  /* extensible setup data list node */
>  struct setup_data {
> diff --git a/arch/x86/lib/zimage.c b/arch/x86/lib/zimage.c
> index 2a82bc8..7e7ec5e 100644
> --- a/arch/x86/lib/zimage.c
> +++ b/arch/x86/lib/zimage.c
> @@ -14,6 +14,7 @@
>   */
>
>  #include <common.h>
> +#include <malloc.h>
>  #include <asm/acpi_table.h>
>  #include <asm/io.h>
>  #include <asm/ptrace.h>
> @@ -95,6 +96,35 @@ static int get_boot_protocol(struct setup_header *hdr)
>         }
>  }
>
> +static int setup_device_tree(struct setup_header *hdr)
> +{
> +       const void *fdt_blob = gd->fdt_blob;
> +       struct setup_data *sd;
> +       int size;
> +
> +       if (!fdt_blob)
> +               return 0;
> +
> +       size = fdt_totalsize(fdt_blob);
> +       if (size < 0)
> +               return -EINVAL;
> +
> +       size += sizeof(struct setup_data);
> +       sd = (struct setup_data *)malloc(size);
> +       if (!sd) {
> +               printf("Not enough memory for DTB setup data\n");
> +               return -ENOMEM;
> +       }
> +
> +       sd->next = hdr->setup_data;
> +       sd->type = SETUP_DTB;
> +       sd->len = fdt_totalsize(fdt_blob);
> +       memcpy(sd->data, fdt_blob, sd->len);
> +       hdr->setup_data = (unsigned long)sd;
> +
> +       return 0;
> +}
> +
>  struct boot_params *load_zimage(char *image, unsigned long kernel_size,
>                                 ulong *load_addressp)
>  {
> @@ -262,6 +292,7 @@ int setup_zimage(struct boot_params *setup_base, char *cmd_line, int auto_boot,
>  #endif
>
>         setup_video(&setup_base->screen_info);
> +       setup_device_tree(hdr);
>
>         return 0;
>  }
> --

Regards,
Bin
Simon Glass March 19, 2018, 5:59 p.m. UTC | #2
On 18 March 2018 at 21:38, Bin Meng <bmeng.cn@gmail.com> wrote:
> Hi Ivan,
>
> On Sat, Mar 17, 2018 at 8:32 AM, Ivan Gorinov <ivan.gorinov@intel.com> wrote:
>> On x86 platforms, U-Boot does not provide Device Tree data to the kernel.
>> This prevents the kernel from using the same hardware description.
>>
>> Make a copy of DTB data with setup_data header and insert new item
>> into the the setup data linked list.
>>
>
> So this means the Linux kernel reuses the same DTB as what is used by
> U-Boot. However U-Boot's DTB contains a lot of stuff which is only
> useful for bootloader, like the microcode stuff.
>
> Like other arch's bootm command, should we allow a separate DTB (which
> is only used by the kernel) passed to the 'zboot' command?

Yes I think so. Probably this needs another arg to zboot.

Also we do support FIT boot on x86 so should make sure that the DT can
be passed in that case too.

>
>> Signed-off-by: Ivan Gorinov <ivan.gorinov@intel.com>
>> ---
>>  arch/x86/include/asm/bootparam.h |  7 +++++--
>>  arch/x86/lib/zimage.c            | 31 +++++++++++++++++++++++++++++++
>>  2 files changed, 36 insertions(+), 2 deletions(-)
>>
>> diff --git a/arch/x86/include/asm/bootparam.h b/arch/x86/include/asm/bootparam.h
>> index 90768a9..6aba614 100644
>> --- a/arch/x86/include/asm/bootparam.h
>> +++ b/arch/x86/include/asm/bootparam.h
>> @@ -10,8 +10,11 @@
>>  #include <asm/video/edid.h>
>>
>>  /* setup data types */
>> -#define SETUP_NONE                     0
>> -#define SETUP_E820_EXT                 1
>> +enum {
>> +       SETUP_NONE = 0,
>> +       SETUP_E820_EXT,
>> +       SETUP_DTB,
>> +};
>>
>>  /* extensible setup data list node */
>>  struct setup_data {
>> diff --git a/arch/x86/lib/zimage.c b/arch/x86/lib/zimage.c
>> index 2a82bc8..7e7ec5e 100644
>> --- a/arch/x86/lib/zimage.c
>> +++ b/arch/x86/lib/zimage.c
>> @@ -14,6 +14,7 @@
>>   */
>>
>>  #include <common.h>
>> +#include <malloc.h>
>>  #include <asm/acpi_table.h>
>>  #include <asm/io.h>
>>  #include <asm/ptrace.h>
>> @@ -95,6 +96,35 @@ static int get_boot_protocol(struct setup_header *hdr)
>>         }
>>  }
>>
>> +static int setup_device_tree(struct setup_header *hdr)
>> +{
>> +       const void *fdt_blob = gd->fdt_blob;
>> +       struct setup_data *sd;
>> +       int size;
>> +
>> +       if (!fdt_blob)
>> +               return 0;
>> +
>> +       size = fdt_totalsize(fdt_blob);
>> +       if (size < 0)
>> +               return -EINVAL;
>> +
>> +       size += sizeof(struct setup_data);
>> +       sd = (struct setup_data *)malloc(size);
>> +       if (!sd) {
>> +               printf("Not enough memory for DTB setup data\n");
>> +               return -ENOMEM;
>> +       }
>> +
>> +       sd->next = hdr->setup_data;
>> +       sd->type = SETUP_DTB;
>> +       sd->len = fdt_totalsize(fdt_blob);
>> +       memcpy(sd->data, fdt_blob, sd->len);
>> +       hdr->setup_data = (unsigned long)sd;
>> +
>> +       return 0;
>> +}
>> +
>>  struct boot_params *load_zimage(char *image, unsigned long kernel_size,
>>                                 ulong *load_addressp)
>>  {
>> @@ -262,6 +292,7 @@ int setup_zimage(struct boot_params *setup_base, char *cmd_line, int auto_boot,
>>  #endif
>>
>>         setup_video(&setup_base->screen_info);
>> +       setup_device_tree(hdr);
>>
>>         return 0;
>>  }
>> --
>
> Regards,
> Bin

Regards,
Simon
diff mbox series

Patch

diff --git a/arch/x86/include/asm/bootparam.h b/arch/x86/include/asm/bootparam.h
index 90768a9..6aba614 100644
--- a/arch/x86/include/asm/bootparam.h
+++ b/arch/x86/include/asm/bootparam.h
@@ -10,8 +10,11 @@ 
 #include <asm/video/edid.h>
 
 /* setup data types */
-#define SETUP_NONE			0
-#define SETUP_E820_EXT			1
+enum {
+	SETUP_NONE = 0,
+	SETUP_E820_EXT,
+	SETUP_DTB,
+};
 
 /* extensible setup data list node */
 struct setup_data {
diff --git a/arch/x86/lib/zimage.c b/arch/x86/lib/zimage.c
index 2a82bc8..7e7ec5e 100644
--- a/arch/x86/lib/zimage.c
+++ b/arch/x86/lib/zimage.c
@@ -14,6 +14,7 @@ 
  */
 
 #include <common.h>
+#include <malloc.h>
 #include <asm/acpi_table.h>
 #include <asm/io.h>
 #include <asm/ptrace.h>
@@ -95,6 +96,35 @@  static int get_boot_protocol(struct setup_header *hdr)
 	}
 }
 
+static int setup_device_tree(struct setup_header *hdr)
+{
+	const void *fdt_blob = gd->fdt_blob;
+	struct setup_data *sd;
+	int size;
+
+	if (!fdt_blob)
+		return 0;
+
+	size = fdt_totalsize(fdt_blob);
+	if (size < 0)
+		return -EINVAL;
+
+	size += sizeof(struct setup_data);
+	sd = (struct setup_data *)malloc(size);
+	if (!sd) {
+		printf("Not enough memory for DTB setup data\n");
+		return -ENOMEM;
+	}
+
+	sd->next = hdr->setup_data;
+	sd->type = SETUP_DTB;
+	sd->len = fdt_totalsize(fdt_blob);
+	memcpy(sd->data, fdt_blob, sd->len);
+	hdr->setup_data = (unsigned long)sd;
+
+	return 0;
+}
+
 struct boot_params *load_zimage(char *image, unsigned long kernel_size,
 				ulong *load_addressp)
 {
@@ -262,6 +292,7 @@  int setup_zimage(struct boot_params *setup_base, char *cmd_line, int auto_boot,
 #endif
 
 	setup_video(&setup_base->screen_info);
+	setup_device_tree(hdr);
 
 	return 0;
 }