Crossdev build environment for Raspberry Pi Pico on Gentoo
The Gentoo wiki page on Crossdev is lacking some essential details for me, and after naturally emerge-ing the package, then trying to create the repository it would always error with hardly documented information.
Most probably there was a reason hidden somewhere inside my setup, but I was unable to resolve it for several years. It was not really necessary and I would always postpone learning the usage, until I got hands on a pico, wanting to run C++ code on it.
The necessary target is called arm-none-eabi, while the repo name can be chosen with one’s own taste, such as crosspico as below.
The script below chooses the /usr/arm-none-eabi path as the root for the crossdev build environment and
- Creates the portage repository.
- Creates the minimal portage description files of the repository inside the
/usr/arm-none-eabi/etc/portage. - Sets the
make.profile. It probably needs to be the symlink of the current host profile. In my case it was23.0/desktop.
Perhaps it is necessary to make additional customizations before starting the build process of the environment, it is useful to call the crossdev command with extra argument --init-target, which will initialize the full target, before building glibc, gcc, and rest of the excellent tools.
The working example of the script can also be found on my github.
1#! /bin/bash
2REPO="crosspico"
3TARGET="arm-none-eabi"
4mkdir -p /usr/${TARGET}/var/db/repos/${REPO}/{profiles,metadata}
5
6echo ${REPO} > /usr/${TARGET}/var/db/repos/${REPO}/profiles/repo_name
7echo "masters = gentoo" > /usr/${TARGET}/var/db/repos/${REPO}/metadata/layout.conf
8chown -R portage:portage /usr/${TARGET}/var/db/repos/${REPO}
9
10mkdir -p /usr/${TARGET}/etc/portage/repos.conf
11
12echo "[${REPO}]" > /usr/${TARGET}/etc/portage/repos.conf/${REPO}.conf
13echo "location = /usr/${TARGET}/var/db/repos/${REPO}" >> /usr/${TARGET}/etc/portage/repos.conf/${REPO}.conf
14echo "priority = 10" >> /usr/${TARGET}/etc/portage/repos.conf/${REPO}.conf
15echo "masters = gentoo" >> /usr/${TARGET}/etc/portage/repos.conf/${REPO}.conf
16echo "auto-sync = no" >> /usr/${TARGET}/etc/portage/repos.conf/${REPO}.conf
17
18mkdir -p /usr/${TARGET}/etc/portage/cross-${TARGET}
19
20#rm "/usr/${TARGET}/etc/portage/make.profile"
21ln -s /var/db/repos/gentoo/profiles/default/linux/arm64/23.0/desktop /usr/${TARGET}/etc/portage/make.profile
22
23PORTAGE_CONFIGROOT=/usr/${TARGET} crossdev -S --target ${TARGET} --overlays "${REPO}" --ov-output "/usr/${TARGET}/var/db/repos/" --init-target
24PORTAGE_CONFIGROOT=/usr/${TARGET} crossdev -S --target ${TARGET} --overlays "${REPO}" --ov-output "/usr/${TARGET}/var/db/repos/"
