J-Link Docker Container

From SEGGER Wiki
Jump to: navigation, search

Docker This tutorial or quick reference page will help you getting started with Docker under Linux and on how to install J-Link in a container.

Installing Docker under Ubuntu

Below, you may find the steps for installing Docker under a Ubuntu distribution.

 $ sudo apt install apt-transport-https ca-certificates curl software-properties-common
 $ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
 $ sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu bionic stable"
 $ apt-cache policy docker-ce
 $ sudo apt install docker-ce
 $ sudo systemctl status docker

Start the docker service

 $ sudo service docker start  

Checking the Docker installation

$ sudo docker run hello-world

If your installation was successful your output should provide the following message.

 Hello from Docker!
 This message shows that your installation appears to be working correctly.

Docker Image and Container

Make a Docker image pull

 $ sudo docker pull ubuntu

Note: For this demonstration, we will install Ubuntu docker image. If you wish you can also choose a different image for that just take a look in the available images in the Docker Hub.

Adding a Ubuntu docker container In order to add a container with usb support --privileged mode needs to be used.

 $ sudo docker run -t -i --privileged -v /dev/bus/usb/:/dev/bus/usb ubuntu bash

Your terminal should now be in a docker container session. Should look something like this:

 anybody@ubuntu:~/Downloads$ sudo docker run -t -i --privileged -v /dev/bus/usb/:/dev/bus/usb ubuntu bash
 root@808cdff86898:/# ls / home/
 bin  boot  dev  etc  home  lib  lib64  media  mnt  opt  proc  root  run  sbin  srv  sys  tmp  usr  var

Installing J-Link in a Container

In order to install J-Link under container running Ubuntu start by downloading J-Link software ( J-Link 32-bit J-Link 64-bit)

Check the running container ID and name:

 anybody@ubuntu:~/Downloads$ sudo docker ps 
 CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
 808cdff86898        ubuntu              "bash"              About an hour ago   Up 8 seconds                            youthful_buck

List all created containers

 $ sudo docker ps -a 
 anybody@ubuntu:~/Downloads$ sudo docker ps -a
 CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                      PORTS               NAMES
 808cdff86898        ubuntu              "bash"              4 minutes ago       Up 4 minutes                                    youthful_buck
 49b5480e0ee9        hello-world         "/hello"            15 minutes ago      Exited (0) 15 minutes ago                       vigorous_benz

For example, my container ID is 808cdff86898.

From a separate terminal session(not the container one), copy the installer file to the container. Remember that this is only possible when the container is started. Therefore docker ps should return a container id. In case you stopped your container session you can always start it with

 $ sudo docker start -ai <container_id> 

Copy J-Link installer to the container.

 $ sudo docker cp JLink_Linux_x86_64.deb 808cdff86898:/home/JLink_Linux_x86_64.deb

Check that the file was successfully copied to the container and from the container command line install the previously downloaded package.

 root@808cdff86898:/# ls /home/
 root@808cdff86898:/# dpkg -i /home/JLink_Linux_V647f_x86_64.deb
 (Reading database ... 4385 files and directories currently installed.)
 Preparing to unpack .../JLink_Linux_V647f_x86_64.deb ...
 Removing /opt/SEGGER/JLink ...
 Unpacking jlink (6.476) over (6.476) ...
 Setting up jlink (6.476) ...
 root@808cdff86898:/# /opt/SEGGER/JLink/JLinkExe -autoconnect 1 -device Cortex-m7 -if swd -speed 4000
 SEGGER J-Link Commander V6.47f (Compiled Jul 22 2019 11:06:18)
 DLL version V6.47f, compiled Jul 22 2019 11:06:06
 Connecting to J-Link via USB...O.K.
 Firmware: J-Link V10 compiled Jul 23 2019 13:46:10
 Hardware version: V10.10
 S/N: 60000000
 License(s): RDI, FlashBP, FlashDL, JFlash, GDB
 Device "CORTEX-M7" selected.
 Connecting to target via SWD
 Found SW-DP with ID 0x0BD11477
 Scanning AP map to find all available APs
 AP[1]: Stopped AP scan as end of AP map has been reached
 AP[0]: AHB-AP (IDR: 0x04770041)
 Iterating through AP map to find AHB-AP to use
 AP[0]: Core found
 AP[0]: AHB-AP ROM base: 0xE00FD000 
 CPUID register: 0x411FC271. Implementer code: 0x41 (ARM)
 Found Cortex-M7 r1p1, Little endian.
 Cortex-M7 identified.

That's it. Now you can use J-Link in a Docker container for your testing and or development purposes.

Useful parameters in Docker

List all created containers

 $ docker ps -a 

List active containers

 $ docker ps

Stop a container

 $ docker stop <container_id> 

Remove a container

 $ docker rm <container_id>

Start a container

 $ sudo docker start -ai <container_id>

Stop all containers

 $ sudo docker stop $(sudo docker ps -a -q)

Remove all containers

 $ sudo docker rm $(sudo docker ps -a -q)

List local Docker images

 $ sudo docker images 

Search available images in the Docker Hub with ubuntu keyword

 $ sudo docker search ubuntu