Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix loading platforms with malformed boards.txt #1326

Merged
merged 7 commits into from
Jun 18, 2021

Conversation

silvanocerza
Copy link
Contributor

Please check if the PR fulfills these requirements

  • The PR has no duplicates (please search among the Pull Requests
    before creating one)
  • The PR follows
    our contributing guidelines
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)
  • UPGRADING.md has been updated with a migration guide (for breaking changes)
  • What kind of change does this PR introduce?

Makes the CLI more resilient by avoiding loading boards not respecting the specification.

  • What is the current behavior?

Boards that specify a custom option like this:

duemilanove.menu.cpu.atmega328=ATmega328P
duemilanove.menu.cpu.atmega168=ATmega168

are always loaded, even if the option menu.cpu is not defined anywhere else in boards.txt file.
This may cause issues and crashes for other commands that expect this menu.cpu property to exist like the specification states.

We must first define a set of menu.MENU_ID=Text properties. Text is what is displayed on the GUI for every
custom menu we are going to create and must be declared at the beginning of the boards.txt file:

menu.cpu=Processor
[.....]

From https://arduino.github.io/arduino-cli/dev/platform-specification/#custom-board-options

This is an example of the problems the missing option definition may cause:

$ ./arduino-cli core install --additional-urls https://raw.githubusercontent.com/sparkfun/Arduino_Boards/master/IDE_Board_Manager/package_sparkfun_index.json SparkFun:[email protected]

...

$ ./arduino-cli board details SparkFun:samd:samd51_thing_plus
panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xc0000005 code=0x0 addr=0x0 pc=0x8bb167]

goroutine 1 [running]:
github.com/arduino/go-properties-orderedmap.(*Map).Get(...)
        /go/pkg/mod/github.com/arduino/[email protected]/properties.go:223
github.com/arduino/arduino-cli/arduino/cores.(*Board).GetConfigOptions(0xc000bf7480, 0xc00051a3d8)
        /home/build/arduino/cores/board.go:72 +0x107
github.com/arduino/arduino-cli/commands/board.Details(0x12012a0, 0xc00002c140, 0xc0008fbd50, 0xb, 0xb, 0xa)
        /home/build/commands/board/details.go:94 +0xa1b
github.com/arduino/arduino-cli/cli/board.runDetailsCommand(0xc0008b82c0, 0xc0008075a0, 0x1, 0x1)
        /home/build/cli/board/details.go:69 +0x125
github.com/spf13/cobra.(*Command).execute(0xc0008b82c0, 0xc000807580, 0x1, 0x1, 0xc0008b82c0, 0xc000807580)
        /go/pkg/mod/github.com/spf13/[email protected]/command.go:846 +0x2a4
github.com/spf13/cobra.(*Command).ExecuteC(0xc0001318c0, 0x41, 0xc0006cb8c0, 0xc0006e0820)
        /go/pkg/mod/github.com/spf13/[email protected]/command.go:950 +0x350
github.com/spf13/cobra.(*Command).Execute(...)
        /go/pkg/mod/github.com/spf13/[email protected]/command.go:887
main.main()
        /home/build/main.go:31 +0x8c

The SparkFun:samd:samd51_thing_plus board in this case defines the following options:

samd51_thing_plus.menu.cache.on=Enabled
samd51_thing_plus.menu.cache.on.build.cache_flags=-DENABLE_CACHE
samd51_thing_plus.menu.cache.off=Disabled
samd51_thing_plus.menu.cache.off.build.cache_flags=

But menu.cache is not defined anywhere in the boards.txt.

  • What is the new behavior?

Boards that define a custom option like stated above won't be loaded anymore if the related menu.MENU_ID=Text is not defined anywhere in the boards.txt.

A warning will be displayed to the user reminding them that the boards are not loaded. The platform will still be loaded correctly.

$ arduino-cli core list
Error initializing instance: loading platform release SparkFun:[email protected]: loading boards: skip loading of boards SparkFun:samd:micromod_samd51, SparkFun:samd:samd51_thing_plus: malformed custom board options
ID            Installed Latest Name                                                         
arduino:avr   1.8.3     1.8.3  Arduino AVR Boards                                           
SparkFun:samd 1.8.1     1.8.1  SparkFun SAMD Boards  (dependency: Arduino SAMD Boards 1.8.1)

Nope.

  • Other information:

As of now this mainly affects the SparkFun:samd platform, there is an open PR that fixes this issue: sparkfun/Arduino_Boards#73.

Am not sure if there are other platforms that will be affected.


See how to contribute

@silvanocerza silvanocerza requested a review from a team June 17, 2021 14:55
@silvanocerza silvanocerza self-assigned this Jun 17, 2021
docs/platform-specification.md Outdated Show resolved Hide resolved
arduino/cores/packagemanager/loader.go Outdated Show resolved Hide resolved
arduino/cores/packagemanager/loader.go Outdated Show resolved Hide resolved
arduino/cores/packagemanager/loader.go Outdated Show resolved Hide resolved
arduino/cores/packagemanager/loader.go Outdated Show resolved Hide resolved
test/test_core.py Outdated Show resolved Hide resolved
arduino/cores/packagemanager/loader.go Outdated Show resolved Hide resolved
@silvanocerza silvanocerza merged commit 2173c12 into master Jun 18, 2021
@silvanocerza silvanocerza deleted the scerza/fix-malformed-platform-loading branch June 18, 2021 17:02
@silvanocerza silvanocerza mentioned this pull request Jul 9, 2021
5 tasks
@per1234 per1234 mentioned this pull request Sep 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement Proposed improvement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants