CONFIG_CUSTOM_LINKER_SCRIPT in prj.conf not working.

Summary:
If I add these two lines to my prj.conf the system will no longer build. Any ideas on what I’m doing wrong? Any help would be appreciated.

CONFIG_HAVE_CUSTOM_LINKER_SCRIPT=y
CONFIG_CUSTOM_LINKER_SCRIPT="linker.cmd"

Details:
Without those two lines I can build the supplied cli sample from the nordic SDK and build it fine. It runs fine too. With a now populated cli/build directory if I then do the following commands:

$ cd cli
$ cp  build/zephyr/linker.cmd linker.cmd
$ rm build/zephyr/linker.cmd

… and then add the two lines to my prj.conf files you would think I’d get the same exact build as before since all I did is relocate the same linker.cmd and add the reference in prj.conf. But in fact the build will fail the link step. Any ideas on what I’m doing wrong? Any help would be appreciated.

Misc:
nrf sample project = cli
board: nrf52840-DK
SDK: nrf v2.4.1
Machine: MacBook Pro with Ventura 13.4.1

Error Transcript:
[381/386] Generating linker.cmd
[382/386] Generating isr_tables.c, isrList.bin
FAILED: zephyr/isr_tables.c zephyr/isrList.bin
cd /Users/Kranz/puzl/nrf/nordic_puzl_thread/build/zephyr && /opt/nordic/ncs/toolchains/4ef6631da0/opt/zephyr-sdk/arm-zephyr-eabi/bin/arm-zephyr-eabi-objcopy --input-target=elf32-littlearm --output-target=binary --only-section=.intList /Users/Kranz/puzl/nrf/nordic_puzl_thread/build/zephyr/zephyr_pre1.elf isrList.bin && /opt/nordic/ncs/toolchains/4ef6631da0/opt/[email protected]/bin/python3.9 /opt/nordic/ncs/v2.4.1/zephyr/scripts/build/gen_isr_tables.py --output-source isr_tables.c --kernel /Users/Kranz/puzl/nrf/nordic_puzl_thread/build/zephyr/zephyr_pre1.elf --intlist isrList.bin --sw-isr-table --vector-table
Traceback (most recent call last):
  File "/opt/nordic/ncs/v2.4.1/zephyr/scripts/build/gen_isr_tables.py", line 359, in <module>
    main()
  File "/opt/nordic/ncs/v2.4.1/zephyr/scripts/build/gen_isr_tables.py", line 261, in main
    intlist = read_intlist(args.intlist, syms)
  File "/opt/nordic/ncs/v2.4.1/zephyr/scripts/build/gen_isr_tables.py", line 82, in read_intlist
    header = struct.unpack_from(intlist_header_fmt, intdata, 0)
struct.error: unpack_from requires a buffer of at least 8 bytes for unpacking 8 bytes at offset 0 (actual buffer size is 0)
ninja: build stopped: subcommand failed.
FATAL ERROR: command exited with status 1: /opt/nordic/ncs/toolchains/4ef6631da0/bin/cmake --build /Users/Kranz/puzl/nrf/nordic_puzl_thread/build

Thanks in advance,
Steve K, PuzL Labs, LLC

Parents Reply Children
  • What you are trying to do wont' work. You are trying to use a file which has all the generated sections in, the custom linker file is for additional parts, not the base file itself, you cannot replace the whole file, it would duplicate all entries.

    It needs to be a .ld file e.g.
    https://github.com/zephyrproject-rtos/zephyr/blob/main/samples/application_development/code_relocation_nocopy/linker_arm_nocopy.ld 

    Kenneth

  • Hi Kenneth,

    Thank you for your reply. Hmmm, I’d like to offer some additional info; it might be that I’m heading in a more complicated direction than needed. I simply want to reserve the first 0x100 bytes of RAM so they are not assigned by the link process. By default the link step will assume the following (as directed by build/zephyr/linker.cmd):

    RAM (wx) : ORIGIN = 0x20000000, LENGTH = (256 * 1K)

    … and I simply want the following instead:

    RAM (wx) : ORIGIN = 0x20000100, LENGTH = ((256 * 1K) - 0x100)

    How would you approach that? Again, I’m am very new to Nordic and have a lot that I’ve been ramping up on. I have to say it has been going well, but I naturally welcome any insights that will more quickly get me over the hurdles. Thanks in advance!

    Steve K.
    PuzL Labs, LLC

  • Hi Kenneth,

    Summary:
    As I looked more at your response I clued into the fact that Nordic offers a sample  for using a *.ld (code_relocation_nocopy). I studied it and made an attempt at my own linker.ld (for my Nordic CLI sample). But something still looks fishy and I wonder if you could review?

    Details:
    I added the following lines to my prj.conf:

    CONFIG_HAVE_CUSTOM_LINKER_SCRIPT=y
    CONFIG_CUSTOM_LINKER_SCRIPT="linker.ld"

    I created a linker.ld file and placed it in my cli proj root directory. This file:

    $ cd cli
    $ cat linker.ld
    #include <zephyr/linker/sections.h>
    #include <zephyr/devicetree.h>
    #include <zephyr/linker/linker-defs.h>
    #include <zephyr/linker/linker-tool.h>
    MEMORY
    {
         RAM (wx) : ORIGIN = 0x20000100, LENGTH = ((256 * 1K) - 0x100)
    }
    #include <zephyr/arch/arm/aarch32/cortex_m/scripts/linker.ld>

    I performed a prestine build, and it built, but then I glanced at the the derived *.cmd file and noticed two lines where I think I might have expected only 1. Does this look normal?

    $ head -n15 ./build/zephyr/linker.cmd
     OUTPUT_FORMAT("elf32-littlearm")
    MEMORY
    {
         RAM (wx) : ORIGIN = 0x20000100, LENGTH = ((256 * 1K) - 0x100)
    }
    _region_min_align = 32;
    MEMORY
        {
        FLASH (rx) : ORIGIN = (0x0 + 0x0), LENGTH = (1024*1K - 0x0)
        RAM (wx) : ORIGIN = 0x20000000, LENGTH = (256 * 1K)
       
        IDT_LIST (wx) : ORIGIN = 0xFFFFF7FF, LENGTH = 2K
        }
    ENTRY("__start")
    SECTIONS
    ...<snip for brevity>...


    Thanks,
    Steve K.
    PuzL Labs, LLC

  • Hi Kenneth,

    Did you happen to see that last reply I sent you (around Aug 18th)?

    Steve K. PuzL Labs, LLC

  • Hi Steve,

    I believe a more straightforward way to reserve the first 256 bytes in RAM is to offset the start address of the sram0 node in the devicetree by 0x100. You can achieve this by creating a board overlay file.

    For example, for the nrf52840dk_nrf52840 board, the overlay file would look like this:

    nrf52840dk_nrf52840.overlay

    &sram0 {
        reg = < 0x20000100 (DT_SIZE_K(256)-0x100)>;
    };

    The overlay can be placed in the project root. It will be picked up by the build system after a pristine build.

    Best regards,

    Vidar

Related