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

nRF91 family improvements #1578

Merged
merged 5 commits into from
Jul 12, 2023
Merged

nRF91 family improvements #1578

merged 5 commits into from
Jul 12, 2023

Conversation

maxd-nordic
Copy link
Contributor

This patch adds the following improvements to nRF91 support:

  • UICR flashing
  • unlocking newer models with hardened APPROTECT
  • built-in flash algos

@maxd-nordic maxd-nordic force-pushed the nrf91_uicr branch 3 times, most recently from 7403d90 to 9f7f3a2 Compare July 3, 2023 09:13
@flit
Copy link
Member

flit commented Jul 4, 2023

Thanks for the improvements. 😄 I've been on holiday but will be back tomorrow and will start reviewing in earnest.

@maxd-nordic
Copy link
Contributor Author

Do you know if the builtin algos can be automatically applied to the nrf9160_xxaa target?

@flit
Copy link
Member

flit commented Jul 5, 2023

You mean the CMSIS-Pack based nrf9160_xxaa target? There's not an existing mechanism to override a pack's algos from a family class.

What is the reason for overriding the pack algos? Is it to fix issues, or add additional algos?

In any case, it should be possible by modifying the memory map. There probably should be a family subclass that is specifically used for pack-based targets (via the family class regex table) and which performs the memory map modifications. Still, this feels a bit hacky. There are also concerns about the pack possibly having newer algo versions than pyocd. However, inserting an additional memory region+algo should be safe (if that region is not already present, of course).

@maxd-nordic
Copy link
Contributor Author

maxd-nordic commented Jul 6, 2023

The algorithm here is modified slightly to work with pyocd. Since the UICR region is not present in the pack-based target, we could add it as an additional memory region there. How would I do that?

@flit
Copy link
Member

flit commented Jul 7, 2023

I see. To add the region, you can just call self.memory_map.add_region() (or .add_regions()) in your family class and pass it a new FlashRegion instance. It really can be done at any point prior to discovery. But the easiest is probably from the .__init__() method. Just add the region into the provided memory_map argument before it's passed to super().__init__().

Similarly, you can modify the memory map at this point to override the flash algo. (The ability to modify memory region attributes after creation is a recent change. If you run into trouble, just let me know!)

@maxd-nordic
Copy link
Contributor Author

@flit Thanks! Just made the change to automatically add the UICR region if not present already.

pyocd/target/family/target_nRF91.py Outdated Show resolved Hide resolved
@flit
Copy link
Member

flit commented Jul 10, 2023

Btw, I meant to mention earlier, it would be nice to add a command to perform the modem firmware update since you already have the code. Someone was asking how to do this with pyocd on the Nordic forum. Doesn't have to be in this PR, though.

To do this, create a command class like those in pyocd/commands/commands.py.

Starting from something like this:

class nRF91ModemFirmwareUpdateCommand(CommandBase):
    INFO = {
            'names': ['nrf91-update-modem-fw'],
            'group': 'nrf91', # This is the group named passed to `.add_command_group()`.
            'category': 'nrf', # Could also be 'nrf91'? This is the category the command will be grouped under in help.
            'nargs': 1, # Set based on usage
            'usage': "FILL ME IN",
            'help': "Update modem firmware for an nRF91 target.",
            'extra_help': "",
            }

    def parse(self, args):
        pass

    def execute(self):
        pass

Then override .add_target_command_groups() on the family class.

    def add_target_command_groups(self, command_set: CommandSet) -> None:
        command_set.add_command_group('nrf91')

As long as the command class is in a module loaded before add_target_command_groups() is called, it will be found automatically when you call command_set.add_command_group().

@maxd-nordic
Copy link
Contributor Author

That's great! I just added a command like you described.

@maxd-nordic maxd-nordic requested a review from flit July 12, 2023 11:06
@flit
Copy link
Member

flit commented Jul 12, 2023

Awesome! 😄

@flit flit merged commit 314d55a into pyocd:develop Jul 12, 2023
36 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants