Flash image via USB

Hi,

I have an imx8m-mini that I’m working on. I have developed an application for a customer running on Python in a Docker Container. I’ve developed the application on one unit and now we are going to produce 100 unit for our customer. I’m wondering if there is any easy way to flash the contents of my SoM to the others without having to connect a screen, install TorizonCore throught the Easy Installer and do that whole process?
Is there some way I can flash the entire image I have on my module with all the files on a USB stick and then flash in to the next SoM?

Thanks for the help!

Best regards,
Pontus

Hi @pontusoim,

When you download TorizonCore Image, you will see inside a file called image.json. There you can find relevant configurations for your image. One of them is called "autoinstall":

{
    "config_format": "4",
    "autoinstall": false,
    "name": "TorizonCore",
    "description": "TorizonCore Linux with no containers pre-provisioned.",
...

If you change this parameter to true, as soon as Tezi recognizes this image on your storage device, it will begin the installation, rather than showing as an option to install.
You can read more about it here: Detailed Manual | Toradex Developer Center

Best regards,
Hiago.

Hi,

That’s great. Is there any guide on how to create an image from my current installation that includes the all my files, docker containers and configurations? That I can use to auto flash the new units?

/Pontus

Hi @pontusoim,

Yes, you can configure your image using TorizonCore Builder.
You can check these articles on how to do it:

Let me know if you need any help with that.

Best regards,
Hiago.

Hi,

I’ve been following the guide and I’ve managed to create a minimal image that boots automatically when with the EasyInstaller. I have two issues though.
Do you have some more specific documentation for how to get a docker container into the image that runs automatically on boot? They mention the docker-compse and bundle briefly but I don’t understand how to do it. Do you have any examples of a docker-compose file that would boot automatically?
I’m also wondering how to get my python files into the system when I install the image. Can I include them somehow?

Thanks for the help,
Pontus

Hi @pontusoim,

For your docker container to initialize with your OS, you can use TorizonCore Builder. You need to add your docker-compose to your image by editing your tcbuild.yaml. If you run torizoncore-builder build --create-template, it will create a template for you with all possible configurations and some useful commentaries:

# >> NOTES:
# >> Lines containing ">>" are simply comments explaining the properties that
# >> follow; if you don't like these comments run:
# >>   $ grep -v '>>' tcbuild.yaml > tcbuild-clean.yaml
# >> A line not containing ">>" can be uncommented (by removing the hash mark
# >> plus a space from its beginning); also set the corresponding property to
# >> appropriate values.
# >> When uncommenting a line having a property, remember to uncomment all its
# >> parent properties as well; for example: if you uncomment the
# >> 'splash-screen' property, also uncomment its parent property called
# >> 'customization'.

# >> The input section specifies the image to be taken as the base for the
# >> customization.
input:
  easy-installer:
    # >> Choose one of the options (REQUIRED):
    # >> (1) Image as local folder or tarball.
    # local: torizon-core-docker-apalis-imx6-Tezi_5.2.0-devel-202104+build.11.tar
    # >> (2) Remote file (optionally with a filename and or a sha256 checksum):
    # remote: "https://artifacts.toradex.com/.../torizon-core-docker-apalis-imx8-Tezi_5.1.0%2Bbuild.1.tar"
    # remote: "https://artifacts.toradex.com/.../torizon-core-docker-colibri-imx6-Tezi_5.0.0-devel-202009%2Bbuild.2.tar;filename=torizon-core-docker-colibri-imx6-Tezi_5.0.0-devel-202009+build.2.tar;sha256sum=368595fa3fb00af9604e70311de3b04df6b30b280deec2f8918c46f479026ddb"
    # >> (3) Image specification (URL will be generated by the tool)
    # toradex-feed:
    #   version: "5.1.0"
    #   release: quarterly
    #   machine: colibri-imx7-emmc
    #   distro: torizon-upstream
    #   variant: torizon-core-docker
    #   build-number: "1"
    #   # build-date: "20210408"

# >> The customization section defines the modifications to be applied to get
# >> the desired output image.
# customization:
  # >> Splash screen:
  # splash-screen: custom-splash-screen.png
  # >> Directories overlayed to the base OSTree
  # filesystem:
     # - changes/
  # device-tree:
    # >> Directories where to look for include files.
    # include-dirs:
      # - device-trees/include/
    # >> Custom device tree source:
    # custom: device-trees/dts-arm32/imx6ull-colibri-eval-v3.dts
    # >> Device-tree overlays configuration:
    # overlays:
      # >> Whether to ignore all overlays from the base image (or ostree
      # >> archive in the future).
      # clear: false
      # >> Specific overlays not to use from base image (useful only when
      # >> clear is false and not DT has been selected).
      # remove:
        # - apalis-imx8_hdmi_overlay.dtbo
      # >> Overlays to add to output image.
      # add:
        # - device-trees/overlays/display-edt7_overlay.dts
  # kernel:
    # >> Custom kernel arguments.
    # arguments:
      # - key1=val1
      # - key2=val2
    # >> Modules to build and possibly load automatically.
    # modules:
      # - source-dir: virtual_touchscreen/
      #   autoload: false

# >> The output section defines properties of the output image.
output:
  # >> OSTree deployment configuration (relevant also for Easy Installer output).
  # ostree:
    # branch: my-dev-branch
    # commit-subject: "OSTree commit subject"
    # commit-body: "OSTree commit body"
  # >> Parameters for deploying to an Easy Installer image.
  easy-installer:
    # >> Output directory of the customized image (REQUIRED):
    local: output_directory
    # >> Information shown by Toradex Easy Installer:
    # name: "My customized image"
    # description: "My customized image (description)"
    # licence: files/custom-licence.html
    # release-notes: files/custom-release-notes.html
    # bundle:
      # >> Choose one of the options:
      # >> (1) Specify a docker-compose file whose referenced images will be downloaded.
      # >>     Properties platform, username, password and registry are optional.
      # compose-file: files/docker-compose.yml
      # platform: linux/arm/v7
      # username: "${USERNAME}"
      # password: "${PASSWORD}"
      # registry: hub.docker.com
      # >> (2) Specify a local directory containing the bundled images (previously
      # >>     obtained by 'torizoncore-builder bundle' command).
      # dir: bundle/
    # >> Provisioning configuration:
    # provisioning:
      # >> For "online" mode, properties "shared-data" and "online-data" must be specified. 
      # >> For "offline" mode, property "shared-data" must be specified alone.
      # mode: "online"
      # shared-data: "shared-data.tar.gz"
      # online-data: "${ONLINE_PROVISIONING_DATA:?online provisioning data not supplied}"

In your tcbuild.yaml you need to add your docker-compose file under output:

output:
  easy-installer:
    local: output_directory
    bundle:
      # >> Choose one of the options:
      # >> (1) Specify a docker-compose file whose referenced images will be downloaded.
      # >>     Properties platform, username, password and registry are optional.
      compose-file: files/docker-compose.yml
            

Don’t forget to uncomment these lines and also to select a TorizonCore image (just like this example: TorizonCore Builder Tool “build” command | Toradex Developer Center).
Finally, you can run torizoncore-builder build and our tool will automatically parse this file and create a custom image for you. If you’re using the above template, your image will be inside a folder called output_directory. You can simply take the file inside this folder, put into a storage device and flash it through Torizon Easy Installer. Don’t forget to change the autoinstall = true in your image.json file.

You need to add them to your Dockerfile. You will COPY the necessary python files inside your Docker image and then use the ENTRYPOINT to start your script automatically (Dockerfile reference | Docker Documentation). For example, you can add this to your Dockerfile and then build your container:

COPY /home/my_computer/main.py /home/root/
ENTRYPOINT ["python3", "/home/root/main.py"]

So when your container starts, it will start your python file automatically.

I hope this will make things clearer for you.
Let me know if you need extra help with that.

Best regards,
Hiago.

Perfect, it works now.

Thanks for the help!