From 53214ceb5721e502de072f7c57061fadb90e5365 Mon Sep 17 00:00:00 2001 From: xarantolus Date: Fri, 14 Feb 2025 16:04:24 +0000 Subject: [PATCH 1/2] Initial dev container configuration --- .devcontainer/Dockerfile | 73 +++++++++++++++++++++++++++++++++ .devcontainer/devcontainer.json | 23 +++++++++++ .gitignore | 2 +- 3 files changed, 97 insertions(+), 1 deletion(-) create mode 100644 .devcontainer/Dockerfile create mode 100644 .devcontainer/devcontainer.json diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile new file mode 100644 index 0000000..1def7d7 --- /dev/null +++ b/.devcontainer/Dockerfile @@ -0,0 +1,73 @@ +FROM fedora:latest + +# Install Development Tools and required packages +RUN dnf update -y && \ + dnf install -y @development-tools && \ + dnf install -y \ + direnv \ + arm-none-eabi-gcc-cs \ + arm-none-eabi-gcc-c++ \ + arm-none-eabi-newlib \ + cmake \ + git \ + python3 \ + python3-virtualenv \ + python3-pip \ + ninja-build \ + pkgconf \ + glib2-devel \ + flex \ + bison \ + clang \ + zlib-devel \ + meson \ + pixman-devel \ + alsa-lib-devel \ + texinfo \ + lzo-devel \ + snappy-devel \ + libaio-devel \ + libtasn1-devel \ + gnutls-devel \ + nettle-devel \ + curl \ + dtc \ + libcap-devel \ + libcap-ng-devel \ + socat \ + libslirp-devel \ + libffi-devel \ + ncurses-devel && \ + dnf clean all + +ARG USERNAME=vscode +RUN useradd -m -s /bin/bash ${USERNAME} && \ + echo "${USERNAME} ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers + +# Set working directory and switch to non-root user +WORKDIR /home/${USERNAME} +USER ${USERNAME} + +# Install Rust +RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y && \ + . $HOME/.cargo/env && \ + rustup component add rust-src && \ + rustup component add llvm-tools-preview && \ + cargo install cargo-binutils && \ + rustup target add thumbv7em-none-eabihf && \ + rustup target add thumbv7em-none-eabi + +# Clone, build, and install QEMU +RUN git clone --depth 1 https://github.com/thomasw04/qemu.git /tmp/qemu && \ + cd /tmp/qemu && \ + python3 -m venv .venv && \ + . .venv/bin/activate && \ + pip install --no-cache-dir tomli sphinx && \ + mkdir build && cd build && \ + ../configure --disable-werror --cc=clang --cxx=clang++ --extra-cflags="-Wno-error -fdeclspec" --target-list=arm-softmmu,arm-linux-user --enable-kvm && \ + make -j$(nproc) && \ + sudo make install && \ + cd / && \ + rm -rf /tmp/qemu + +CMD ["bash"] diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000..576989d --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,23 @@ +// For format details, see https://aka.ms/devcontainer.json. +{ + "name": "Nix Dev Container", + "build": { + "dockerfile": "Dockerfile", + "context": ".." + }, + "remoteUser": "vscode", + "privileged": false, + "customizations": { + "vscode": { + "extensions": [ + "rust-lang.rust-analyzer", + "vadimcn.vscode-lldb", + "ms-vscode.cmake-tools", + "llvm-vs-code-extensions.vscode-clangd" + ] + } + }, + "mounts": [ + "source=${localEnv:HOME}/.ssh,target=/home/vscode/.ssh,type=bind,consistency=cached" + ] +} diff --git a/.gitignore b/.gitignore index 467fd94..2988fc8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ -build/ +build*/ .vscode/ qemu/ .venv/ From 0489914902220f981d985f96e6a31c9afc981693 Mon Sep 17 00:00:00 2001 From: xarantolus Date: Fri, 14 Feb 2025 18:46:15 +0000 Subject: [PATCH 2/2] Hardware interaction from container --- .devcontainer/Dockerfile | 15 ++++++++++++++- .devcontainer/devcontainer.json | 12 +++++++++++- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index 1def7d7..ae5138a 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -37,9 +37,14 @@ RUN dnf update -y && \ socat \ libslirp-devel \ libffi-devel \ + libusb1-devel \ ncurses-devel && \ dnf clean all +RUN dnf install -y 'dnf-command(copr)' && \ + dnf copr enable -y rleh/arm-none-eabi-gdb && \ + dnf install -y arm-none-eabi-gdb + ARG USERNAME=vscode RUN useradd -m -s /bin/bash ${USERNAME} && \ echo "${USERNAME} ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers @@ -70,4 +75,12 @@ RUN git clone --depth 1 https://github.com/thomasw04/qemu.git /tmp/qemu && \ cd / && \ rm -rf /tmp/qemu -CMD ["bash"] +RUN git clone --single-branch --depth 1 -b "develop" \ + https://github.com/stlink-org/stlink.git /tmp/stlink && \ + cd /tmp/stlink && \ + make -j release && \ + sudo make install && \ + sudo ldconfig + +# Fix for fedora not finding libstlink.so.1 +ENV LD_LIBRARY_PATH=/usr/local/lib:/usr/local/lib64 diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 576989d..2ea96a9 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -1,12 +1,16 @@ // For format details, see https://aka.ms/devcontainer.json. { - "name": "Nix Dev Container", + "name": "Osiris Dev Container", "build": { "dockerfile": "Dockerfile", "context": ".." }, "remoteUser": "vscode", "privileged": false, + "capAdd": [ + // Permissions for accessing host USB devices + "SYS_RAWIO", "CAP_MKNOD" + ], "customizations": { "vscode": { "extensions": [ @@ -17,7 +21,13 @@ ] } }, + "runArgs": [ + // Mount USB devices under Linux + "--device", + "/dev/bus/usb:/dev/bus/usb" + ], "mounts": [ + // Make ssh keys available "source=${localEnv:HOME}/.ssh,target=/home/vscode/.ssh,type=bind,consistency=cached" ] }