{"id":13343806,"url":"https://github.com/Scottapotamas/docker-riscv-zephyr","last_synced_at":"2025-03-12T06:30:30.000Z","repository":{"id":144752408,"uuid":"286778252","full_name":"Scottapotamas/docker-riscv-zephyr","owner":"Scottapotamas","description":"Docker container specifically for building Zephyr projects and flashing them to RISC-V dev-kits.","archived":false,"fork":false,"pushed_at":"2020-08-11T15:46:18.000Z","size":9,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-10-24T16:49:21.417Z","etag":null,"topics":["docker","microcontroller","risc-v","zephyr-rtos"],"latest_commit_sha":null,"homepage":"","language":"Dockerfile","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Scottapotamas.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-08-11T15:19:33.000Z","updated_at":"2022-04-11T19:45:10.000Z","dependencies_parsed_at":"2023-06-01T10:30:56.614Z","dependency_job_id":null,"html_url":"https://github.com/Scottapotamas/docker-riscv-zephyr","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Scottapotamas%2Fdocker-riscv-zephyr","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Scottapotamas%2Fdocker-riscv-zephyr/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Scottapotamas%2Fdocker-riscv-zephyr/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Scottapotamas%2Fdocker-riscv-zephyr/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Scottapotamas","download_url":"https://codeload.github.com/Scottapotamas/docker-riscv-zephyr/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243171373,"owners_count":20247876,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["docker","microcontroller","risc-v","zephyr-rtos"],"created_at":"2024-07-29T19:32:01.231Z","updated_at":"2025-03-12T06:30:29.992Z","avatar_url":"https://github.com/Scottapotamas.png","language":"Dockerfile","funding_links":[],"categories":[],"sub_categories":[],"readme":"# RISC-V Zephyr Docker\n\nBuild [Zephyr](https://www.zephyrproject.org/) firmware projects and flash (specifically RISC-V) targets from a Docker container! \n\nIntended for development tests without mangling the local machine, and allows CI build and flash sequences.\n\n___\n\n***Why?***\n\nCompared to other publicly available Zephyr docker images, *this* container's benefits are (at time of writing) age and specificity:\n\n- Tested against the [Sparkfun RED-V Thing Plus](https://www.sparkfun.com/products/15799) (`FE310-G002`), and [used in production](https://electricui.com/blog/hardware-testing).\n  - Environment setup is similar to the [Sparkfun RED-V development guide](https://learn.sparkfun.com/tutorials/red-v-development-guide) with some bug fixes and QoL improvements.\n- Includes the latest SEGGER J-Link tools needed to interface with the [RED-V's onboard J-Link programmer](https://wiki.segger.com/J-Link-OB-K22-SiFive).\n- Exists outside of the official Zephyr docker images, which means it doesn't bundle extra weight for building/testing Zephyr itself, or unnecessary compilers etc.\n\n- No hardcoded version/dependencies - uses some bash tricks to ensure we use the latest (stable) Zephyr SDK and J-Link tools when building the docker container.\n\n# Usage\n\nAssumes you have Docker setup on your machine already. If not, see [Docker: Orientation and setup](https://docs.docker.com/get-started/).\n\nBuild the docker image from the Dockerfile: `docker build --tag riscv-zephyr:0.4 .`\n\nUse the toolchain interactively: `docker run -i --privileged --rm -v $PWD:/project -w /project riscv-zephyr:0.4`\n\n\u003e We use `-i --privileged` to allow the container access over all USB devices. This is considered a insecure in general use, so consider only [providing the required hardware](https://stackoverflow.com/questions/24225647/docker-a-way-to-give-access-to-a-host-usb-or-serial-device).\n\u003e\n\u003e The onboard J-Link programmer on the RED-V is listed by `lsusb` as `1366:1061 SEGGER HiFive`, and presents as a pair of `/dev/ttyACMx` entries (UART passthrough, and the JTAG programmer respectively).\n\n## Build/Flash/Run Example\n\nThis is provided as reference for a working build/flash output. Run the following while using the docker container interactively as described above:\n\n1. `west init testproject`\n\n2. `cd testproject`\n\n3. `west update`\n\n4. `pip3 install -r zephyr/scripts/requirements.txt`\n\n5. `west build -b hifive1_revb samples/hello_world`\n\n6. `west flash`\n\n   ```\n   -- west flash: rebuilding\n   [0/1] cd /project/hello-electricui/zephyr/build/zephyr/cmake/flash \u0026\u0026 /usr/bin/cmake -E echo\n   \n   -- west flash: using runner jlink\n   -- runners.jlink: Flashing file: /project/hello-electricui/zephyr/build/zephyr/zephyr.bin\n   SEGGER J-Link Commander V6.82c (Compiled Jul 31 2020 17:40:13)\n   DLL version V6.82c, compiled Jul 31 2020 17:40:02\n   \n   J-Link Command File read successfully.\n   Processing script file...\n   \n   J-Link connection not established yet but required for command.\n   Connecting to J-Link via USB...O.K.\n   Firmware: J-Link OB-K22-SiFive compiled Jun 17 2020 14:52:05\n   Hardware version: V1.00\n   S/N: 979004978\n   VTref=3.300V\n   Target connection not established yet but required for command.\n   Device \"FE310\" selected.\n   \n   Connecting to target via JTAG\n   ConfigTargetSettings() start\n   ConfigTargetSettings() end\n   TotalIRLen = 5, IRPrint = 0x01\n   JTAG chain detection found 1 devices:\n    #0 Id: 0x20000913, IRLen: 05, Unknown device\n   Debug architecture:\n     RISC-V debug: 0.13\n     AddrBits: 7\n     DataBits: 32\n     IdleClks: 5\n   Memory access:\n     Via system bus: No\n     Via ProgBuf: Yes (16 ProgBuf entries)\n   DataBuf: 1 entries\n     autoexec[0] implemented: Yes\n   Detected: RV32 core\n   CSR access via abs. commands: No\n   Temp. halted CPU for NumHWBP detection\n   HW instruction/data BPs: 8\n   Support set/clr BPs while running: No\n   HW data BPs trigger before execution of inst\n   RISC-V identified.\n   Reset delay: 0 ms\n   Reset type Normal: Resets core \u0026 peripherals using \u003cndmreset\u003e bit in \u003cdmcontrol\u003e debug register.\n   RISC-V: Performing reset via \u003cndmreset\u003e\n   \n   Downloading file [/project/hello-electricui/zephyr/build/zephyr/zephyr.bin]...\n   /opt/SEGGER/JLink_V682c/JLinkGUIServerExe: error while loading shared libraries: libSM.so.6: cannot open shared object file: No such file or directory\n   J-Link: Flash download: Bank 0 @ 0x20000000: 1 range affected (65536 bytes)\n   J-Link: Flash download: Total: 1.183s (Prepare: 0.384s, Compare: 0.320s, Erase: 0.137s, Program \u0026 Verify: 0.328s, Restore: 0.013s)\n   J-Link: Flash download: Program \u0026 Verify speed: 194 KB/s\n   O.K.\n   \n   Writing DP register 1 = 0x00000000 (0 write repetitions needed)\n   Reading DP register 1 = 0x00000001 (0 read repetitions needed)\n   \n   Script processing completed.\n   ```\n\n7. Connect to the programmer's passthrough serial port (`/dev/ttyACM0` for me) with a serial terminal at `115200 baud` and the board should output the following at boot:\n\n   ```\n   ATE0--\u003eSend Flag Timed Out Busy. Giving Up.\n    Send Flag error: #0 #0 #0 #0 AT+BLEINIT=0--\u003eSend Flag Timed Out Busy. Giving Up.\n    Send Flag error: #0 #0 #0 #0 AT+CWMODE=0--\u003eSend Flag Timed Out Busy. Giving Up.\n    Send Flag error: #0 #0 #0 #0 \n   *** Booting Zephyr OS build zephyr-v2.3.0-1733-g9df168b53569  ***\n   Hello World! hifive1_revb\n   ```\n\nThat's it!\n\n# Troubleshooting\n\n## J-Link does not support selecting another hart/core\n\nAt time of writing (Aug 2020) the Sparkfun RED-V Thing Plus didn't work out of the box with recent Segger JLink tooling (validated against two separate boards).\n\nWhen running `west flash` to burn a firmware file, errors like this are output:\n\n```\nConnecting to J-Link via USB...JLinkGUIServerExe: cannot connect to X server \nO.K.\nFirmware: J-Link OB-K22-SiFive compiled Feb 28 2019 12:46:23\nHardware version: V1.00\nS/N: 979004978\nVTref=3.300V\nTarget connection not established yet but required for command.\nDevice \"FE310\" selected.\n\n[... removed JTAG Chain detection output which successfully detects the RV32 core etcc ...]\n\n****** Error: The connected J-Link does not support selecting another hart/core than 0 for RISC-V\nSpecific core setup failed.\nCannot connect to target.\n\nTarget connection not established yet but required for command.\nDevice \"FE310\" selected.\n\n```\n\nThe solution is to **update the devkit's onboard J-Link programmer firmware**.\n\nI didn't do this through the docker container, as CLI based update instructions aren't easy to find.\n\n\u003e I've used J-Link V6.82c as it was the most up to date, but reading suggests anything \u003eV6.50 should resolve these issues...\n\n1. On my native workstation, with J-Link V6.82c running, run `JLinkConfigExe`.\n2. The GUI will launch, showing Segger programmer images, some empty lists/boxes and simple buttons. \n   - Look for hardware in the \"Connected via USB\" area.\n3. Unplug and replug USB if it wasn't found, mine wasn't found immediately. You should see `J-Link OB-K22-SiFive [...]` in the list.\n   - My board showed an older probe version dated `2019 Feb`.\n\n4. Select the listed unit, then click `Update firmware of selected probes and programmers`.\n5. Wait for the update to complete. Once done, the probe firmware was listed as built on `2020 June 17 14:52`.\n6. Close the tool. Plug/unplug the board to properly power cycle everything.\n7. Reattempt flashing the target with `west flash` inside the Docker container.\n\n## J-Link Failed to open DLL\n\nAfter resolving the J-Link firmware version issues, this might appear:\n\n```\nJ-Link connection not established yet but required for command.\nConnecting to J-Link via USB...FAILED: Failed to open DLL\n```\n\nIn my case, this worked after I had ensured Zephyr was up to date and properly installed. From a project (`west init testproject` then `cd testproject`), ensure the python requirements have actually been installed!\n\n```\nwest update\nsudo pip3 install -r zephyr/scripts/requirements.txt\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FScottapotamas%2Fdocker-riscv-zephyr","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FScottapotamas%2Fdocker-riscv-zephyr","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FScottapotamas%2Fdocker-riscv-zephyr/lists"}