riscv: booti: do not force relocation if force_reloc is not set
authorVitaly Wool <vitaly.wool@konsulko.com>
Tue, 6 Apr 2021 07:50:16 +0000 (10:50 +0300)
committerLeo Yu-Chi Liang <ycliang@andestech.com>
Wed, 21 Jul 2021 08:38:26 +0000 (16:38 +0800)
If force_reloc flag is not set and booti is called for an address
ouside RAM (i. e. QSPI NOR flash), we should honor that and not try
to force relocation in a bogus fashion.

Signed-off-by: Vitaly Wool <vitaly.wool@konsulko.com>
Reviewed-by: Leo Yu-Chi Liang <ycliang@andestech.com>
arch/riscv/lib/image.c

index 47f2edc..a65a5b8 100644 (file)
@@ -50,7 +50,12 @@ int booti_setup(ulong image, ulong *relocated_addr, ulong *size,
                return -EINVAL;
        }
        *size = lhdr->image_size;
-       *relocated_addr = gd->ram_base + lhdr->text_offset;
+       if (force_reloc ||
+          (gd->ram_base <= image && image < gd->ram_base + gd->ram_size)) {
+               *relocated_addr = gd->ram_base + lhdr->text_offset;
+       } else {
+               *relocated_addr = image;
+       }
 
        unmap_sysmem(lhdr);