devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* linaro-uboot: device tree without ramdisk and boot_relocate_fdt cause illegal memory access in kernel
@ 2011-05-27  8:52 Barry Song
       [not found] ` <BANLkTikK9EVVZrRa1--8n1j_OXv2qK8XmA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
  0 siblings, 1 reply; 3+ messages in thread
From: Barry Song @ 2011-05-27  8:52 UTC (permalink / raw)
  To: linaro-dev; +Cc: devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ

Hi all,
i am using linaro uboot(u-boot-linaro-stable.git).  i have let our
prima2 board support device tree with some workaround in uboot.  two
problems i have meet:
1. device tree without ramdisk
now uboot used commands like
"bootm kernel_address  ramdisk_address dtb_address"
to start linux kernel.
in many cases, people have no ramdisk at all, but the following codes
will still stop people to use device tree to start kernel since it got
an illegal ramdisk:

common/cmd_bootm.c:
        if (((images.os.type == IH_TYPE_KERNEL) ||
             (images.os.type == IH_TYPE_MULTI)) &&
            (images.os.os == IH_OS_LINUX)) {
                /* find ramdisk */
                ret = boot_get_ramdisk (argc, argv, &images, IH_INITRD_ARCH,
                                &images.rd_start, &images.rd_end);
                if (ret) {
                        puts ("Ramdisk image is corrupt or invalid\n");
                       return 1;
                }

#if defined(CONFIG_OF_LIBFDT)
                /* find flattened device tree */
                ret = boot_get_fdt (flag, argc, argv, &images,
                                    &images.ft_addr, &images.ft_len);
                if (ret) {
                        puts ("Could not find a valid device tree\n");
                        return 1;
                }
then i delete the first return 1 to let uboot ignore the ramdisk checking.

2. boot_relocate_fdt in common/image.c
this function will relocate fdt to an new address by:
lmb_alloc_base(lmb, of_len, 0x1000, getenv_bootm_mapsize() + getenv_bootm_low())

but the return address is probably not in the initilized scale which
kernel will build mapping in head.S. then in the function
setup_machine_fdt() of arch/arm/kernel/devtree.c, when executing:
         devtree = phys_to_virt(dt_phys);

        /* check device tree validity */
        if (be32_to_cpu(devtree->magic) != OF_DT_HEADER)
                return NULL;
kernel will die due to illegal memory access since dt_phys was not
mapped to virtual address yet.

For problem1 , could uboot have a way to ignore ramdisk by itself?
since we need 3 param in bootm to support device tree. For problem2,
could uboot just relocate fdt to the original address of old ATAG,
OFF+ 0x100?

Thanks
Barry

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: linaro-uboot: device tree without ramdisk and boot_relocate_fdt cause illegal memory access in kernel
       [not found] ` <BANLkTikK9EVVZrRa1--8n1j_OXv2qK8XmA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
@ 2011-05-27  9:31   ` Shawn Guo
       [not found]     ` <20110527093141.GE30146-+NayF8gZjK2ctlrPMvKcciBecyulp+rMXqFh9Ls21Oc@public.gmane.org>
  0 siblings, 1 reply; 3+ messages in thread
From: Shawn Guo @ 2011-05-27  9:31 UTC (permalink / raw)
  To: Barry Song; +Cc: devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ, linaro-dev

On Fri, May 27, 2011 at 04:52:38PM +0800, Barry Song wrote:
> Hi all,
> i am using linaro uboot(u-boot-linaro-stable.git).  i have let our
> prima2 board support device tree with some workaround in uboot.  two
> problems i have meet:
> 1. device tree without ramdisk
> now uboot used commands like
> "bootm kernel_address  ramdisk_address dtb_address"
> to start linux kernel.
> in many cases, people have no ramdisk at all, but the following codes
> will still stop people to use device tree to start kernel since it got
> an illegal ramdisk:
> 
> common/cmd_bootm.c:
>         if (((images.os.type == IH_TYPE_KERNEL) ||
>              (images.os.type == IH_TYPE_MULTI)) &&
>             (images.os.os == IH_OS_LINUX)) {
>                 /* find ramdisk */
>                 ret = boot_get_ramdisk (argc, argv, &images, IH_INITRD_ARCH,
>                                 &images.rd_start, &images.rd_end);
>                 if (ret) {
>                         puts ("Ramdisk image is corrupt or invalid\n");
>                        return 1;
>                 }
> 
> #if defined(CONFIG_OF_LIBFDT)
>                 /* find flattened device tree */
>                 ret = boot_get_fdt (flag, argc, argv, &images,
>                                     &images.ft_addr, &images.ft_len);
>                 if (ret) {
>                         puts ("Could not find a valid device tree\n");
>                         return 1;
>                 }
> then i delete the first return 1 to let uboot ignore the ramdisk checking.
> 
> 2. boot_relocate_fdt in common/image.c
> this function will relocate fdt to an new address by:
> lmb_alloc_base(lmb, of_len, 0x1000, getenv_bootm_mapsize() + getenv_bootm_low())
> 
> but the return address is probably not in the initilized scale which
> kernel will build mapping in head.S. then in the function
> setup_machine_fdt() of arch/arm/kernel/devtree.c, when executing:
>          devtree = phys_to_virt(dt_phys);
> 
>         /* check device tree validity */
>         if (be32_to_cpu(devtree->magic) != OF_DT_HEADER)
>                 return NULL;
> kernel will die due to illegal memory access since dt_phys was not
> mapped to virtual address yet.
> 
> For problem1 , could uboot have a way to ignore ramdisk by itself?
> since we need 3 param in bootm to support device tree. For problem2,

bootm kernel_address - dtb_address

Use '-' for ramdisk address, if you do not have a ramdisk image.

> could uboot just relocate fdt to the original address of old ATAG,
> OFF+ 0x100?
> 
Do you have the following commit on your kernel tree?

commit 4d901c4271951d110afb13ee9aa73d27a6c8e53d
Author: Rob Herring <rob.herring-bsGFqQB8/DxBDgjK7y7TUQ@public.gmane.org>
Date:   Wed Feb 2 16:33:17 2011 +0100

    ARM: 6648/1: map ATAGs when not in first 1MB of RAM

    If ATAGs or DTB pointer is not within first 1MB of RAM, then the boot params
    will not be mapped early enough, so map the 1MB region that r2 points to. Only
    map the first 1MB when r2 is 0.

    Some assembly improvements from Nicolas Pitre.

    Acked-by: Tony Lindgren <tony-4v6yS6AI5VpBDgjK7y7TUQ@public.gmane.org>
    Acked-by: Nicolas Pitre <nicolas.pitre-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
    Signed-off-by: Rob Herring <rob.herring-bsGFqQB8/DxBDgjK7y7TUQ@public.gmane.org>
    Signed-off-by: Russell King <rmk+kernel-lFZ/pmaqli7XmaaqVzeoHQ@public.gmane.org>

You can get it from linux-linaro-2.6.38 tree.

-- 
Regards,
Shawn

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: linaro-uboot: device tree without ramdisk and boot_relocate_fdt cause illegal memory access in kernel
       [not found]     ` <20110527093141.GE30146-+NayF8gZjK2ctlrPMvKcciBecyulp+rMXqFh9Ls21Oc@public.gmane.org>
@ 2011-05-28 14:54       ` Barry Song
  0 siblings, 0 replies; 3+ messages in thread
From: Barry Song @ 2011-05-28 14:54 UTC (permalink / raw)
  To: Shawn Guo; +Cc: devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ, linaro-dev

hi Shawn,
thanks a lot.
-barry

2011/5/27 Shawn Guo <shawn.guo@freescale.com>:
> On Fri, May 27, 2011 at 04:52:38PM +0800, Barry Song wrote:
>> Hi all,
>> i am using linaro uboot(u-boot-linaro-stable.git).  i have let our
>> prima2 board support device tree with some workaround in uboot.  two
>> problems i have meet:
>> 1. device tree without ramdisk
>> now uboot used commands like
>> "bootm kernel_address  ramdisk_address dtb_address"
>> to start linux kernel.
>> in many cases, people have no ramdisk at all, but the following codes
>> will still stop people to use device tree to start kernel since it got
>> an illegal ramdisk:
>>
>> common/cmd_bootm.c:
>>         if (((images.os.type == IH_TYPE_KERNEL) ||
>>              (images.os.type == IH_TYPE_MULTI)) &&
>>             (images.os.os == IH_OS_LINUX)) {
>>                 /* find ramdisk */
>>                 ret = boot_get_ramdisk (argc, argv, &images, IH_INITRD_ARCH,
>>                                 &images.rd_start, &images.rd_end);
>>                 if (ret) {
>>                         puts ("Ramdisk image is corrupt or invalid\n");
>>                        return 1;
>>                 }
>>
>> #if defined(CONFIG_OF_LIBFDT)
>>                 /* find flattened device tree */
>>                 ret = boot_get_fdt (flag, argc, argv, &images,
>>                                     &images.ft_addr, &images.ft_len);
>>                 if (ret) {
>>                         puts ("Could not find a valid device tree\n");
>>                         return 1;
>>                 }
>> then i delete the first return 1 to let uboot ignore the ramdisk checking.
>>
>> 2. boot_relocate_fdt in common/image.c
>> this function will relocate fdt to an new address by:
>> lmb_alloc_base(lmb, of_len, 0x1000, getenv_bootm_mapsize() + getenv_bootm_low())
>>
>> but the return address is probably not in the initilized scale which
>> kernel will build mapping in head.S. then in the function
>> setup_machine_fdt() of arch/arm/kernel/devtree.c, when executing:
>>          devtree = phys_to_virt(dt_phys);
>>
>>         /* check device tree validity */
>>         if (be32_to_cpu(devtree->magic) != OF_DT_HEADER)
>>                 return NULL;
>> kernel will die due to illegal memory access since dt_phys was not
>> mapped to virtual address yet.
>>
>> For problem1 , could uboot have a way to ignore ramdisk by itself?
>> since we need 3 param in bootm to support device tree. For problem2,
>
> bootm kernel_address - dtb_address
>
> Use '-' for ramdisk address, if you do not have a ramdisk image.
>
>> could uboot just relocate fdt to the original address of old ATAG,
>> OFF+ 0x100?
>>
> Do you have the following commit on your kernel tree?
>
> commit 4d901c4271951d110afb13ee9aa73d27a6c8e53d
> Author: Rob Herring <rob.herring@calxeda.com>
> Date:   Wed Feb 2 16:33:17 2011 +0100
>
>    ARM: 6648/1: map ATAGs when not in first 1MB of RAM
>
>    If ATAGs or DTB pointer is not within first 1MB of RAM, then the boot params
>    will not be mapped early enough, so map the 1MB region that r2 points to. Only
>    map the first 1MB when r2 is 0.
>
>    Some assembly improvements from Nicolas Pitre.
>
>    Acked-by: Tony Lindgren <tony@atomide.com>
>    Acked-by: Nicolas Pitre <nicolas.pitre@linaro.org>
>    Signed-off-by: Rob Herring <rob.herring@calxeda.com>
>    Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
>
> You can get it from linux-linaro-2.6.38 tree.

>
> --
> Regards,
> Shawn
>
_______________________________________________
devicetree-discuss mailing list
devicetree-discuss@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/devicetree-discuss

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2011-05-28 14:54 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-05-27  8:52 linaro-uboot: device tree without ramdisk and boot_relocate_fdt cause illegal memory access in kernel Barry Song
     [not found] ` <BANLkTikK9EVVZrRa1--8n1j_OXv2qK8XmA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2011-05-27  9:31   ` Shawn Guo
     [not found]     ` <20110527093141.GE30146-+NayF8gZjK2ctlrPMvKcciBecyulp+rMXqFh9Ls21Oc@public.gmane.org>
2011-05-28 14:54       ` Barry Song

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).