]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
boot: fdt: Change type of env_get_bootm_low() to phys_addr_t
authorMarek Vasut <marek.vasut+renesas@mailbox.org>
Tue, 26 Mar 2024 22:13:11 +0000 (23:13 +0100)
committerTom Rini <trini@konsulko.com>
Thu, 11 Apr 2024 15:38:57 +0000 (09:38 -0600)
Change type of ulong env_get_bootm_low() to phys_addr_t env_get_bootm_low().
The PPC/LS systems already treat env_get_bootm_low() result as phys_addr_t,
while the function itself still returns ulong. This is potentially dangerous
on 64bit systems, where ulong might not be large enough to hold the content
of "bootm_low" environment variable. Fix it by using phys_addr_t, similar to
what env_get_bootm_size() does, which returns phys_size_t .

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reported-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Marek Vasut <marek.vasut+renesas@mailbox.org>
boot/bootm.c
boot/image-board.c
boot/image-fdt.c
include/image.h

index d071537d6921162148983a426e353e6a1f1790a4..032f5a4a160540a1e265886c121660fd08b4d0cb 100644 (file)
@@ -242,13 +242,13 @@ static int boot_get_kernel(const char *addr_fit, struct bootm_headers *images,
 #ifdef CONFIG_LMB
 static void boot_start_lmb(struct bootm_headers *images)
 {
-       ulong           mem_start;
+       phys_addr_t     mem_start;
        phys_size_t     mem_size;
 
        mem_start = env_get_bootm_low();
        mem_size = env_get_bootm_size();
 
-       lmb_init_and_reserve_range(&images->lmb, (phys_addr_t)mem_start,
+       lmb_init_and_reserve_range(&images->lmb, mem_start,
                                   mem_size, NULL);
 }
 #else
index 75f6906cd564b90903a7e9834b6fc7d582f9bde5..3263497a1d5ff18423e6f090d0b2dbae7695bb44 100644 (file)
@@ -107,14 +107,12 @@ static int on_loadaddr(const char *name, const char *value, enum env_op op,
 }
 U_BOOT_ENV_CALLBACK(loadaddr, on_loadaddr);
 
-ulong env_get_bootm_low(void)
+phys_addr_t env_get_bootm_low(void)
 {
        char *s = env_get("bootm_low");
 
-       if (s) {
-               ulong tmp = hextoul(s, NULL);
-               return tmp;
-       }
+       if (s)
+               return simple_strtoull(s, NULL, 16);
 
 #if defined(CFG_SYS_SDRAM_BASE)
        return CFG_SYS_SDRAM_BASE;
@@ -538,7 +536,7 @@ int boot_ramdisk_high(struct lmb *lmb, ulong rd_data, ulong rd_len,
                      ulong *initrd_start, ulong *initrd_end)
 {
        char    *s;
-       ulong   initrd_high;
+       phys_addr_t initrd_high;
        int     initrd_copy_to_ram = 1;
 
        s = env_get("initrd_high");
@@ -553,8 +551,8 @@ int boot_ramdisk_high(struct lmb *lmb, ulong rd_data, ulong rd_len,
                initrd_high = env_get_bootm_mapsize() + env_get_bootm_low();
        }
 
-       debug("## initrd_high = 0x%08lx, copy_to_ram = %d\n",
-             initrd_high, initrd_copy_to_ram);
+       debug("## initrd_high = 0x%llx, copy_to_ram = %d\n",
+             (u64)initrd_high, initrd_copy_to_ram);
 
        if (rd_data) {
                if (!initrd_copy_to_ram) {      /* zero-copy ramdisk support */
index 5e4aa9de0d279cdca370c0d2d964712006e55fc2..c2571b22244d9485c19e07c9caa0fb4e3d39d7a6 100644 (file)
@@ -160,9 +160,10 @@ int boot_relocate_fdt(struct lmb *lmb, char **of_flat_tree, ulong *of_size)
 {
        void    *fdt_blob = *of_flat_tree;
        void    *of_start = NULL;
-       u64     start, size, usable;
+       phys_addr_t start, size, usable;
        char    *fdt_high;
-       ulong   mapsize, low;
+       phys_addr_t low;
+       phys_size_t mapsize;
        ulong   of_len = 0;
        int     bank;
        int     err;
@@ -217,7 +218,7 @@ int boot_relocate_fdt(struct lmb *lmb, char **of_flat_tree, ulong *of_size)
                        if (start + size < low)
                                continue;
 
-                       usable = min(start + size, (u64)(low + mapsize));
+                       usable = min(start + size, low + mapsize);
 
                        /*
                         * At least part of this DRAM bank is usable, try
@@ -233,7 +234,7 @@ int boot_relocate_fdt(struct lmb *lmb, char **of_flat_tree, ulong *of_size)
                         * Reduce the mapping size in the next bank
                         * by the size of attempt in current bank.
                         */
-                       mapsize -= usable - max(start, (u64)low);
+                       mapsize -= usable - max(start, low);
                        if (!mapsize)
                                break;
                }
index 21de70f0c9e4687005bf5f1f5c4b0e1c61791d6c..acffd17e0dfd03ee37feddbe69357e24d06a0b19 100644 (file)
@@ -946,7 +946,7 @@ static inline void image_set_name(struct legacy_img_hdr *hdr, const char *name)
 int image_check_hcrc(const struct legacy_img_hdr *hdr);
 int image_check_dcrc(const struct legacy_img_hdr *hdr);
 #ifndef USE_HOSTCC
-ulong env_get_bootm_low(void);
+phys_addr_t env_get_bootm_low(void);
 phys_size_t env_get_bootm_size(void);
 phys_size_t env_get_bootm_mapsize(void);
 #endif