[PATCH 3/6] spl: LOAD_FIT_FULL: Relocate FDT for u-boot payloads

Alex G. mr.nuke.me at gmail.com
Mon Mar 29 19:36:46 CEST 2021


On 3/29/21 2:43 AM, Simon Glass wrote:
> Hi Alexandru,

>> diff --git a/common/spl/spl.c b/common/spl/spl.c
>> index 8f6c8dba6f..e63f05bb33 100644
>> --- a/common/spl/spl.c
>> +++ b/common/spl/spl.c
>> @@ -201,6 +201,7 @@ static int spl_load_fit_image(struct spl_image_info *spl_image,
>>   {
>>          bootm_headers_t images;
>>          const char *fit_uname_config = NULL;
>> +       uintptr_t fdt_hack;
>>          const char *uname;
>>          ulong fw_data = 0, dt_data = 0, img_data = 0;
>>          ulong fw_len = 0, dt_len = 0, img_len = 0;
>> @@ -233,9 +234,18 @@ static int spl_load_fit_image(struct spl_image_info *spl_image,
>>          ret = fit_image_load(&images, (ulong)header, NULL, &fit_uname_config,
>>                         IH_ARCH_DEFAULT, IH_TYPE_FLATDT, -1,
>>                         FIT_LOAD_OPTIONAL, &dt_data, &dt_len);
>> -       if (ret >= 0)
>> +       if (ret >= 0) {
>>                  spl_image->fdt_addr = (void *)dt_data;
>>
>> +               if (spl_image->os == IH_OS_U_BOOT) {
>> +                       /* HACK: U-boot expects FDT at a specific address */
>> +                       fdt_hack = spl_image->load_addr + spl_image->size;
>> +                       fdt_hack = (fdt_hack + 3) & ~3;
> 
> I don't think this is needed and it just confuses things. If U-Boot is
> not an aligned sign, it can't boot because the DT ends up in the wrong
> place. The build system makes sure this doesn't happen.

The correct alignment for an FDT is 8 bytes. For a while, this alignment 
was implemented [1], and that worked fine with everything but u-boot.

Now to the build system argument. I don't think It's wise the assume the 
conventions of the SPL build and of the u-boot build are the same. Even 
assuming the branch building the SPL is perfect, the FIT image could 
have been built from a buggy u-boot branch, or even assembled manually 
outside the u-boot build.

Consequently, we can't assume the FIT image will have a spl_image->size 
of the correct alignment. Thus, aligning things by hand is quite necessary.

The problem with [1] is that it broke booting u-boot with FIT. It had to 
be reverted [2]. There was a lengthy email discussion about, where I 
included an example of the failure [3]. Now, wish the actual problem 
could be fixed, but I don't have the bandwidth. The best I can do is 
document the problem.

Alex

[1] 
https://source.denx.de/u-boot/u-boot/-/commit/eb39d8ba5f0d1468b01b89a2a464d18612d3ea76
[2] 
https://source.denx.de/u-boot/u-boot/-/commit/5675ed7cb645f5ec13958726992daeeed16fd114
[3] https://lists.denx.de/pipermail/u-boot/2020-October/430058.html


More information about the U-Boot mailing list