Skip to content

[PC-1568] Portenta Family Code Format Patch Docs #1720

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

Merged
merged 6 commits into from
Feb 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ This can be done with **imgtool**. You can download and install it directly from
***`imgtool` is already installed by the mbed platform and can be found in the `%LOCALAPPDATA%\Arduino15\packages\arduino\tools\imgtool` directory on Windows, in `~/.arduino15/packages/arduino/tools/imgtool` on Linux and in `~/Library/Arduino15/packages/arduino/tools/imgtool` on macOS.***

To generate the new keys you can use this command line:
```

```bash
imgtool keygen --key my-sign-keyfile.pem -t ecdsa-p256
imgtool keygen --key my-encrypt-keyfile.pem -t ecdsa-p256
```
Expand All @@ -57,7 +58,8 @@ Remember to **save the keys and keep them in a secure location** and not to lose

### 2. Upload the Custom Keys to the Board
Once the keys have been generated, they have to be uploaded to the Portenta H7. This procedure has to be done only once, because it is persistent. To extract the public\private key and encode it in to a "C" byte array inside a `.h` header file you can use:
```

```bash
imgtool getpriv -k my-encrypt-keyfile.pem > ecsda-p256-encrypt-priv-key.h
imgtool getpub -k my-sign-keyfile.pem > ecsda-p256-signing-pub-key.h
```
Expand All @@ -71,7 +73,8 @@ To do so, just save the sketch to another location and replace the `ecsda-p256-e
Since the default keys have been changed in favour of custom generated ones, the new ones have to be used when compiling and uploading a sketch, because the compiled sketch is signed and encrypted using such keys.

To override the security keys used during the compile, you have to use the Arduino CLI and specify the keys with:
```

```bash
arduino-cli compile -b arduino:mbed_portenta:envie_m7 --board-options security=sien --keys-keychain <path-to-your-keys> --sign-key ecdsa-p256-signing-priv-key.pem --encrypt-key ecdsa-p256-encrypt-pub-key.pem /home/user/Arduino/MySketch
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ To upload the firmware, you can use the ADB tool that has been installed as part

From that directory, you can use the `adb` tool. To upload your compiled sketch, you will need to use the following command:

```
```bash
adb push <sketchBinaryPath> /tmp/arduino/m4-user-sketch.elf
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ temperature = rpc_client.call('temperature')

The complete Python® application files are in the same package as the Arduino sketch (see above). Like in the previous step, upload the `python-sensor-rpc` folder to the X8 via `adb push <local directory path>/python-sensor-rpc /home/fio`. Log into the X8 via `adb shell`. Then navigate into the `python-sensor-rpc` folder and execute `sudo docker build . -t python-sensor-rpc`. When it is finished, you can run the container with `sudo docker-compose up`. After a few seconds, you should see the output from the Python application featuring the sensor readings on the M4 that exchanges through the RPC mechanism. The output should look similar to the following:

```
```bash
python-sensor-rpc_1 | ============================================
python-sensor-rpc_1 | == Portenta X8 Sensor reading ==
python-sensor-rpc_1 | ============================================
Expand All @@ -116,7 +116,9 @@ Whenever you change anything in the Python® script on your computer, you will h
```bash
# On your computer
adb push python-sensor-rpc /home/fio
```

```bash
# On X8
sudo docker-compose down
sudo docker build . -t python-sensor-rpc
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ In this tutorial, we will go through the steps of how to install, run and remove

The Portenta X8 provides Docker CLI by default. The following command will help you verify if it is installed correctly:

```
```bash
docker -v
```

Expand All @@ -63,7 +63,7 @@ First, you will need to search for ["Hello World" container image](https://hub.d

The following command must be used to pull the `hello-world` image. The Docker hub page for images has the instructions to pull the image and deploy the container.

```
```bash
docker pull hello-world
```

Expand All @@ -73,7 +73,7 @@ docker pull hello-world

This is the command to begin the container instance.

```
```bash
docker run hello-world
```

Expand All @@ -85,15 +85,15 @@ docker run hello-world

The following command will display the active containers and will show the `hello-world` container if it was able to run successfully. The `STATUS` message will let you know if the container is active or has finished operation depending on its purpose.

```
```bash
docker ps -a
```

![Docker CLI listing all the active containers](assets/docker-ps.png)

The list of available images, including installed `hello-world` image, can be verified using the following command:

```
```bash
docker images
```

Expand All @@ -103,15 +103,15 @@ docker images

You will need to obtain an assigned `CONTAINER ID` to be able to remove a container of your choice. The list of active containers provides this information. The remove (`rm`) command is then used with the desired container identifier to proceed with the removal process.

```
```bash
docker container rm <CONTAINER ID>
```

For this example, the command `docker ps -a` will show the `CONTAINER ID` of the `hello-world` container designated as: `c44ba77b65cb`. If you encounter an error stating that the container cannot be removed, it may mean that the container has an actively ongoing operation which can be checked with `STATUS` message.

Granted that this is the case, you will need to stop the container and verify with `STATUS` message that it has exited successfully. To do this, the following command is used:

```
```bash
docker stop <CONTAINER ID>
```

Expand All @@ -123,7 +123,7 @@ Using the `docker ps -a` after container removal, the `hello-world` container sh

The same goes for the images if you would like to free some space. The removal command will now be as follows using `IMAGE ID` found within the image table:

```
```bash
docker rmi <IMAGE ID>
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,19 @@ For security purposes, we recommend that you rotate your FoundriesFactory keys.

First, we will rotate the root keys. These are the most important keys, as they are used to create new target keys. Rotate them with the command:

```
```bash
fioctl keys rotate-root --initial /absolute/path/to/root.keys.tgz
```

Now we can rotate the target-only keys with following command:

```
```bash
fioctl keys rotate-targets /absolute/path/to/root.keys.tgz
```

And finally, for security reasons, we separating the target keys from the root using the following command:

```
```bash
fioctl keys copy-targets /absolute/path/to/root.keys.tgz /path/to/target.only.key.tgz
```

Expand All @@ -68,13 +68,13 @@ Now we can move on to creating our Wave.

Before a Factory can start making production OTAs, an initial production Targets file must be created. For more information, please check out [here](https://docs.foundries.io/latest/reference-manual/ota/production-targets.html). We can begin by creating a dummy wave with the command:

```
```bash
fioctl wave init -k /absolute/path/to/targets.only.key.tgz populate-targets
```

Then complete the Wave with:

```
```bash
fioctl wave complete populate-targets
```

Expand All @@ -84,19 +84,19 @@ This creates a new `targets.json` file for production devices, subscribing to th

Now we can start creating our Wave. The command below will create a Wave that is pushable to our devices. To create a Wave, we will sign it with a key, and here we will use the targets-only key. Then we give the Wave a name, target number, and tag. The `target number` needs to correspond to the target that we want the Wave to contain for our devices. The `tag` can be set as production or development.

```
```bash
fioctl wave init -k /absolute/path/to/targets.only.key.tgz <waveName> <targetNumber> <tag>
```

And then we can complete the Wave by passing the name to the "complete" function:

```
```bash
fioctl wave complete <waveName>
```

If you decide to cancel, the following command will help you to do that:

```
```bash
fioctl waves cancel <waveName>
```

Expand All @@ -108,13 +108,13 @@ After creating the Wave, you should see it on your Factory page. It should also

With this command, we create our group, giving it a name and a short description:

```
```bash
fioctl config device-group create <groupName> "<shortDescription>"
```

The name and the short description should be as explicit and concise as possible to highlight its group. Now to assign a device to our group we use the following command:

```
```bash
fioctl device config group <deviceName> <groupName>
```

Expand All @@ -124,7 +124,7 @@ On your FoundriesFactory device page, you can sort and view devices by the group

To roll out our Wave to our device group, use the following command:

```
```bash
fioctl waves rollout <waveName> <deviceGroupName>
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ To pull or push repositories, you have to generate an API key. This is done by g

Use the following command in git on your machine. To get the repository on your machine, replace "YOUR_FACTORY" with the name of your Factory. The "-b" parameter specifies a branch to checkout after cloning the repository. Running this command will get the container repository, where we will put our folder.

```
```bash
git clone https://source.foundries.io/factories/YOUR_FACTORY/containers.git -b devel
```

Expand All @@ -157,48 +157,51 @@ Put the "x8-custom-test" folder in the repository and push it with git. When you

After the build finishes, it can take up to 10 minutes for your device to update over-the-air to this new version. You can inspect it via the "Devices" tab of your FoundriesFactory. After your device takes the update, navigate into the "x8-custom-test" folder, which should be located on your board now. This allows us to build our container with a simple command. Using ```docker build``` with a ```--tag``` will let us give the container a tag so we can easily keep track of what version of the build this is.

```python
```bash
docker build --tag "x8-custom-test:latest" .
```

Now that it is built, we can run it with ```docker run```, finding it with the tag that we chose to give to the build we want to run. Here we need to enter the user information into the --user tag. This information is found inside the "docker-compose.yml" file.

```python
```bash
docker run -it --rm --user "63" x8-custom-test:latest
```

### Using Docker-Compose

An option for testing an app or container is to use "docker-compose". It is helpful when we have a lot of settings in our "docker-compose.yml" file since we don't have to use those settings in the run argument with this method. First, navigate into the container folder.

```python
```bash
cd /home/fio/x8-custom-test
```

This docker-compose command will start your application and register it as a systemd service that will persist even when a reboot occurs. So at the next boot, your docker-compose app will run automatically.

```python
```bash
docker-compose up --detach
```

To stop the docker-compose app from running, use the following command:

```python
```bash
docker-compose stop
```

## Deploying with Docker Hub

An alternative method to deploy the custom container is by using the Docker Hub platform. For this, it needs a [Docker Hub account](https://hub.docker.com/) to have your own repository to have the custom container uploaded. When you have the repository ready, the following command will let you upload the custom container image.

```
```bash
docker push HUB_USERNAME/x8-custom-test
```

The custom container image can now be found within `HUB_USERNAME` Docker Hub repository. The image can be accessed whenever any connectivity type grants access to the container image. To pull the image and deploy the container, you will need to connect the Portenta X8 via ADB and use following commands in sequence:

```
```bash
adb shell
```

```bash
docker pull x8-custom-test
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,19 @@ You will create a Docker image that has the dependencies needed to build your de

First, clone the lmp-manifest repository with the following command:

```
```bash
git clone https://github.com/arduino/lmp-manifest.git
```

![Cloning lmp-manifest repository](assets/git_clone_lmp-manifest.png)

After cloning the lmp-manifest repository successfully, we will proceed to build the Docker Image using following command sequence:

```
```bash
cd lmp-manifest
```

```bash
docker build -t yocto-build ./lmp-manifest
```

Expand All @@ -69,13 +72,13 @@ Once the *Docker Image* is ready, we will run the image with the `-v` argument t

Run the `yocto-build` builder image with following command:

```
```bash
docker run -v <source>:/dockerVolume -it yocto-build bash
```

We need to switch to the `builder` user with the following command after the previous process, and the password is **builder**:

```
```bash
su builder
```

Expand All @@ -89,7 +92,7 @@ Now that you are running inside the Docker Image, you can use tools like **git-r

First, configure git with your credentials. They don't need to be the real ones but are required by `git-repo` to pull. The following commands can be used for this example:

```
```bash
git config --global user.email "you@example.com"
git config --global user.name "Your Name"
```
Expand All @@ -98,7 +101,7 @@ git config --global user.name "Your Name"

Change to the home directory, and initialize the repository using **repo**:

```
```bash
cd /dockerVolume
repo init -u https://github.com/arduino/lmp-manifest.git -m arduino.xml -b release
```
Expand All @@ -107,7 +110,7 @@ repo init -u https://github.com/arduino/lmp-manifest.git -m arduino.xml -b relea

Then pull the needed files with:

```
```bash
repo sync
```

Expand Down Expand Up @@ -149,7 +152,7 @@ You will be able to see similar output as following after the previous steps:

To start building the image, following command is used:

```
```bash
bitbake lmp-partner-arduino-image
```

Expand All @@ -174,7 +177,7 @@ If possible, it is a good practice to understand the available threads of your c

To flash your board, you will need to compile **lmp-mfgtool distro** to get additional tools. First, go into your home folder and change `DISTRO` following the command sequence:

```
```bash
cd ..
DISTRO=lmp-mfgtool MACHINE=portenta-x8 . setup-environment
echo "ACCEPT_FSL_EULA = \"1\"" >> conf/local.conf
Expand All @@ -189,7 +192,7 @@ You should be able to see similar results as following image when successful:

To compile and get the tools required, we will use following command:

```
```bash
bitbake mfgtool-files
```

Expand All @@ -205,7 +208,7 @@ After completion:

After a successful build, save the needed files to the host volume you mounted with `docker run`. Use the following commands to copy the files to your storage unit:

```
```bash
cd ..
mkdir ../../dockerVolume/flashing
DEPLOY_FOLDER=../../dockerVolume/flashing
Expand Down
Loading