Bookworm armhf cross compile docker: Difference between revisions
From embeddedTS Manuals
(Created page with "Debian only provides their cross compiler for their distribution. Our examples will set up a Docker for Debian to use for development. If using Debian 12 Bullseye natively, or...") |
No edit summary |
||
Line 1: | Line 1: | ||
Debian | Debian provides cross toolchains within their distribution for different architectures. If you are running a matching system you can | ||
For best portability we recommend using a container like docker to run a Debian 12 rootfs for the toolchain. On any Linux system first install docker. | |||
* Ubuntu/Debian: | |||
<source lang=bash> | |||
apt-get install docker -y | |||
</source> | |||
* Fedora | |||
<source lang=bash> | |||
dnf install docker -y | |||
</source> | |||
<source lang=bash> | |||
# Add your user to the docker group. You may need to logout/log back in. | |||
sudo usermod -aG docker $USER | |||
</source> | |||
Make sure you can run docker's hello world image to verify it is working: | |||
<source lang=bash> | |||
docker run hello-world | |||
</source> | |||
Now create a file "/opt/docker-toolchain/docker-debian-bookworm-armhf/Dockerfile" with these contents: | |||
<source lang=bash> | <source lang=bash> | ||
# syntax = docker/dockerfile:1.2 | # syntax = docker/dockerfile:1.2 | ||
Line 61: | Line 82: | ||
xz-utils | xz-utils | ||
# Provide a more friendly name | |||
ENV debian_chroot debian_bookworm | ENV debian_chroot debian_bookworm | ||
RUN echo "PS1='\${debian_chroot}\\[\033[01;32m\\]@\\H\[\\033[00m\\]:\\[\\033[01;34m\\]\\w\\[\\033[00m\\]\\$ '" >> /etc/bash.bashrc | RUN echo "PS1='\${debian_chroot}\\[\033[01;32m\\]@\\H\[\\033[00m\\]:\\[\\033[01;34m\\]\\w\\[\\033[00m\\]\\$ '" >> /etc/bash.bashrc | ||
# Set up locales | |||
RUN sed -i -e 's/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/' /etc/locale.gen && \ | RUN sed -i -e 's/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/' /etc/locale.gen && \ | ||
echo 'LANG="en_US.UTF-8"'>/etc/default/locale && \ | echo 'LANG="en_US.UTF-8"'>/etc/default/locale && \ | ||
dpkg-reconfigure --frontend=noninteractive locales && \ | dpkg-reconfigure --frontend=noninteractive locales && \ | ||
update-locale LANG=en_US.UTF-8 | update-locale LANG=en_US.UTF-8 | ||
ENV LC_ALL en_US.UTF-8 | ENV LC_ALL en_US.UTF-8 | ||
ENV LANG en_US.UTF-8 | ENV LANG en_US.UTF-8 | ||
ENV LANGUAGE en_US.UTF-8 | ENV LANGUAGE en_US.UTF-8 | ||
# Needed for make dtbs_check | |||
RUN pip3 install dtschema | RUN pip3 install dtschema | ||
</source> | |||
Finally, make a shell script to enter into this docker container. In /usr/local/bin/docker-debian-bookworm: | |||
<source lang=bash> | |||
#!/bin/bash -e | |||
# Enters a docker running Debian 12 Bookworm | |||
# Any arguments are run in the docker, or if no arguments it runs a shell | |||
export TAG=debian-bookworm-armdev | |||
SCRIPTPATH=$(readlink -f "$0") | |||
DOCKERPATH=$(dirname "$SCRIPTPATH")/../docker/debian-bookworm | |||
DOCKER_BUILDKIT=1 docker build --tag "$TAG" "$DOCKERPATH" --quiet | |||
exec docker run --rm \ | |||
-it \ | |||
--volume "$(pwd)":/work \ | |||
--user $(id -g):$(id -u) \ | |||
-w /work \ | |||
-e HOME=/tmp \ | |||
"$TAG" \ | |||
$@; | |||
</source> | </source> |
Revision as of 16:05, 5 January 2023
Debian provides cross toolchains within their distribution for different architectures. If you are running a matching system you can
For best portability we recommend using a container like docker to run a Debian 12 rootfs for the toolchain. On any Linux system first install docker.
- Ubuntu/Debian:
apt-get install docker -y
- Fedora
dnf install docker -y
# Add your user to the docker group. You may need to logout/log back in.
sudo usermod -aG docker $USER
Make sure you can run docker's hello world image to verify it is working:
docker run hello-world
Now create a file "/opt/docker-toolchain/docker-debian-bookworm-armhf/Dockerfile" with these contents:
# syntax = docker/dockerfile:1.2
FROM debian:bookworm
RUN dpkg --add-architecture armhf
RUN apt-get update && apt-get install -y \
autogen \
automake \
bash \
bc \
bison \
build-essential \
bzip2 \
ca-certificates \
ccache \
chrpath \
cpio \
curl \
diffstat \
fakeroot \
file \
flex \
gawk \
gcc-arm-linux-gnueabihf \
git \
gzip \
kmod \
libgpiod-dev:armhf \
libncursesw5-dev \
libssl-dev \
libtool \
libyaml-dev \
locales \
lz4 \
lzop \
make \
multistrap \
ncurses-dev \
pkg-config \
python3 \
python3-cbor \
python3-pexpect \
python3-pip \
qemu-user-static \
rsync \
runit \
socat \
srecord \
swig \
texinfo \
u-boot-tools \
zstd \
unzip \
vim \
wget \
xz-utils
# Provide a more friendly name
ENV debian_chroot debian_bookworm
RUN echo "PS1='\${debian_chroot}\\[\033[01;32m\\]@\\H\[\\033[00m\\]:\\[\\033[01;34m\\]\\w\\[\\033[00m\\]\\$ '" >> /etc/bash.bashrc
# Set up locales
RUN sed -i -e 's/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/' /etc/locale.gen && \
echo 'LANG="en_US.UTF-8"'>/etc/default/locale && \
dpkg-reconfigure --frontend=noninteractive locales && \
update-locale LANG=en_US.UTF-8
ENV LC_ALL en_US.UTF-8
ENV LANG en_US.UTF-8
ENV LANGUAGE en_US.UTF-8
# Needed for make dtbs_check
RUN pip3 install dtschema
Finally, make a shell script to enter into this docker container. In /usr/local/bin/docker-debian-bookworm:
#!/bin/bash -e
# Enters a docker running Debian 12 Bookworm
# Any arguments are run in the docker, or if no arguments it runs a shell
export TAG=debian-bookworm-armdev
SCRIPTPATH=$(readlink -f "$0")
DOCKERPATH=$(dirname "$SCRIPTPATH")/../docker/debian-bookworm
DOCKER_BUILDKIT=1 docker build --tag "$TAG" "$DOCKERPATH" --quiet
exec docker run --rm \
-it \
--volume "$(pwd)":/work \
--user $(id -g):$(id -u) \
-w /work \
-e HOME=/tmp \
"$TAG" \
$@;