Creating a custom WPC Service adapter

Contents

Creating a custom WPC Service adapter#

This chapter is for those users, who wish not to use EL2GO, but rather have their own solution.

To help you getting started with creating a custom Service, we have a Cookiecutter template located in: <spsdk_repo>/examples/templates/cookiecutter-spsdk-wpc-service-plugin.zip
This template will create a Python project, containing a plugin for SPSDK

  1. Install cookiecutter: pip install cookiecutter

  2. Create your project: cookiecutter <spsdk_repo>/examples/plugins/templates/cookiecutter-spsdk-wpc-service-plugin.zip

    • follow the prompts

    • your project will be created in the current working directory

  3. Class representing your adapter will be located in: <your_project_name/your_project_name/your_project_name.py>

  4. Implement necessary methods

    • get_validation_schema

      • Use this method to provide JSON validation schema for your class (parameters for the __init__ method)

      • Schema will be used when instantiating your class using configuration data via .from_config method

      • This schema will be also used to generate configuration file using nxpwpc get-template

    • get_wpc_cert

      • This method is the bread and butter of your adapter

      • Here is where you’ll implement the process of getting the WPC Certificate Chain

  5. Install your plugin into virtual environment where you have SPSDK

    • pip install (--editable) <path/to/your/project>

    • The --editable flag is used for development purposes. It will allow you to develop your plugin without a need to re-install your plugin after every change

  6. Verify your plugin was picked-up by SPSDK

    • nxpwpc get-template --help

    • You should see the name of your plugin in --service-type option

    • Name of the plugin is set during project creation, also defined in your class as NAME attribute

Example#

my_wpc_service_plugin-0.1.0.tar.gz is an example of a Python project created from the template mentioned above.

!pip install my_wpc_service_plugin-0.1.0.tar.gz
Processing .\my_wpc_service_plugin-0.1.0.tar.gz
  Preparing metadata (setup.py): started
  Preparing metadata (setup.py): finished with status 'done'
Requirement already satisfied: spsdk>=2.0 in c:\_projects\mcu_boot\repo\bsdk-master\venv\lib\site-packages (from my-wpc-service-plugin==0.1.0) (2.1.0+wpc.ear1.post1)
Requirement already satisfied: oscrypto<1.4 in c:\_projects\mcu_boot\repo\bsdk-master\venv\lib\site-packages (from spsdk>=2.0->my-wpc-service-plugin==0.1.0) (1.3.0)
Requirement already satisfied: pypemicro<0.2,>=0.1.11 in c:\_projects\mcu_boot\repo\bsdk-master\venv\lib\site-packages (from spsdk>=2.0->my-wpc-service-plugin==0.1.0) (0.1.11)
Requirement already satisfied: prettytable<3.10,>=3.0.0 in c:\_projects\mcu_boot\repo\bsdk-master\venv\lib\site-packages (from spsdk>=2.0->my-wpc-service-plugin==0.1.0) (3.9.0)
Requirement already satisfied: libusbsio<2.2,>=2.1.11 in c:\_projects\mcu_boot\repo\bsdk-master\venv\lib\site-packages (from spsdk>=2.0->my-wpc-service-plugin==0.1.0) (2.1.11)
Requirement already satisfied: click-command-tree<1.2 in c:\_projects\mcu_boot\repo\bsdk-master\venv\lib\site-packages (from spsdk>=2.0->my-wpc-service-plugin==0.1.0) (1.1.1)
Requirement already satisfied: platformdirs<4.2,>=3.9.1 in c:\_projects\mcu_boot\repo\bsdk-master\venv\lib\site-packages (from spsdk>=2.0->my-wpc-service-plugin==0.1.0) (4.1.0)
Requirement already satisfied: typing-extensions<4.10 in c:\_projects\mcu_boot\repo\bsdk-master\venv\lib\site-packages (from spsdk>=2.0->my-wpc-service-plugin==0.1.0) (4.9.0)
Requirement already satisfied: click-option-group<0.6,>=0.3.0 in c:\_projects\mcu_boot\repo\bsdk-master\venv\lib\site-packages (from spsdk>=2.0->my-wpc-service-plugin==0.1.0) (0.5.6)
Requirement already satisfied: fastjsonschema<2.20,>=2.15.1 in c:\_projects\mcu_boot\repo\bsdk-master\venv\lib\site-packages (from spsdk>=2.0->my-wpc-service-plugin==0.1.0) (2.19.1)
Requirement already satisfied: cryptography<41.1,>=35.0.0 in c:\_projects\mcu_boot\repo\bsdk-master\venv\lib\site-packages (from spsdk>=2.0->my-wpc-service-plugin==0.1.0) (41.0.7)
Requirement already satisfied: deepmerge<1.2 in c:\_projects\mcu_boot\repo\bsdk-master\venv\lib\site-packages (from spsdk>=2.0->my-wpc-service-plugin==0.1.0) (1.1.1)
Requirement already satisfied: colorama<0.5,>=0.4.6 in c:\_projects\mcu_boot\repo\bsdk-master\venv\lib\site-packages (from spsdk>=2.0->my-wpc-service-plugin==0.1.0) (0.4.6)
Requirement already satisfied: astunparse<1.7,>=1.6 in c:\_projects\mcu_boot\repo\bsdk-master\venv\lib\site-packages (from spsdk>=2.0->my-wpc-service-plugin==0.1.0) (1.6.3)
Requirement already satisfied: requests<2.32,>=2.0 in c:\_projects\mcu_boot\repo\bsdk-master\venv\lib\site-packages (from spsdk>=2.0->my-wpc-service-plugin==0.1.0) (2.31.0)
Requirement already satisfied: pyocd-pemicro<1.2,>=1.1.5 in c:\_projects\mcu_boot\repo\bsdk-master\venv\lib\site-packages (from spsdk>=2.0->my-wpc-service-plugin==0.1.0) (1.1.5)
Requirement already satisfied: ruamel.yaml<0.19,>=0.17 in c:\_projects\mcu_boot\repo\bsdk-master\venv\lib\site-packages (from spsdk>=2.0->my-wpc-service-plugin==0.1.0) (0.18.5)
Requirement already satisfied: asn1crypto<1.6,>=1.2 in c:\_projects\mcu_boot\repo\bsdk-master\venv\lib\site-packages (from spsdk>=2.0->my-wpc-service-plugin==0.1.0) (1.5.1)
Requirement already satisfied: hexdump<3.4 in c:\_projects\mcu_boot\repo\bsdk-master\venv\lib\site-packages (from spsdk>=2.0->my-wpc-service-plugin==0.1.0) (3.3)
Requirement already satisfied: sly<0.6 in c:\_projects\mcu_boot\repo\bsdk-master\venv\lib\site-packages (from spsdk>=2.0->my-wpc-service-plugin==0.1.0) (0.5)
Requirement already satisfied: bitstring<4.2,>=3.1 in c:\_projects\mcu_boot\repo\bsdk-master\venv\lib\site-packages (from spsdk>=2.0->my-wpc-service-plugin==0.1.0) (4.1.4)
Requirement already satisfied: crcmod<1.8 in c:\_projects\mcu_boot\repo\bsdk-master\venv\lib\site-packages (from spsdk>=2.0->my-wpc-service-plugin==0.1.0) (1.7)
Requirement already satisfied: pyocd<0.37,>=0.35.1 in c:\_projects\mcu_boot\repo\bsdk-master\venv\lib\site-packages (from spsdk>=2.0->my-wpc-service-plugin==0.1.0) (0.36.0)
Requirement already satisfied: bincopy<20.1,>=17.14.5 in c:\_projects\mcu_boot\repo\bsdk-master\venv\lib\site-packages (from spsdk>=2.0->my-wpc-service-plugin==0.1.0) (20.0.0)
Requirement already satisfied: pyserial<3.6,>=3.1 in c:\_projects\mcu_boot\repo\bsdk-master\venv\lib\site-packages (from spsdk>=2.0->my-wpc-service-plugin==0.1.0) (3.5)
Requirement already satisfied: pylink-square<1.3,>=1.0 in c:\_projects\mcu_boot\repo\bsdk-master\venv\lib\site-packages (from spsdk>=2.0->my-wpc-service-plugin==0.1.0) (1.2.0)
Requirement already satisfied: click!=8.1.4,<8.1.6,>=7.1 in c:\_projects\mcu_boot\repo\bsdk-master\venv\lib\site-packages (from spsdk>=2.0->my-wpc-service-plugin==0.1.0) (8.1.5)
Requirement already satisfied: six<2.0,>=1.6.1 in c:\_projects\mcu_boot\repo\bsdk-master\venv\lib\site-packages (from astunparse<1.7,>=1.6->spsdk>=2.0->my-wpc-service-plugin==0.1.0) (1.16.0)
Requirement already satisfied: wheel<1.0,>=0.23.0 in c:\_projects\mcu_boot\repo\bsdk-master\venv\lib\site-packages (from astunparse<1.7,>=1.6->spsdk>=2.0->my-wpc-service-plugin==0.1.0) (0.41.0)
Requirement already satisfied: humanfriendly in c:\_projects\mcu_boot\repo\bsdk-master\venv\lib\site-packages (from bincopy<20.1,>=17.14.5->spsdk>=2.0->my-wpc-service-plugin==0.1.0) (10.0)
Requirement already satisfied: pyelftools in c:\_projects\mcu_boot\repo\bsdk-master\venv\lib\site-packages (from bincopy<20.1,>=17.14.5->spsdk>=2.0->my-wpc-service-plugin==0.1.0) (0.29)
Requirement already satisfied: argparse-addons>=0.4.0 in c:\_projects\mcu_boot\repo\bsdk-master\venv\lib\site-packages (from bincopy<20.1,>=17.14.5->spsdk>=2.0->my-wpc-service-plugin==0.1.0) (0.12.0)
Requirement already satisfied: bitarray<3.0.0,>=2.8.0 in c:\_projects\mcu_boot\repo\bsdk-master\venv\lib\site-packages (from bitstring<4.2,>=3.1->spsdk>=2.0->my-wpc-service-plugin==0.1.0) (2.9.2)
Requirement already satisfied: cffi>=1.12 in c:\_projects\mcu_boot\repo\bsdk-master\venv\lib\site-packages (from cryptography<41.1,>=35.0.0->spsdk>=2.0->my-wpc-service-plugin==0.1.0) (1.15.1)
Requirement already satisfied: wcwidth in c:\_projects\mcu_boot\repo\bsdk-master\venv\lib\site-packages (from prettytable<3.10,>=3.0.0->spsdk>=2.0->my-wpc-service-plugin==0.1.0) (0.2.6)
Requirement already satisfied: psutil>=5.2.2 in c:\_projects\mcu_boot\repo\bsdk-master\venv\lib\site-packages (from pylink-square<1.3,>=1.0->spsdk>=2.0->my-wpc-service-plugin==0.1.0) (5.9.5)
Requirement already satisfied: pyyaml<7.0,>=6.0 in c:\_projects\mcu_boot\repo\bsdk-master\venv\lib\site-packages (from pyocd<0.37,>=0.35.1->spsdk>=2.0->my-wpc-service-plugin==0.1.0) (6.0.1)
Requirement already satisfied: importlib-metadata>=3.6 in c:\_projects\mcu_boot\repo\bsdk-master\venv\lib\site-packages (from pyocd<0.37,>=0.35.1->spsdk>=2.0->my-wpc-service-plugin==0.1.0) (6.8.0)
Requirement already satisfied: hidapi<1.0,>=0.10.1 in c:\_projects\mcu_boot\repo\bsdk-master\venv\lib\site-packages (from pyocd<0.37,>=0.35.1->spsdk>=2.0->my-wpc-service-plugin==0.1.0) (0.14.0)
Requirement already satisfied: intelhex<3.0,>=2.0 in c:\_projects\mcu_boot\repo\bsdk-master\venv\lib\site-packages (from pyocd<0.37,>=0.35.1->spsdk>=2.0->my-wpc-service-plugin==0.1.0) (2.3.0)
Requirement already satisfied: natsort<9.0,>=8.0.0 in c:\_projects\mcu_boot\repo\bsdk-master\venv\lib\site-packages (from pyocd<0.37,>=0.35.1->spsdk>=2.0->my-wpc-service-plugin==0.1.0) (8.4.0)
Requirement already satisfied: pyusb<2.0,>=1.2.1 in c:\_projects\mcu_boot\repo\bsdk-master\venv\lib\site-packages (from pyocd<0.37,>=0.35.1->spsdk>=2.0->my-wpc-service-plugin==0.1.0) (1.2.1)
Requirement already satisfied: cmsis-pack-manager<1.0,>=0.5.2 in c:\_projects\mcu_boot\repo\bsdk-master\venv\lib\site-packages (from pyocd<0.37,>=0.35.1->spsdk>=2.0->my-wpc-service-plugin==0.1.0) (0.5.2)
Requirement already satisfied: importlib-resources in c:\_projects\mcu_boot\repo\bsdk-master\venv\lib\site-packages (from pyocd<0.37,>=0.35.1->spsdk>=2.0->my-wpc-service-plugin==0.1.0) (6.0.0)
Requirement already satisfied: intervaltree<4.0,>=3.0.2 in c:\_projects\mcu_boot\repo\bsdk-master\venv\lib\site-packages (from pyocd<0.37,>=0.35.1->spsdk>=2.0->my-wpc-service-plugin==0.1.0) (3.1.0)
Requirement already satisfied: libusb-package<2.0,>=1.0 in c:\_projects\mcu_boot\repo\bsdk-master\venv\lib\site-packages (from pyocd<0.37,>=0.35.1->spsdk>=2.0->my-wpc-service-plugin==0.1.0) (1.0.26.2)
Requirement already satisfied: capstone<5.0,>=4.0 in c:\_projects\mcu_boot\repo\bsdk-master\venv\lib\site-packages (from pyocd<0.37,>=0.35.1->spsdk>=2.0->my-wpc-service-plugin==0.1.0) (4.0.2)
Requirement already satisfied: lark<2.0,>=1.1.5 in c:\_projects\mcu_boot\repo\bsdk-master\venv\lib\site-packages (from pyocd<0.37,>=0.35.1->spsdk>=2.0->my-wpc-service-plugin==0.1.0) (1.1.7)
Requirement already satisfied: idna<4,>=2.5 in c:\_projects\mcu_boot\repo\bsdk-master\venv\lib\site-packages (from requests<2.32,>=2.0->spsdk>=2.0->my-wpc-service-plugin==0.1.0) (3.4)
Requirement already satisfied: certifi>=2017.4.17 in c:\_projects\mcu_boot\repo\bsdk-master\venv\lib\site-packages (from requests<2.32,>=2.0->spsdk>=2.0->my-wpc-service-plugin==0.1.0) (2023.7.22)
Requirement already satisfied: urllib3<3,>=1.21.1 in c:\_projects\mcu_boot\repo\bsdk-master\venv\lib\site-packages (from requests<2.32,>=2.0->spsdk>=2.0->my-wpc-service-plugin==0.1.0) (2.0.4)
Requirement already satisfied: charset-normalizer<4,>=2 in c:\_projects\mcu_boot\repo\bsdk-master\venv\lib\site-packages (from requests<2.32,>=2.0->spsdk>=2.0->my-wpc-service-plugin==0.1.0) (3.2.0)
Requirement already satisfied: ruamel.yaml.clib>=0.2.7 in c:\_projects\mcu_boot\repo\bsdk-master\venv\lib\site-packages (from ruamel.yaml<0.19,>=0.17->spsdk>=2.0->my-wpc-service-plugin==0.1.0) (0.2.7)
Requirement already satisfied: pycparser in c:\_projects\mcu_boot\repo\bsdk-master\venv\lib\site-packages (from cffi>=1.12->cryptography<41.1,>=35.0.0->spsdk>=2.0->my-wpc-service-plugin==0.1.0) (2.21)
Requirement already satisfied: appdirs<2.0,>=1.4 in c:\_projects\mcu_boot\repo\bsdk-master\venv\lib\site-packages (from cmsis-pack-manager<1.0,>=0.5.2->pyocd<0.37,>=0.35.1->spsdk>=2.0->my-wpc-service-plugin==0.1.0) (1.4.4)
Requirement already satisfied: setuptools>=19.0 in c:\_projects\mcu_boot\repo\bsdk-master\venv\lib\site-packages (from hidapi<1.0,>=0.10.1->pyocd<0.37,>=0.35.1->spsdk>=2.0->my-wpc-service-plugin==0.1.0) (68.1.2)
Requirement already satisfied: zipp>=0.5 in c:\_projects\mcu_boot\repo\bsdk-master\venv\lib\site-packages (from importlib-metadata>=3.6->pyocd<0.37,>=0.35.1->spsdk>=2.0->my-wpc-service-plugin==0.1.0) (3.16.2)
Requirement already satisfied: sortedcontainers<3.0,>=2.0 in c:\_projects\mcu_boot\repo\bsdk-master\venv\lib\site-packages (from intervaltree<4.0,>=3.0.2->pyocd<0.37,>=0.35.1->spsdk>=2.0->my-wpc-service-plugin==0.1.0) (2.4.0)
Requirement already satisfied: pyreadline3 in c:\_projects\mcu_boot\repo\bsdk-master\venv\lib\site-packages (from humanfriendly->bincopy<20.1,>=17.14.5->spsdk>=2.0->my-wpc-service-plugin==0.1.0) (3.4.1)
Building wheels for collected packages: my-wpc-service-plugin
  Building wheel for my-wpc-service-plugin (setup.py): started
  Building wheel for my-wpc-service-plugin (setup.py): finished with status 'done'
  Created wheel for my-wpc-service-plugin: filename=my_wpc_service_plugin-0.1.0-py2.py3-none-any.whl size=4648 sha256=22c11df12b43ccaf3246953cca5531e56a2f1823ee836415d55fd1cfd5f996a0
  Stored in directory: c:\users\nxa17573\appdata\local\pip\cache\wheels\2c\e2\dd\9fe0383a114285c98810467b5670c8c8a8c87a22d1de50ba3a
Successfully built my-wpc-service-plugin
Installing collected packages: my-wpc-service-plugin
  Attempting uninstall: my-wpc-service-plugin
    Found existing installation: my-wpc-service-plugin 0.1.0
    Uninstalling my-wpc-service-plugin-0.1.0:
      Successfully uninstalled my-wpc-service-plugin-0.1.0
Successfully installed my-wpc-service-plugin-0.1.0
[notice] A new release of pip available: 22.3.1 -> 23.3.2
[notice] To update, run: python.exe -m pip install --upgrade pip
!nxpwpc get-template --help
Usage: nxpwpc get-template [OPTIONS]

  Generate a configuration template.

Options:
  -st, --service-type [el2go|mywpc]
                                  Name of the WPC service type.  [required]
  -tt, --target-type [model|mboot]
                                  Name of the MCU target type.  [required]
  -f, --family [mwct2d17s]        Select the chip family.  [required]
  -o, --output FILE               Path to a file, where to store the output.
                                  [required]
  --force                         Force overwriting of existing files.
  --help                          Show this message and exit.

Please note the mywpc service type above

!nxpwpc get-template -st mywpc -tt model -f mwct2d17s -o config_with_plugin.yaml --force
Creating config_with_plugin.yaml template file.

Please note the service_parameters section of config_with_plugin.yaml.
Keys param1 and param2 are coming from .get_validation_schema method from the plugin.
When instantiating the plugin class using .from_config, these two keys will will be passed to the __init__ method.