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

west: Introduce run once commands (e.g. erase, recover) and deferred reset #69748

Merged
merged 6 commits into from
Apr 29, 2024

Conversation

nordicjm
Copy link
Collaborator

@nordicjm nordicjm commented Mar 4, 2024

Introduces additional fields to soc.yml or board.yml which can be used to specify west flash commands that should be grouped for multiple boards when using sysbuild, this allows usage of e.g. --erase to allow the flash to be erased once when flashing a set of images rather than once per image which would erase what had just been programmed. The format of this is the command then a list of boards which are part of the group whereby it will only be executed one for. Also supported is grouping boards to prevent resetting of the CPUs after programming when multiple images are being programmed until all images for the grouped cores have been programmed, at which point the CPU can be reset, this is ideal for multiple cores or things like TF-M.

TODO list:

  • documentation

@nordicjm nordicjm force-pushed the hwmv2-single-commands branch 3 times, most recently from 4ad6619 to 915fc92 Compare March 5, 2024 11:34
@carlescufi carlescufi requested a review from tejlmand March 6, 2024 10:08
@nordicjm nordicjm force-pushed the hwmv2-single-commands branch 3 times, most recently from a4297bd to 518b393 Compare March 6, 2024 13:12
@nordicjm nordicjm added the Architecture Review Discussion in the Architecture WG required label Mar 7, 2024
@nordicjm nordicjm force-pushed the hwmv2-single-commands branch from 518b393 to d298929 Compare March 7, 2024 11:25
@nordicjm nordicjm force-pushed the hwmv2-single-commands branch from d298929 to 29c7ef6 Compare March 7, 2024 12:10
@nordicjm nordicjm requested a review from carlescufi March 7, 2024 12:10
@nordicjm nordicjm changed the title west: Introduce single use commands (e.g. erase, recover) west: Introduce run once commands (e.g. erase, recover) and deferred reset Mar 8, 2024
@nordicjm nordicjm marked this pull request as ready for review March 8, 2024 07:29
run_once:
- '--recover':
- boards:
- /(.+)/nrf5340/cpunet/
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why would you have an entry with a single board target like this? what's the point of saying "run once" for a single target?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could be flashing multiple images to the network core, for example mcuboot, slot0 application and slot1 application, with this if you do west flash --recover then you get one recover and 3 flashes, without it you get 3 recovers and 3 flashes (thus a broken image). The run one actions only apply if there is an entry

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I see!

- name: nrf9161

# Recovery/erase is only needed once per core.
run_once:
Copy link
Member

@gmarull gmarull Mar 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a top-level "run_conce" key feels weird here, I'd suggest something like:

flashing:
  - singlerun:
  ...
  - anyfuturestuff:  

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(or flash.yml...)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was a separate file initially but moved into these files because "of too many yaml files" concerns raised by others

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was a separate file initially but moved into these files because "of too many yaml files" concerns raised by others

IMHO mixing files purpose is not a good idea either.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMHO mixing files purpose is not a good idea either.

feel free to join the discussion: #50305 (comment)
I feel the same, multiple files can be easier to read understand if the are well named and organized, quote:

The fact that both files are in yaml doesn't mean there should be one huge yaml file containing everything.

But there was request to unify and have a single source for various meta data:
#50305 (comment)

Copy link
Collaborator

@tejlmand tejlmand left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Main issues I see with current approach relates to yaml file / schema:

  • Multiple boards: entries seems to be creating a group, but it's not clear what a group is, and whether such a group should have a name. Should be made clearer.
  • Misuse of yaml keys, so that instead of being a key, it actually is a value.
    Please use a key: value pair for such cases.
  • board.yml seems to be able to reference board names which have no relation to the boards defined by the board.yml. Please ensure that only boards defined by the board.yml itself can be referenced in the commands sections. Similar for the soc.yml.

Comment on lines 258 to 261
for grp in data_yaml['run_once']:
for c, b in grp.items():
for d in b:
used_cmds.append(UsedFlashCommand(c, d['boards']))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it has been mentioned in offline discussion that a reason for placing value as the key is simpler Python parsing.
I assume that comment referred to this code, but why is this code simpler than:

for command in t['run_once']:
    used_cmds.append(UsedFlashCommand(command.get('command'), command.get('boards))

To me, removing two for loops seems even simpler.

sequence:
- type: map
mapping:
regex;(.*):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this makes the command to become a key in the yaml file, not a value.

As I see it, there are two main implecations of such approach

  • The free form .* means there is effectively no schema check, as anything is allowed for a value.
  • A : must suddenly follow the value.
    In yaml, a value is either after the colon, like:
    <key>: <value>
    or a list of values, like:
    my_list:
    - value1
    - value2
    - value3
    - ...
    

but you're creating a list of maps, but where the key in that list is actually the value.

I don't see why regular key: value mapping cannot be used, and thereby avoid tricks like this.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unification with snippets

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but not unified with boards.yml.

For example, the board.yml for nrf9160dk does:

board:
  name: nrf9160dk
  vendor: nordic
  socs:
  - name: nrf9160
    variants:
    - name: 'ns'
  - name: nrf52840

and not:

board:
  name: nrf9160dk
  vendor: nordic
  socs:
  - nrf9160:
      variants:
      - name: 'ns'
  - nrf52840:

The fact that snippet does this does not justify this principle in board or soc yaml files.

Especially not when this proposal introduces inconsistency on how things are done within the same yaml file.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See also comment here: #69748 (comment)

Comment on lines +250 to +244
except FileNotFoundError:
continue
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

something to handle ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, hwmv1 so can be ignored

Copy link
Collaborator

@tejlmand tejlmand Mar 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

then please add a comment in code, for example:

Suggested change
except FileNotFoundError:
continue
except FileNotFoundError:
# Legacy boards don't have a board.yml or soc.yml.
continue

- name: nrf9161

# Recovery/erase is only needed once per core.
run_once:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMHO mixing files purpose is not a good idea either.

feel free to join the discussion: #50305 (comment)
I feel the same, multiple files can be easier to read understand if the are well named and organized, quote:

The fact that both files are in yaml doesn't mean there should be one huge yaml file containing everything.

But there was request to unify and have a single source for various meta data:
#50305 (comment)

- /(.+)/nrf5340/cpunet/
- boards:
- /(.+)/nrf5340/cpuapp/
- /(.+)/nrf5340/cpuapp/ns/
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A soc.yml should really not know anything about board variants.

A board variant is defined by the board and could be named anything.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There needs to be a uniform naming scheme. And ns is going to be mandated by TFM anyhow

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For ns, but there can be many other variant names.

Variant names, just like other board names, should not be defined by the soc.yml.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's up to vendors if they want to change, and if they do they can add this into their board.yml file, it is not an issue

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that the groups in soc.yml should only account for socs and cpuclusters, not whole board targets.

I can't imagine a use case where a board variant would be in a separate group from its parent soc/cpucluster anyway.
But if there is one, then further refinement should be possible in board.yml.

@carlescufi
Copy link
Member

Architecture WG:

  • @nordicjm explains the feature
  • @henrikbrixandersen asks if this can be overridden from a board. The answer is yes, you can override whatever the default is for the SoC
  • @nashif asks for other vendors to take a look so that we can ensure that the soc.yml doesn't get out of hand if we keep inserting
  • @henrikbrixandersen suggests having this information in a snippet's yml file
  • @nashif wants to generalize this so that it is applicable to other vendors' use cases

@nordicjm nordicjm force-pushed the hwmv2-single-commands branch from 29c7ef6 to 7477e8f Compare March 13, 2024 10:42
@nordicjm
Copy link
Collaborator Author

@fabiobaltieri @JordanYates is the PR acceptable? If so, can you approve please?

@fabiobaltieri
Copy link
Member

@fabiobaltieri @JordanYates is the PR acceptable? If so, can you approve please?

To be totally honest I don't love it, it seems fairly complex, but I also don't really have any alternative to suggest so fine by me.

fabiobaltieri
fabiobaltieri previously approved these changes Apr 29, 2024
@carlescufi
Copy link
Member

@nordicjm please rebase

This adds supports for flashing images with sysbuild where there
are multiple images per board to prevent using the same command per
image flash which might cause issues if they are not ran just once
per flash per unique board name. A deferred reset feature is also
introduced that prevents a board (or multiple) from being reset if
multiple images are to be flashed until the final one has been
flashed which prevents issues with e.g. security bits being enabled
that then prevent flashing further images.

These options can be set at a board level (in board.yml) or a SoC
level (in soc.yml), if both are present then the board configuration
will be used instead of the SoC, and regex can be used for matching
of partial names which allows for matching specific SoCs or CPU cores
regardless of the board being used

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
Reformats the soc.yml file to have uniform 2-space indentation

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
Adds configuration that allows nRF53 and nRF91-based boards to be
flashed through west using sysbuild for multiple images with the
recover or erase options and prevent running those commands for
each image being flash, which would make the device unbootable.
Also defers reset whilst all images for the cores of these SoCs
are flashed.

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
Adds documentation on the new flashing configuration system

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
Adds a note that a new flashing configuration system has been
added for boards and socs

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
Adds checking that qualifiers listed in a soc.yml file are valid
for the socs and cpuclusters defined in that file

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
Copy link
Member

@carlescufi carlescufi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As described here and here I am not a huge fan of the yaml format, but I see no reason not to move forward with this at this point.

@carlescufi
Copy link
Member

carlescufi commented Apr 29, 2024

Removing assignee since @tejlmand is opting out of this particular review.

@fabiobaltieri fabiobaltieri merged commit 5033399 into zephyrproject-rtos:main Apr 29, 2024
36 checks passed
PerMac added a commit to PerMac/zephyr that referenced this pull request May 10, 2024
Using `erase` with west-flash was blocked as it was
messing with sysbuild. With zephyrproject-rtos#69748 the issue is fixed, hence
'erase' is no longer blocked.
Remove obsolete twister test

Signed-off-by: Maciej Perkowski <Maciej.Perkowski@nordicsemi.no>
nashif pushed a commit that referenced this pull request May 11, 2024
Using `erase` with west-flash was blocked as it was
messing with sysbuild. With #69748 the issue is fixed, hence
'erase' is no longer blocked.
Remove obsolete twister test

Signed-off-by: Maciej Perkowski <Maciej.Perkowski@nordicsemi.no>
SebastianBoe pushed a commit to SebastianBoe/zephyr that referenced this pull request May 23, 2024
Using `erase` with west-flash was blocked as it was
messing with sysbuild. With zephyrproject-rtos#69748 the issue is fixed, hence
'erase' is no longer blocked.
Remove obsolete twister test

Signed-off-by: Maciej Perkowski <Maciej.Perkowski@nordicsemi.no>
(cherry picked from commit be682e2)
mariopaja pushed a commit to mariopaja/zephyr that referenced this pull request May 26, 2024
Using `erase` with west-flash was blocked as it was
messing with sysbuild. With zephyrproject-rtos#69748 the issue is fixed, hence
'erase' is no longer blocked.
Remove obsolete twister test

Signed-off-by: Maciej Perkowski <Maciej.Perkowski@nordicsemi.no>
@nordicjm nordicjm deleted the hwmv2-single-commands branch July 12, 2024 12:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: Build System area: West West utility platform: nRF Nordic nRFx Release Notes To be mentioned in the release notes
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

10 participants