]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
spl: Use map_sysmem where appropriate
authorSean Anderson <seanga2@gmail.com>
Sat, 14 Oct 2023 20:47:55 +0000 (16:47 -0400)
committerTom Rini <trini@konsulko.com>
Wed, 18 Oct 2023 00:50:52 +0000 (20:50 -0400)
All "physical" addresses in SPL must be converted to virtual addresses
before access in order for sandbox to work. Add some calls to map_sysmem in
appropriate places. We do not generally call unmap_sysmem, since we need
the image memory to still be mapped when we jump to the image. This doesn't
matter at the moment since unmap_sysmem is a no-op.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
common/spl/spl.c
common/spl/spl_blk_fs.c
common/spl/spl_ext.c
common/spl/spl_fat.c
common/spl/spl_fit.c
common/spl/spl_imx_container.c
common/spl/spl_legacy.c
common/spl/spl_mmc.c
common/spl/spl_net.c
common/spl/spl_nor.c
common/spl/spl_spi.c

index 66eeea41a34be8358429ead3a0965a9d463cf7d8..732d90d39e6ccd20efbf0e7feb0f5272c6376e73 100644 (file)
@@ -653,7 +653,9 @@ void board_init_r(gd_t *dummy1, ulong dummy2)
        spl_set_bd();
 
        if (IS_ENABLED(CONFIG_SPL_SYS_MALLOC)) {
-               mem_malloc_init(SPL_SYS_MALLOC_START, SPL_SYS_MALLOC_SIZE);
+               mem_malloc_init((ulong)map_sysmem(SPL_SYS_MALLOC_START,
+                                                 SPL_SYS_MALLOC_SIZE),
+                               SPL_SYS_MALLOC_SIZE);
                gd->flags |= GD_FLG_FULL_MALLOC_INIT;
        }
        if (!(gd->flags & GD_FLG_SPL_INIT)) {
index ea5d1a51d9fcaa9cbe0d6152d85088c93253305d..63825d620d11a456f72503d52fd00b83c5d87bd7 100644 (file)
@@ -9,6 +9,7 @@
 #include <spl.h>
 #include <image.h>
 #include <fs.h>
+#include <asm/io.h>
 
 struct blk_dev {
        const char *ifname;
@@ -29,7 +30,8 @@ static ulong spl_fit_read(struct spl_load_info *load, ulong file_offset,
                return ret;
        }
 
-       ret = fs_read(load->filename, (ulong)buf, file_offset, size, &actlen);
+       ret = fs_read(load->filename, virt_to_phys(buf), file_offset, size,
+                     &actlen);
        if (ret < 0) {
                printf("spl: error reading image %s. Err - %d\n",
                       load->filename, ret);
@@ -69,7 +71,7 @@ int spl_blk_load_image(struct spl_image_info *spl_image,
                goto out;
        }
 
-       ret = fs_read(filename, (ulong)header, 0,
+       ret = fs_read(filename, virt_to_phys(header), 0,
                      sizeof(struct legacy_img_hdr), &actlen);
        if (ret) {
                printf("spl: unable to read file %s. Err - %d\n", filename,
index 902564a607763808275407967d4b0fb15961699c..af836ca15b8897de463db1ce442bc70f3d149366 100644 (file)
@@ -2,6 +2,7 @@
 
 #include <common.h>
 #include <env.h>
+#include <mapmem.h>
 #include <part.h>
 #include <spl.h>
 #include <asm/u-boot.h>
@@ -53,7 +54,8 @@ int spl_load_image_ext(struct spl_image_info *spl_image,
                goto end;
        }
 
-       err = ext4fs_read((char *)spl_image->load_addr, 0, filelen, &actlen);
+       err = ext4fs_read(map_sysmem(spl_image->load_addr, filelen), 0, filelen,
+                         &actlen);
 
 end:
 #ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
index b7b6a7794fd39d65ef7de2e0f0ac0ef3411be13e..014074f85be4e0dd0faf7731a44d898bfecd878c 100644 (file)
@@ -11,6 +11,7 @@
 #include <common.h>
 #include <env.h>
 #include <log.h>
+#include <mapmem.h>
 #include <spl.h>
 #include <asm/u-boot.h>
 #include <fat.h>
@@ -79,11 +80,13 @@ int spl_load_image_fat(struct spl_image_info *spl_image,
 
        if (IS_ENABLED(CONFIG_SPL_LOAD_FIT_FULL) &&
            image_get_magic(header) == FDT_MAGIC) {
-               err = file_fat_read(filename, (void *)CONFIG_SYS_LOAD_ADDR, 0);
+               err = file_fat_read(filename,
+                                   map_sysmem(CONFIG_SYS_LOAD_ADDR, 0), 0);
                if (err <= 0)
                        goto end;
                err = spl_parse_image_header(spl_image, bootdev,
-                               (struct legacy_img_hdr *)CONFIG_SYS_LOAD_ADDR);
+                                            map_sysmem(CONFIG_SYS_LOAD_ADDR,
+                                                       err));
                if (err == -EAGAIN)
                        return err;
                if (err == 0)
@@ -104,8 +107,8 @@ int spl_load_image_fat(struct spl_image_info *spl_image,
                if (err)
                        goto end;
 
-               err = file_fat_read(filename,
-                                   (u8 *)(uintptr_t)spl_image->load_addr, 0);
+               err = file_fat_read(filename, map_sysmem(spl_image->load_addr,
+                                                        spl_image->size), 0);
        }
 
 end:
index 32316d8baaca676d6112c47e9f42133abd485039..c026e1a194571e47c41417165e349ce6d41437ac 100644 (file)
@@ -16,6 +16,7 @@
 #include <sysinfo.h>
 #include <asm/cache.h>
 #include <asm/global_data.h>
+#include <asm/io.h>
 #include <linux/libfdt.h>
 #include <linux/printk.h>
 
@@ -393,25 +394,32 @@ static int spl_fit_append_fdt(struct spl_image_info *spl_image,
        /* Figure out which device tree the board wants to use */
        node = spl_fit_get_image_node(ctx, FIT_FDT_PROP, index++);
        if (node < 0) {
+               size_t size;
+
                debug("%s: cannot find FDT node\n", __func__);
 
                /*
                 * U-Boot did not find a device tree inside the FIT image. Use
                 * the U-Boot device tree instead.
                 */
-               if (gd->fdt_blob)
-                       memcpy((void *)image_info.load_addr, gd->fdt_blob,
-                              fdt_totalsize(gd->fdt_blob));
-               else
+               if (!gd->fdt_blob)
                        return node;
+
+               /*
+                * Make the load-address of the FDT available for the SPL
+                * framework
+                */
+               size = fdt_totalsize(gd->fdt_blob);
+               spl_image->fdt_addr = map_sysmem(image_info.load_addr, size);
+               memcpy(spl_image->fdt_addr, gd->fdt_blob, size);
        } else {
                ret = load_simple_fit(info, sector, ctx, node, &image_info);
                if (ret < 0)
                        return ret;
+
+               spl_image->fdt_addr = phys_to_virt(image_info.load_addr);
        }
 
-       /* Make the load-address of the FDT available for the SPL framework */
-       spl_image->fdt_addr = map_sysmem(image_info.load_addr, 0);
        if (CONFIG_IS_ENABLED(FIT_IMAGE_TINY))
                return 0;
 
@@ -876,7 +884,7 @@ int spl_load_fit_image(struct spl_image_info *spl_image,
 #ifdef CONFIG_SPL_FIT_SIGNATURE
        images.verify = 1;
 #endif
-       ret = fit_image_load(&images, (ulong)header,
+       ret = fit_image_load(&images, virt_to_phys((void *)header),
                             NULL, &fit_uname_config,
                             IH_ARCH_DEFAULT, IH_TYPE_STANDALONE, -1,
                             FIT_LOAD_OPTIONAL, &fw_data, &fw_len);
@@ -884,15 +892,15 @@ int spl_load_fit_image(struct spl_image_info *spl_image,
                printf("DEPRECATED: 'standalone = ' property.");
                printf("Please use either 'firmware =' or 'kernel ='\n");
        } else {
-               ret = fit_image_load(&images, (ulong)header, NULL,
-                                    &fit_uname_config, IH_ARCH_DEFAULT,
+               ret = fit_image_load(&images, virt_to_phys((void *)header),
+                                    NULL, &fit_uname_config, IH_ARCH_DEFAULT,
                                     IH_TYPE_FIRMWARE, -1, FIT_LOAD_OPTIONAL,
                                     &fw_data, &fw_len);
        }
 
        if (ret < 0) {
-               ret = fit_image_load(&images, (ulong)header, NULL,
-                                    &fit_uname_config, IH_ARCH_DEFAULT,
+               ret = fit_image_load(&images, virt_to_phys((void *)header),
+                                    NULL, &fit_uname_config, IH_ARCH_DEFAULT,
                                     IH_TYPE_KERNEL, -1, FIT_LOAD_OPTIONAL,
                                     &fw_data, &fw_len);
        }
@@ -914,9 +922,9 @@ int spl_load_fit_image(struct spl_image_info *spl_image,
 #ifdef CONFIG_SPL_FIT_SIGNATURE
        images.verify = 1;
 #endif
-       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);
+       ret = fit_image_load(&images, virt_to_phys((void *)header), NULL,
+                            &fit_uname_config, IH_ARCH_DEFAULT, IH_TYPE_FLATDT,
+                            -1, FIT_LOAD_OPTIONAL, &dt_data, &dt_len);
        if (ret >= 0) {
                spl_image->fdt_addr = (void *)dt_data;
 
index c29cb15f55e3adff0cded027426cb19e15126e0e..127802f5cb7769957a21876e39280ddd8c5b01be 100644 (file)
@@ -9,6 +9,7 @@
 #include <errno.h>
 #include <imx_container.h>
 #include <log.h>
+#include <mapmem.h>
 #include <spl.h>
 #ifdef CONFIG_AHAB_BOOT
 #include <asm/mach-imx/ahab.h>
@@ -46,7 +47,8 @@ static struct boot_img_t *read_auth_image(struct spl_image_info *spl_image,
        debug("%s: container: %p sector: %lu sectors: %u\n", __func__,
              container, sector, sectors);
        if (info->read(info, sector, sectors,
-                      (void *)images[image_index].dst) != sectors) {
+                      map_sysmem(images[image_index].dst,
+                                 images[image_index].size)) != sectors) {
                printf("%s wrong\n", __func__);
                return NULL;
        }
index e9564e5c2a5c60a149a9041f85f90b747b60fdac..51656fb96174274974e54144d7ae66234866a707 100644 (file)
@@ -7,6 +7,7 @@
 #include <image.h>
 #include <log.h>
 #include <malloc.h>
+#include <mapmem.h>
 #include <asm/sections.h>
 #include <spl.h>
 
@@ -129,7 +130,7 @@ int spl_load_legacy_img(struct spl_image_info *spl_image,
                        dataptr += sizeof(*hdr);
 
                load->read(load, dataptr, spl_image->size,
-                          (void *)(unsigned long)spl_image->load_addr);
+                          map_sysmem(spl_image->load_addr, spl_image->size));
                break;
 
        case IH_COMP_LZMA:
@@ -148,7 +149,8 @@ int spl_load_legacy_img(struct spl_image_info *spl_image,
                }
 
                load->read(load, dataptr, spl_image->size, src);
-               ret = lzmaBuffToBuffDecompress((void *)spl_image->load_addr,
+               ret = lzmaBuffToBuffDecompress(map_sysmem(spl_image->load_addr,
+                                                         spl_image->size),
                                               &lzma_len, src, spl_image->size);
                if (ret) {
                        printf("LZMA decompression error: %d\n", ret);
index 03a081fa47e042c1cfee00e53adf947ed70aa903..0b01368d9deab88cc217a1cf652c5c7cf6ba03cb 100644 (file)
@@ -8,6 +8,7 @@
 #include <common.h>
 #include <dm.h>
 #include <log.h>
+#include <mapmem.h>
 #include <part.h>
 #include <spl.h>
 #include <linux/compiler.h>
@@ -46,7 +47,8 @@ static int mmc_load_legacy(struct spl_image_info *spl_image,
        count = blk_dread(mmc_get_blk_desc(mmc),
                          sector + image_offset_sectors,
                          image_size_sectors,
-                         (void *)(ulong)spl_image->load_addr);
+                         map_sysmem(spl_image->load_addr,
+                                    image_size_sectors * mmc->read_bl_len));
        debug("read %x sectors to %lx\n", image_size_sectors,
              spl_image->load_addr);
        if (count != image_size_sectors)
index b2c901b554b81fa02cebd0f897af221782311700..f01d4df8bc664e4150dba6cf6a0b1615b68019a9 100644 (file)
@@ -11,6 +11,7 @@
 #include <errno.h>
 #include <image.h>
 #include <log.h>
+#include <mapmem.h>
 #include <spl.h>
 #include <net.h>
 #include <linux/libfdt.h>
@@ -21,14 +22,15 @@ static ulong spl_net_load_read(struct spl_load_info *load, ulong sector,
 {
        debug("%s: sector %lx, count %lx, buf %lx\n",
              __func__, sector, count, (ulong)buf);
-       memcpy(buf, (void *)(image_load_addr + sector), count);
+       memcpy(buf, map_sysmem(image_load_addr + sector, count), count);
        return count;
 }
 
 static int spl_net_load_image(struct spl_image_info *spl_image,
                              struct spl_boot_device *bootdev)
 {
-       struct legacy_img_hdr *header = (struct legacy_img_hdr *)image_load_addr;
+       struct legacy_img_hdr *header = map_sysmem(image_load_addr,
+                                                  sizeof(*header));
        int rv;
 
        env_init();
@@ -62,7 +64,9 @@ static int spl_net_load_image(struct spl_image_info *spl_image,
                if (rv)
                        return rv;
 
-               memcpy((void *)spl_image->load_addr, header, spl_image->size);
+               memcpy(map_sysmem(spl_image->load_addr, spl_image->size),
+                      map_sysmem(image_load_addr, spl_image->size),
+                      spl_image->size);
        }
 
        return rv;
index dd44798207185c750d2ca67b8c650d8226faa123..236b07182833a88a150823f8cfd1ab4dd93ce3bb 100644 (file)
@@ -7,6 +7,7 @@
 #include <image.h>
 #include <imx_container.h>
 #include <log.h>
+#include <mapmem.h>
 #include <spl.h>
 
 static ulong spl_nor_load_read(struct spl_load_info *load, ulong sector,
@@ -14,7 +15,7 @@ static ulong spl_nor_load_read(struct spl_load_info *load, ulong sector,
 {
        debug("%s: sector %lx, count %lx, buf %p\n",
              __func__, sector, count, buf);
-       memcpy(buf, (void *)sector, count);
+       memcpy(buf, map_sysmem(sector, count), count);
 
        return count;
 }
@@ -92,7 +93,7 @@ static int spl_nor_load_image(struct spl_image_info *spl_image,
         * Load real U-Boot from its location in NOR flash to its
         * defined location in SDRAM
         */
-       header = (const struct legacy_img_hdr *)spl_nor_get_uboot_base();
+       header = map_sysmem(spl_nor_get_uboot_base(), sizeof(*header));
 #ifdef CONFIG_SPL_LOAD_FIT
        if (image_get_magic(header) == FDT_MAGIC) {
                debug("Found FIT format U-Boot\n");
index 1427c9478c0ec0dd32fa6c3d833936b50f3198ed..3ac4b1b5091c42d9e2b9b6563a3e67474f91522c 100644 (file)
 #include <image.h>
 #include <imx_container.h>
 #include <log.h>
+#include <mapmem.h>
 #include <spi.h>
 #include <spi_flash.h>
 #include <errno.h>
 #include <spl.h>
 #include <asm/global_data.h>
+#include <asm/io.h>
 #include <dm/ofnode.h>
 
 #if CONFIG_IS_ENABLED(OS_BOOT)
@@ -134,13 +136,16 @@ static int spl_spi_load_image(struct spl_image_info *spl_image,
 
                if (IS_ENABLED(CONFIG_SPL_LOAD_FIT_FULL) &&
                    image_get_magic(header) == FDT_MAGIC) {
+                       u32 size = roundup(fdt_totalsize(header), 4);
+
                        err = spi_flash_read(flash, payload_offs,
-                                            roundup(fdt_totalsize(header), 4),
-                                            (void *)CONFIG_SYS_LOAD_ADDR);
+                                            size,
+                                            map_sysmem(CONFIG_SYS_LOAD_ADDR,
+                                                       size));
                        if (err)
                                return err;
                        err = spl_parse_image_header(spl_image, bootdev,
-                                       (struct legacy_img_hdr *)CONFIG_SYS_LOAD_ADDR);
+                                       phys_to_virt(CONFIG_SYS_LOAD_ADDR));
                } else if (IS_ENABLED(CONFIG_SPL_LOAD_FIT) &&
                           image_get_magic(header) == FDT_MAGIC) {
                        struct spl_load_info load;
@@ -172,7 +177,8 @@ static int spl_spi_load_image(struct spl_image_info *spl_image,
                                return err;
                        err = spi_flash_read(flash, payload_offs + spl_image->offset,
                                             spl_image->size,
-                                            (void *)spl_image->load_addr);
+                                            map_sysmem(spl_image->load_addr,
+                                                       spl_image->size));
                }
                if (IS_ENABLED(CONFIG_SPI_FLASH_SOFT_RESET)) {
                        err = spi_nor_remove(flash);