Skip to content

Add Device Tree Compiler build #12

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ jobs:
bin/pico-sdk-tools-*-x64-win.zip
bin/openocd-*-x64-win.zip
bin/riscv-toolchain-*-x64-win.zip
bin/dtc-*-x64-win.zip
- name: Add Release Asset
uses: softprops/action-gh-release@v2
if: startsWith(github.ref, 'refs/tags/')
Expand All @@ -48,6 +49,7 @@ jobs:
bin/pico-sdk-tools-*-x64-win.zip
bin/openocd-*-x64-win.zip
bin/riscv-toolchain-*-x64-win.zip
bin/dtc-*-x64-win.zip

build_macos:
name: Build MacOS
Expand Down Expand Up @@ -81,6 +83,7 @@ jobs:
bin/pico-sdk-tools-*-mac.zip
bin/openocd-*-mac.zip
bin/riscv-toolchain-*.zip
bin/dtc-*-mac.tar.gz
- name: Add Release Asset
uses: softprops/action-gh-release@v2
if: startsWith(github.ref, 'refs/tags/')
Expand All @@ -90,6 +93,7 @@ jobs:
bin/pico-sdk-tools-*-mac.zip
bin/openocd-*-mac.zip
bin/riscv-toolchain-*.zip
bin/dtc-*-mac.tar.gz

build_linux:
name: Build Linux
Expand Down Expand Up @@ -120,6 +124,7 @@ jobs:
bin/pico-sdk-tools-*-lin.tar.gz
bin/openocd-*-lin.tar.gz
bin/riscv-toolchain-*-lin.tar.gz
bin/dtc-*-lin.tar.gz
- name: Add Release Asset
uses: softprops/action-gh-release@v2
if: startsWith(github.ref, 'refs/tags/')
Expand All @@ -129,3 +134,4 @@ jobs:
bin/pico-sdk-tools-*-lin.tar.gz
bin/openocd-*-lin.tar.gz
bin/riscv-toolchain-*-lin.tar.gz
bin/dtc-*-lin.tar.gz
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ The tools currently included are:
* **OpenOCD** (includes `linuxgpiod` and `cmsis-dap` adapters)
* **pioasm**
* **RISC-V Toolchain**
* **Device Tree Compiler**
51 changes: 40 additions & 11 deletions build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ if (-not $SkipDownload) {
# Normal update
msys 'pacman --noconfirm -Suu'

msys "pacman -S --noconfirm --needed autoconf automake base-devel expat git libtool pactoys patchutils pkg-config"
msys "pacman -S --noconfirm --needed autoconf automake base-devel expat git libtool pactoys patchutils pkg-config bison flex"
# pacboy adds MINGW_PACKAGE_PREFIX to package names suffixed with :p
msys "pacboy -S --noconfirm --needed cmake:p ninja:p toolchain:p libusb:p hidapi:p libslirp:p"
}
Expand All @@ -221,15 +221,26 @@ if (-not (Test-Path ".\build\openocd-install\$msysEnv") -and ($env:SKIP_OPENOCD
msys "cd build && ../packages/windows/openocd/build-openocd.sh"
}

if (-not (Test-Path ".\build\picotool-install\$msysEnv")) {
msys "cd build && ../packages/windows/picotool/build-picotool.sh $version"
#if (-not (Test-Path ".\build\picotool-install\$msysEnv")) {
# msys "cd build && ../packages/windows/picotool/build-picotool.sh $version"
#}

if (-not (Test-Path ".\build\dtc-install\$msysEnv")) {
msys "cd build && ../packages/windows/dtc/build-dtc.sh $version"
}

if ($version.Substring(0, 1) -ge 2) {
# Sign files before packaging up the installer
sign "build\openocd-install\$msysEnv\bin\openocd.exe",
"build\pico-sdk-tools\$msysEnv\pioasm\pioasm.exe",
"build\picotool-install\$msysEnv\picotool\picotool.exe"
"build\picotool-install\$msysEnv\picotool\picotool.exe",
"build\dtc-install\$msysEnv\bin\dtc.exe",
"build\dtc-install\$msysEnv\bin\convert-dtsv0.exe",
"build\dtc-install\$msysEnv\bin\dtdiff.exe",
"build\dtc-install\$msysEnv\bin\fdtdump.exe",
"build\dtc-install\$msysEnv\bin\fdtget.exe",
"build\dtc-install\$msysEnv\bin\fdtoverlay.exe",
"build\dtc-install\$msysEnv\bin\fdtput.exe"
} else {
$template = Get-Content ".\packages\windows\pico-sdk-tools\pico-sdk-tools-config-version.cmake" -Raw
$ExecutionContext.InvokeCommand.ExpandString($template) | Set-Content ".\build\pico-sdk-tools\$msysEnv\pico-sdk-tools-config-version.cmake"
Expand All @@ -238,7 +249,14 @@ if ($version.Substring(0, 1) -ge 2) {
sign "build\openocd-install\$msysEnv\bin\openocd.exe",
"build\pico-sdk-tools\$msysEnv\elf2uf2.exe",
"build\pico-sdk-tools\$msysEnv\pioasm.exe",
"build\picotool-install\$msysEnv\picotool.exe"
"build\picotool-install\$msysEnv\picotool.exe",
"build\dtc-install\$msysEnv\bin\dtc.exe",
"build\dtc-install\$msysEnv\bin\convert-dtsv0.exe",
"build\dtc-install\$msysEnv\bin\dtdiff.exe",
"build\dtc-install\$msysEnv\bin\fdtdump.exe",
"build\dtc-install\$msysEnv\bin\fdtget.exe",
"build\dtc-install\$msysEnv\bin\fdtoverlay.exe",
"build\dtc-install\$msysEnv\bin\fdtput.exe"
}

# Package pico-sdk-tools separately as well
Expand All @@ -252,15 +270,26 @@ exec { tar -a -cf "bin\$filename" -C "build\pico-sdk-tools\$msysEnv" '*' }

# Package picotool separately as well

$version = (cmd /c ".\build\picotool-install\$msysEnv\picotool\picotool.exe" version -s '2>&1')
Write-Host "Picotool version $version"
#$version = (cmd /c ".\build\picotool-install\$msysEnv\picotool\picotool.exe" version -s '2>&1')
#Write-Host "Picotool version $version"

#$filename = 'picotool-{0}-{1}.zip' -f
# $version,
# $suffix

#Write-Host "Saving picotool package to $filename"
#exec { tar -a -cf "bin\$filename" -C "build\picotool-install\$msysEnv" '*' }

$filename = 'picotool-{0}-{1}.zip' -f
# Package dtc separately as well
$versionOutput = & ".\build\dtc-install\$msysEnv\bin\dtc.exe" --version
$version = $versionOutput -split '\s+' | Select-Object -Last 1
Write-Host "DTC version $version"

$filename = 'dtc-{0}-{1}.zip' -f
$version,
$suffix

Write-Host "Saving picotool package to $filename"
exec { tar -a -cf "bin\$filename" -C "build\picotool-install\$msysEnv" '*' }
Write-Host "Saving DTC package to $filename"
exec { tar -a -cf "bin\$filename" -C "build\dtc-install\$msysEnv" '*' }

if ($env:SKIP_OPENOCD -ne '1') {
# Package OpenOCD separately as well
Expand Down
28 changes: 19 additions & 9 deletions build_linux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ SKIP_RISCV=${SKIP_RISCV-0}
SKIP_OPENOCD=${SKIP_OPENOCD-0}

# Install prerequisites
sudo apt install -y jq cmake libtool automake libusb-1.0-0-dev libhidapi-dev libftdi1-dev
sudo apt install -y jq cmake libtool automake libusb-1.0-0-dev libhidapi-dev libftdi1-dev bison flex
# RISC-V prerequisites
sudo apt install -y autoconf automake autotools-dev curl python3 python3-pip libmpc-dev libmpfr-dev libgmp-dev gawk build-essential bison flex texinfo gperf libtool patchutils bc zlib1g-dev ninja-build git cmake libglib2.0-dev libslirp-dev
# RPi Only prerequisites
Expand Down Expand Up @@ -50,7 +50,8 @@ if [[ "$SKIP_RISCV" != 1 ]]; then
# Takes ages to build
../packages/linux/riscv/build-riscv-gcc.sh
fi
../packages/linux/picotool/build-picotool.sh
#../packages/linux/picotool/build-picotool.sh
../packages/linux/dtc/build-dtc.sh
cd ..

topd=$PWD
Expand All @@ -67,13 +68,22 @@ if [ ${version:0:1} -ge 2 ]; then
fi

# Package picotool separately as well
version=$("./$builddir/picotool-install/picotool/picotool" version -s)
echo "Picotool version $version"

filename="picotool-${version}-${suffix}.tar.gz"

echo "Saving picotool package to $filename"
pushd "$builddir/picotool-install/"
#version=$("./$builddir/picotool-install/picotool/picotool" version -s)
#echo "Picotool version $version"

#filename="picotool-${version}-${suffix}.tar.gz"

#echo "Saving picotool package to $filename"
#pushd "$builddir/picotool-install/"
#tar -a -cf "$topd/bin/$filename" * .keep
#popd

# Package dtc separately as well
version=$("./$builddir/dtc-install/bin/dtc" --version | awk '{print $3}')
echo "Device Tree Compiler version $version"
filename="dtc-${version}-${suffix}.zip"
echo "Saving dtc package to $filename"
pushd "$builddir/dtc-install/"
tar -a -cf "$topd/bin/$filename" * .keep
popd

Expand Down
38 changes: 25 additions & 13 deletions build_macos.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ SKIP_RISCV=${SKIP_RISCV-0}
SKIP_OPENOCD=${SKIP_OPENOCD-0}

# Install prerequisites
arch -x86_64 /usr/local/bin/brew install jq libtool libusb automake hidapi --quiet
arch -arm64 /opt/homebrew/bin/brew install jq libtool libusb automake hidapi --quiet
arch -x86_64 /usr/local/bin/brew install jq libtool libusb automake hidapi bison flex pkgconf --quiet
arch -arm64 /opt/homebrew/bin/brew install jq libtool libusb automake hidapi bison flex pkgconf --quiet
# RISC-V prerequisites
echo "Listing local"
ls /usr/local/bin
Expand Down Expand Up @@ -57,9 +57,12 @@ if [[ "$SKIP_RISCV" != 1 ]]; then
# Takes ages to build
../packages/macos/riscv/build-riscv-gcc.sh
fi
arch -x86_64 ../packages/macos/picotool/build-picotool.sh
arch -arm64 ../packages/macos/picotool/build-picotool.sh
../packages/macos/picotool/merge-picotool.sh
#arch -x86_64 ../packages/macos/picotool/build-picotool.sh
#arch -arm64 ../packages/macos/picotool/build-picotool.sh
#../packages/macos/picotool/merge-picotool.sh

arch -x86_64 ../packages/macos/dtc/build-dtc.sh
arch -arm64 ../packages/macos/dtc/build-dtc.sh
cd ..

topd=$PWD
Expand All @@ -75,14 +78,23 @@ if [ ${version:0:1} -ge 2 ]; then
fi

# Package picotool separately as well
version=$("./$builddir/picotool-install/picotool/picotool" version -s)
echo "Picotool version $version"

filename="picotool-${version}-${suffix}.zip"

echo "Saving picotool package to $filename"
pushd "$builddir/picotool-install/"
tar -a -cf "$topd/bin/$filename" * .keep
#version=$("./$builddir/picotool-install/picotool/picotool" version -s)
#echo "Picotool version $version"

#filename="picotool-${version}-${suffix}.zip"

#echo "Saving picotool package to $filename"
#pushd "$builddir/picotool-install/"
#tar -a -cf "$topd/bin/$filename" * .keep
#popd

# Package dtc separately as well
version=$("./$builddir/dtc-install/bin/dtc" --version | awk '{print $3}')
echo "Device Tree Compiler version $version"
filename="dtc-${version}-${suffix}.zip"
echo "Saving dtc package to $filename"
pushd "$builddir/dtc-install/"
zip -yr "$topd/bin/$filename" * .keep
popd

if [[ "$SKIP_OPENOCD" != 1 ]] && [[ $(uname -m) == 'arm64' ]]; then
Expand Down
4 changes: 4 additions & 0 deletions config/repositories.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
{
"href": "https://github.com/gcc-mirror/gcc",
"tree": "releases/gcc-14"
},
{
"href": "https://git.kernel.org/pub/scm/utils/dtc/dtc.git",
"tree": "v1.7.2"
}
]
}
12 changes: 12 additions & 0 deletions packages/linux/dtc/build-dtc.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash

set -euo pipefail

cd dtc

# build
make clean
make -j$(nproc) NO_PYTHON=1

INSTALLDIR="$PWD/../dtc-install"
make NO_PYTHON=1 DESTDIR="$INSTALLDIR" PREFIX="" install
59 changes: 59 additions & 0 deletions packages/macos/dtc/build-dtc.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/bin/zsh

set -euo pipefail

# Drop git repo of dtc as we use brew to build
rm -rf dtc
mkdir -p dtc-install
cd dtc-install

arch -x86_64 /usr/local/bin/brew install --build-from-source dtc
arch -arm64 /opt/homebrew/bin/brew install --build-from-source dtc

# Copy the dtc binaries to the build directory
BREW_PREFIX_X86=$(arch -x86_64 /usr/local/bin/brew --prefix)
BREW_PREFIX_ARM64=$(arch -arm64 /opt/homebrew/bin/brew --prefix)

cp -R "$BREW_PREFIX_X86/Cellar/dtc/$(arch -x86_64 /usr/local/bin/brew list --versions dtc | awk '{print $2}')" ./dtc-x86
cp -R "$BREW_PREFIX_ARM64/Cellar/dtc/$(arch -arm64 /opt/homebrew/bin/brew list --versions dtc | awk '{print $2}')" ./dtc-arm64

# Create universal distribution
mkdir -p dtc-universal/{bin,lib}

for binary in dtc fdtdump fdtoverlay fdtput fdtget dtdiff convert-dtsv0; do
lipo -create \
dtc-arm64/bin/$binary \
dtc-x86/bin/$binary \
-output dtc-universal/bin/$binary
done

VERSIONED_DYLIB=$(basename "$(find dtc-arm64/lib -name 'libfdt.dylib.*' | head -n 1)")

lipo -create \
dtc-arm64/lib/$VERSIONED_DYLIB \
dtc-x86/lib/$VERSIONED_DYLIB \
-output dtc-universal/lib/$VERSIONED_DYLIB

lipo -create \
dtc-arm64/lib/libfdt.a \
dtc-x86/lib/libfdt.a \
-output dtc-universal/lib/libfdt.a

# Recreate symlinks
cd dtc-universal/lib
ln -sf $VERSIONED_DYLIB libfdt.1.dylib
ln -sf libfdt.1.dylib libfdt.dylib
cd ../../

cp -R dtc-arm64/include dtc-universal/
cp -R dtc-arm64/README.md dtc-universal/

# clean up
rm -rf dtc-arm64
rm -rf dtc-x86

# move every folder and file from dtc-universal to .
mv dtc-universal/* .
rmdir dtc-universal

cd ..
15 changes: 15 additions & 0 deletions packages/windows/dtc/build-dtc.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash

set -euo pipefail

BUILDDIR=$(pwd)
INSTALLDIR="dtc-install"

cd dtc
make clean
make -j$(nproc) NO_PYTHON=1

make NO_PYTHON=1 DESTDIR="$BUILDDIR/$INSTALLDIR" PREFIX="" install

cd "$BUILDDIR/$INSTALLDIR/${MSYSTEM,,}/bin"
"$BUILDDIR/../packages/windows/copy-deps.sh"
Loading