1

First of all, I must apologize for the conduct and outcome of the topic below. I discovered that the issue was also in U-boot and changes in device-tree (kernel part) were not essential in solving the issue.

This is so true that currently, not even technexion's U-boot 2021.04 pulling directly from github is working without the error mentioned above.

Reading file would overwrite reserved memory. Failed to load 'hello_world.bin

I have imx7d-pico with Carrier board. This tiny computer was used a lot for Android Things. PDF (datasheet) easily found.

With that said, here's the chronology of events:

In April 2022 I customized U-boot 2021.04 from technexion and such uboot works without the error: Reading file would overwrite reserved memory

In April 2023 I customized again U-boot 2021.04 and U-boot 2022.04 from technexion and such uboot DOES NOT work anymore. I have issue: Reading file would overwrite reserved memory ** Failed to load 'hello_world.bin', When I try fatload mmc 0:1 0x7F8000 hello_world.bin

I put '#define LOG_DEBUG' to the top of lmb.c and I see some debugging about the reserved memory:

lmb.c when RPMsg work: https://gist.github.com/neuberfran/c4df18a27974cd6fdc8a967f192d54d6

lmb.c when RPMsg not Work: https://gist.github.com/neuberfran/aebbac2db52c5f78c680f10496cb8784

printenv result U-boot 2021.04 to imx7d-pico When RPMsg not work https://gist.github.com/neuberfran/f07e3d2d83c0f311bdebbf4c12646df8

I made some changes in the uboot/device tree and kernel/device tree of imx7d-pico but it still didn't work.

How can I solve my issue?

enter image description here

vvv444
  • 2,764
  • 1
  • 14
  • 25
neuberfran
  • 359
  • 3
  • 18
  • 1
    Where in memory are you loading this **hello_world.bin** program? What is the definition for CONFIG_STANDALONE_LOAD_ADDR in your build? – sawdust Apr 25 '23 at 23:12
  • @sawdust I create a gists file (More important files) with platform_info.c and linkers that answer your first question(answer: 0x9FFF0000)https://gist.github.com/neuberfran/f4c6aa10fa3c4f0c9e6bea83f359953d Regarding the second question, I (for now) only have this. i am looking for CONFIG_LOADADDR value yet #define CONFIG_SYS_LOAD_ADDR CONFIG_LOADADDR – neuberfran Apr 26 '23 at 01:28
  • @sawdust I edited my question and put it: fatload mmc 0:1 0x7F8000 hello_world.bin I imagine that in my case the value of CONFIG_STANDALONE_LOAD_ADDR is 0xc100000 due to the config.mk that is in the root of my U-boot 2021.04 (which still doesn't work) https://gist.github.com/neuberfran/a312e04a12f87ef4bfa06fb52b0fd77e https://stackoverflow.com/questions/65732440/how-to-get-into-xilinx-zcu102-u-boot-prompt – neuberfran Apr 26 '23 at 22:39
  • "*I imagine that ...*" -- Not interested in your guesses. What is the U-Boot environment that produces all these console messages??? What is the significance of that link to an SO question? What is the origin of the **hello_world.bin** program that you're trying to load and execute? Why am I generating more questions than getting answers? – sawdust Apr 27 '23 at 04:55
  • @sawdust The SO question in the above link talk about CONFIG_STANDALONE_LOAD_ADDR About hello_world.bin: https://github.com/neuberfran/freertos-tn/tree/main/examples/imx7d_pico_m4/demo_apps/hello_world/armgcc/release I ask for patience. I'm producing the rest of the answers. Always letting you know I have a custom version of Uboot 2021.04 here that works. I already did git diff branch_wrong..branch_correct > dif.diff and made changes still without solving my issue. – neuberfran Apr 27 '23 at 14:07
  • The U-Boot environment that you provided does not match the console output "*when RPMsg not Work*". Between the messages `Booting from mmc ...` and `baseboard is ${baseboard}`, the only load command is in **m4boot** for the **m4_tcm.bin** file to 0x7F8000. **There is no reference whatsoever to any hello_world.bin in that U-Boot environment**. So how did you produce that console log??? BTW the load of **m4_tcm.bin** will always fail because RAM starts at 0x80000000, so 0x7F8000 is an address where there is no memory. – sawdust Apr 27 '23 at 21:31
  • @sawdust Sorry about my last gists with printenv I made the correction. I've been doing a few tries and I posted the wrong printenv. You said: "RAM starts at 0x80000000, so 0x7F8000 is an address where there is no memory." How to solve it? – neuberfran Apr 27 '23 at 21:47
  • @sawdust About your last post above where you talk about hello_world.bin/app/github/FreeRTOS it is not the problem for now. Well, as I said, I have a U-boot 2021.04 here (customized by me in Apbril/22) that works with RPMsg. If you pull technexion's U-boot 2021.04 today, you'll see that it has a lot of changes. Some I already customized, like: emmc now the default is 2 and in the old U-boot 2021.04, it was emmc 0. But, RPMsg still doesn't work here and I'm customizing – neuberfran Apr 27 '23 at 21:53
  • @sawdust Without this command (fatload mmc 0:1 0x7F8000 hello_world.bin, and the 2 subsequent ones: dcache flush and bootaux 0x7F8000) I won't be able to upload the module (modprobe imx_rpmsg_pingpong) in userspace. The error that happens with hello_world.bin, also happens with rpmsg_pingpong_freertos_example.bin: https://github.com/neuberfran/freertos-tn/tree/main/examples/imx7d_pico_m4/demo_apps/rpmsg/pingpong_freertos/armgcc/release – neuberfran Apr 27 '23 at 23:18
  • @sawdust About RPMsg this is the best link I rely on for my imx7d-pico: https://imxdev.gitlab.io/tutorial/Multicore_communication_on_WaRP7_using_Remote_Processor_Messaging_bus_(RPMsg)/ – neuberfran Apr 27 '23 at 23:29
  • Apparently U-Boot has evolved to become more strict on where files can be loaded (maybe to help detect mistakes?). The dumps of the LMB structure clearly indicate that only main memory is accessible to U-Boot. So the address space to access the aux processor memory also has to be defined so that U-Boot will allow writing. Try hacking *only* U-Boot's DT to include the 0x7F8000 region as another segment of ordinary memory (rather than part of a device as in the kernel's DT). – sawdust Apr 28 '23 at 04:36
  • @sawdust "Try hacking only U-Boot's DT to include the 0x7F8000 region". Yes, I've already done this based on the ST links below. Still unsuccessful. Really the U-boot must have changed. I need to know exactly where it changed. https://community.st.com/s/question/0D53W00001DMfdlSAD/what-parts-of-the-ddr-can-i-reserve-using-device-tree-without-upsetting-uboot https://community.st.com/s/question/0D53W00001IATDeSAP/issue-in-accessing-ram-address-in-stm32mp1-series-board https://community.st.com/s/question/0D53W000005pokESAQ/reserved-memory-region-for-m4-in-ddr – neuberfran Apr 28 '23 at 13:23
  • I have evolutions after putting debug points in the fs.c file that is in /u-boot-technexion/u-boot-tn-imx/fs/fs.c. So much on U-boot 2021.04 that works so much on what doesn't. Note.: imx7d-pico has no native debug points. Links:- fs.c (Result) when RPMsg work https://gist.github.com/neuberfran/3a344085e1fbd447e7ccf87cba35e823 fs.c (Result) when RPMsg Not work https://gist.github.com/neuberfran/d5042b1b0096e927d165af9d1cc13ca1 – neuberfran Apr 28 '23 at 20:59
  • fs.c https://gist.github.com/neuberfran/a827cf9e83bc283689d40b0de54b0ef2 – neuberfran Apr 28 '23 at 21:44

1 Answers1

1

I have imx7d-pico with Carrier board.
...
I have issue: Reading file would overwrite reserved memory ** Failed to load 'hello_world.bin,

Your use of an SoC that has both a microprocessor and an auxiliary microcontroller with shared memory is a salient point. Refer to the NXP Appnote (esp. Table 5) for details. The use of multiple memory address ranges probably makes your problem a boundary case that U-Boot developers may have overlooked.

Apparently U-Boot has evolved to become more strict on where files can be loaded in address space (probably to help detect mistakes). The dumps of the LMB structure clearly indicate that only main memory, 0x80000000 to 0xbfffffff, is accessible to certain U-Boot commands. Since the address space to access the auxiliary processor memory (0x7f8000 to 0x7fffff) is outside this range of main memory, this auxiliary memory region is unwritable by various load-a-file commands.

The root cause of the error message is in the Logical Memory Block "library" of U-Boot, lib/lmb.c. The procedure lmb_init_and_reserve() only allocates the available (and hence loadable) memory space(s) based on U-Boot's legacy method for memory definition.

The legacy method relies on macro definitions, such as CFG_SYS_SDRAM_BASE, and are typically defined in a board-specific header file. For example the following definitions are extracted from include/configs/imx7-cm.h:

#define CFG_SYS_SDRAM_BASE      PHYS_SDRAM
#define CFG_SYS_INIT_RAM_ADDR   IRAM_BASE_ADDR
#define CFG_SYS_INIT_RAM_SIZE   IRAM_SIZE

Then in common/board_f.c, the base address for SDRAM is assigned to a global_data variable for the base address of RAM used by U-Boot:

static int setup_dest_addr(void)
{
    ...
    gd->ram_base = CFG_SYS_SDRAM_BASE;

Later the first memory bank of the board info structure is filled with this global_data memory info in common/board_f.c:

__weak int dram_init_banksize(void)
{
    gd->bd->bi_dram[0].start = gd->ram_base;
    gd->bd->bi_dram[0].size = get_effective_memsize();

    return 0;
}

That is the board memory info that is later used to fill-in the LMB structure in lib/lmb.c:

/* Initialize the struct, add memory and call arch/board reserve functions */
void lmb_init_and_reserve(struct lmb *lmb, struct bd_info *bd, void *fdt_blob)
{
    int i;

    lmb_init(lmb);

    for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
        if (bd->bi_dram[i].size) {
            lmb_add(lmb, bd->bi_dram[i].start,
                bd->bi_dram[i].size);
        }
    }

    lmb_reserve_common(lmb, fdt_blob);
}

So the Logical Memory Block "library" relies on U-Boot's legacy method for defining memory.
That means the memory definitions in the Device Tree are ignored by U-Boot.


When you try to load a file from a storage device to memory, the following procedure is called in fs/fs.c

#ifdef CONFIG_LMB
/* Check if a file may be read to the given address */
static int fs_read_lmb_check(const char *filename, ulong addr, loff_t offset,
                 loff_t len, struct fstype_info *info)
{
    ...
    lmb_init_and_reserve(&lmb, gd->bd, (void *)gd->fdt_blob);
    lmb_dump_all(&lmb);

    if (lmb_alloc_addr(&lmb, addr, read_len) == addr)
        return 0;

    log_err("** Reading file would overwrite reserved memory **\n");
    return -ENOSPC;
}
#endif

Note the conditional compilation for this routine that performs the memory check.
I tied to build a version of U-Boot 2022.01 without CONFIG_LMB, but the build failed. So even though CONFIG_LMB appears to be an optional library selection in the menuconfig, there seems to be source code changes needed to de-select CONFIG_LMB.
So you cannot try to bypass this memory check by building an alternate configuration of U-Boot.



A Workaround

Rather than try to define the aux memory as a bank of main memory, there is a simple & easy workaround to use a recent & unmodified U-Boot in your situation. Instead of loading the file directly to the auxiliary processor memory, simply load the file to main memory at 0x80008000, and then perform a copy of 32KB to the aux memory at tcm_addr.
The loadm4image variable should be changed to:

loadm4image=fatload mmc ${mmcdev}:${mmcpart} 80008000 ${m4image}; \
cp.b 80008000 ${tcm_addr} 8000

This can be accomplished with the following command to the previously posted environment:

setenv loadm4image 'fatload mmc ${mmcdev}:${mmcpart} 80008000 ${m4image}; cp.b 80008000 ${tcm_addr} 8000'
sawdust
  • 16,103
  • 3
  • 40
  • 50
  • Please edit your answer. The imx7-cm.h file does not exist in include/configs/. Not elsewhere here. – neuberfran May 01 '23 at 12:10
  • in U-boot 2022.04 Solved. But kernel Not Start: https://gist.github.com/neuberfran/2c8c7ef997935a604216bc90c0248c4d in U-boot 2021.04 Solved & Kernel Start Ok! https://gist.github.com/neuberfran/8fb0ef30754b80d9d27627a7a75a9b0f – neuberfran May 01 '23 at 13:06
  • Mention of **imx7-cm.h** is solely for informational purpose. "*But kernel Not Start: ...*" -- This answer is only concerned with the single U-Boot problem stated in your title. The size of the loaded kernel image clearly indicates that you're now using a ***different kernel image*** than before. That different kernel image probably also fails without the workaround, so the workaround would not be the cause of boot hang. So that's a new and different problem that needs a new post. **Don't try to add new problems/questions to your post!** – sawdust May 01 '23 at 23:46
  • Why would I try to create new problems/questions to my post? – neuberfran May 02 '23 at 13:37
  • "That different kernel image probably also fails without the workaround, so the workaround would not be the cause of boot hang". No. Prior to the workaround, the kernel was starting normally(Using U-boot 2022.04 by technexion) – neuberfran May 02 '23 at 13:40
  • U-boot 2022.04 without A Workaround When Kernel Start`s Ok: https://gist.github.com/neuberfran/af03d43250a3df297d2aaefd14da2c69 – neuberfran May 02 '23 at 14:07
  • "*U-boot 2022.04 without A Workaround When Kernel Start`s Ok:*" -- Another apples to oranges comparison! Maybe the kernel images are the same (same length anyway). But the **Device Tree blobs** are different!!! Bogus comparison!!! Don't tell me "*no*" when you haven't provided a convincing case. – sawdust May 02 '23 at 22:45
  • https://postimg.cc/7GNR7Jxw This line is important to the kernel not start issue when using U-boot 2022.04: Kernel image @ 0x80800000 [ 0x000000 - 0x902088 ]. Note.: Your answer convinced me yes. I will choose your answer. But, I tell you that I didn't change anything in the device tree (I just made the changes that you proposed in U-boot 2022.04) and, with those changes, the kernel is not uploading. – neuberfran May 03 '23 at 00:12
  • Do you have anything else to say about my last issue which is the kernel not booting in U-boot 2022.04 after modifications? – neuberfran May 03 '23 at 13:48
  • No, I don't. The file lengths reported by the load operations clearly indicate different files are being loaded for booting. You claim you "*didn't change anything*", but the various boot logs clearly show different files are being loaded. You cannot demonstrate that there is a problem when there are multiple variations in the comparison. – sawdust May 03 '23 at 23:57
  • https://www.youtube.com/watch?v=2VZWySnnd3Y – neuberfran May 05 '23 at 23:11