Cannot find linker script file

I am using a custom board (i have divided memory into high and low, each one is defined as a board) but when i build it does not find the linker script

The .json file:

"build": {
    "core": "arduino",
    "cpu": "cortex-m3",
    "extra_flags": "-D__SAM3X8E__ -DARDUINO_ARCH_SAM -DARDUINO_SAM_DUE",
    "f_cpu": "84000000L",
    "hwids": [
      [
        "0x2341",
        "0x003E"
      ],
      [
        "0x2341",
        "0x003D"
      ],
      [
        "0x2A03",
        "0x003D"
      ]
    ],
    "ldscript": "flash_low.ld",
    "mcu": "at91sam3x8e",
    "usb_product": "Arduino Due",
    "variant": "arduino_due_x"
  },
  "connectivity": [
    "can"
  ],
  "debug": {
    "jlink_device": "ATSAM3X8E",
    "openocd_chipname": "at91sam3X8E",
    "openocd_target": "at91sam3XXX",
    "svd_path": "ATSAM3X8E.svd"
  },
  "frameworks": [
    "arduino",
    "simba"
  ],
  "name": "Arduino Due (Low Bootloader)",
  "upload": {
    "disable_flushing": true,
    "maximum_ram_size": 98304,
    "maximum_size": 524288,
    "native_usb": false,
    "protocol": "sam-ba",
    "protocols": [
      "sam-ba",
      "jlink",
      "blackmagic",
      "atmel-ice",
      "stlink"
    ],
    "require_upload_port": true,
    "use_1200bps_touch": true,
    "wait_for_upload_port": false
  },
  "url": "https://www.arduino.cc/en/Main/ArduinoBoardDue",
  "vendor": "Arduino"
}

I added the board to the .platformio/packages/framework-arduino-same/boards.txt file:

arduino_due_xhb.name=Arduino Due (Low bootloader)
arduino_due_xhb.vid.0=0x2341
arduino_due_xhb.pid.0=0x003e
arduino_due_xhb.vid.1=0x2A03
arduino_due_xhb.pid.1=0x003e
arduino_due_xhb.upload.tool=bossac
arduino_due_xhb.upload.protocol=sam-ba
arduino_due_xhb.upload.maximum_size=262144
arduino_due_xhb.upload.use_1200bps_touch=true_xhb.upload.tool=bossac
arduino_due_xhb.upload.protocol=sam-ba
arduino_due_xhb.upload.maximum_size=262144
arduino_due_xhb.upload.use_1200bps_touch=true
arduino_due_xhb.upload.wait_for_upload_port=true
arduino_due_xhb.upload.native_usb=true
arduino_due_xhb.build.mcu=cortex-m3
arduino_due_xhb.build.f_cpu=84000000L
arduino_due_xhb.build.usb_manufacturer="Arduino LLC"
arduino_due_xhb.build.usb_product="Arduino Due"
arduino_due_xhb.build.board=SAM_DUE
arduino_due_xhb.build.core=arduino
arduino_due_xhb.build.extra_flags=-D__SAM3X8E__ -mthumb {build.usb_flags}
arduino_due_xhb.build.ldscript=linker_scripts/gcc/flash_low.ld
arduino_due_xhb.build.variant=arduino_due_x
arduino_due_xhb.build.variant_system_lib=libsam_sam3x8e_gcc_rel.a
arduino_due_xhb.build.vid=0x2341
arduino_due_xhb.build.pid=0x003e

Made the necessary modifications and copied flash_low.ld to ~/.platformio/packages/framework-arduinosam/variants/arduino_due_x/linker_scripts/gcc

Where could it be looking for the ld script?

The original board file gives this in a different construct, not in the “build” object directly

Does the error go away when you use it like that with the value flash_low.ld?

Also, with the project task “Advanced → Verbose Build” you can get every compiler invocation. The last invocation should be the linker invocation with -o [..] firmware.elf. This command has a bunch of -L switches to add paths to the library search paths and a -T flag that gives the linker script. The linker will only find the linker script if it’s within one of the -L paths it was informed about. What does the linker command look like in full?

Any modifications to this file is completely ignored, PlatformIO does not read information from Arduino’s board.txt file. It sources its information from the board JSON files and the rest is done in the builder script logic (e.g. here).

1 Like

Indeed it needed to be inside arduino construct. I ran the Advanceed verbose build but i could’nt see those paths.

Thank you again for helping the newbie get the project running :slight_smile:

Actually this is really bad for portability onto another computer too – you shouldn’t modify framework packages.

The builder scripts give you the opportunity to specify a custom locations for the variants folder.

Meaning you can copy just the ~/.platformio/packages/framework-arduinosam/variants/arduino_due_x/ folder into the project that uses it under e.g. custom_variants/arduino_due_x and then just set

board_build.variants_dir = custom_variants

in the platformio.ini to make the builder script use it.

Then no modification of framework files is needed and the project is 100% portable (if you only added / changed variant files – though even for changed framework files you can use platform_packages).

So i define it in platformio.ini and run the builder script to create the proper folders?

No, you just move / copy the variant folder and put the info for that path into the platformio.ini. The builder script (arduino-sam.py) is automatically invoked by PlatformIO every time you build the project, you don’t have to explicitly call it. Also it just uses the information that you have configured in the platformio.ini, it doesn’t create the variant folder by itself.

1 Like