Skip to content

Commit 95c05a4

Browse files
committed
Added dtc build
Signed-off-by: paulober <[email protected]>
1 parent 4df55fd commit 95c05a4

File tree

9 files changed

+154
-6
lines changed

9 files changed

+154
-6
lines changed

.github/workflows/build.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ jobs:
3939
bin/pico-sdk-tools-*-x64-win.zip
4040
bin/openocd-*-x64-win.zip
4141
bin/riscv-toolchain-*-x64-win.zip
42+
bin/dtc-*-x64-win.zip
4243
- name: Add Release Asset
4344
uses: softprops/action-gh-release@v2
4445
if: startsWith(github.ref, 'refs/tags/')
@@ -48,6 +49,7 @@ jobs:
4849
bin/pico-sdk-tools-*-x64-win.zip
4950
bin/openocd-*-x64-win.zip
5051
bin/riscv-toolchain-*-x64-win.zip
52+
bin/dtc-*-x64-win.zip
5153
5254
build_macos:
5355
name: Build MacOS
@@ -81,6 +83,7 @@ jobs:
8183
bin/pico-sdk-tools-*-mac.zip
8284
bin/openocd-*-mac.zip
8385
bin/riscv-toolchain-*.zip
86+
bin/dtc-*-mac.tar.gz
8487
- name: Add Release Asset
8588
uses: softprops/action-gh-release@v2
8689
if: startsWith(github.ref, 'refs/tags/')
@@ -90,6 +93,7 @@ jobs:
9093
bin/pico-sdk-tools-*-mac.zip
9194
bin/openocd-*-mac.zip
9295
bin/riscv-toolchain-*.zip
96+
bin/dtc-*-mac.tar.gz
9397
9498
build_linux:
9599
name: Build Linux
@@ -120,6 +124,7 @@ jobs:
120124
bin/pico-sdk-tools-*-lin.tar.gz
121125
bin/openocd-*-lin.tar.gz
122126
bin/riscv-toolchain-*-lin.tar.gz
127+
bin/dtc-*-lin.tar.gz
123128
- name: Add Release Asset
124129
uses: softprops/action-gh-release@v2
125130
if: startsWith(github.ref, 'refs/tags/')
@@ -129,3 +134,4 @@ jobs:
129134
bin/pico-sdk-tools-*-lin.tar.gz
130135
bin/openocd-*-lin.tar.gz
131136
bin/riscv-toolchain-*-lin.tar.gz
137+
bin/dtc-*-lin.tar.gz

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ The tools currently included are:
88
* **OpenOCD** (includes `linuxgpiod` and `cmsis-dap` adapters)
99
* **pioasm**
1010
* **RISC-V Toolchain**
11+
* **Device Tree Compiler**

build.ps1

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ if (-not $SkipDownload) {
208208
# Normal update
209209
msys 'pacman --noconfirm -Suu'
210210

211-
msys "pacman -S --noconfirm --needed autoconf automake base-devel expat git libtool pactoys patchutils pkg-config"
211+
msys "pacman -S --noconfirm --needed autoconf automake base-devel expat git libtool pactoys patchutils pkg-config bison flex"
212212
# pacboy adds MINGW_PACKAGE_PREFIX to package names suffixed with :p
213213
msys "pacboy -S --noconfirm --needed cmake:p ninja:p toolchain:p libusb:p hidapi:p libslirp:p"
214214
}
@@ -225,11 +225,22 @@ if (-not (Test-Path ".\build\picotool-install\$msysEnv")) {
225225
msys "cd build && ../packages/windows/picotool/build-picotool.sh $version"
226226
}
227227

228+
if (-not (Test-Path ".\build\dtc-install\$msysEnv")) {
229+
msys "cd build && ../packages/windows/dtc/build-dtc.sh $version"
230+
}
231+
228232
if ($version.Substring(0, 1) -ge 2) {
229233
# Sign files before packaging up the installer
230234
sign "build\openocd-install\$msysEnv\bin\openocd.exe",
231235
"build\pico-sdk-tools\$msysEnv\pioasm\pioasm.exe",
232-
"build\picotool-install\$msysEnv\picotool\picotool.exe"
236+
"build\picotool-install\$msysEnv\picotool\picotool.exe",
237+
"build\dtc-install\$msysEnv\bin\dtc.exe",
238+
"build\dtc-install\$msysEnv\bin\convert-dtsv0.exe",
239+
"build\dtc-install\$msysEnv\bin\dtdiff.exe",
240+
"build\dtc-install\$msysEnv\bin\fdtdump.exe",
241+
"build\dtc-install\$msysEnv\bin\fdtget.exe",
242+
"build\dtc-install\$msysEnv\bin\fdtoverlay.exe",
243+
"build\dtc-install\$msysEnv\bin\fdtput.exe"
233244
} else {
234245
$template = Get-Content ".\packages\windows\pico-sdk-tools\pico-sdk-tools-config-version.cmake" -Raw
235246
$ExecutionContext.InvokeCommand.ExpandString($template) | Set-Content ".\build\pico-sdk-tools\$msysEnv\pico-sdk-tools-config-version.cmake"
@@ -238,7 +249,14 @@ if ($version.Substring(0, 1) -ge 2) {
238249
sign "build\openocd-install\$msysEnv\bin\openocd.exe",
239250
"build\pico-sdk-tools\$msysEnv\elf2uf2.exe",
240251
"build\pico-sdk-tools\$msysEnv\pioasm.exe",
241-
"build\picotool-install\$msysEnv\picotool.exe"
252+
"build\picotool-install\$msysEnv\picotool.exe",
253+
"build\dtc-install\$msysEnv\bin\dtc.exe",
254+
"build\dtc-install\$msysEnv\bin\convert-dtsv0.exe",
255+
"build\dtc-install\$msysEnv\bin\dtdiff.exe",
256+
"build\dtc-install\$msysEnv\bin\fdtdump.exe",
257+
"build\dtc-install\$msysEnv\bin\fdtget.exe",
258+
"build\dtc-install\$msysEnv\bin\fdtoverlay.exe",
259+
"build\dtc-install\$msysEnv\bin\fdtput.exe"
242260
}
243261

244262
# Package pico-sdk-tools separately as well
@@ -262,6 +280,17 @@ $filename = 'picotool-{0}-{1}.zip' -f
262280
Write-Host "Saving picotool package to $filename"
263281
exec { tar -a -cf "bin\$filename" -C "build\picotool-install\$msysEnv" '*' }
264282

283+
# Package dtc separately as well
284+
$versionOutput = & ".\build\dtc-install\$msysEnv\bin\dtc.exe" --version
285+
$version = $versionOutput -split '\s+' | Select-Object -Last 1
286+
Write-Host "DTC version $version"
287+
288+
$filename = 'dtc-{0}-{1}.zip' -f
289+
$version,
290+
$suffix
291+
Write-Host "Saving DTC package to $filename"
292+
exec { tar -a -cf "bin\$filename" -C "build\dtc-install\$msysEnv" '*' }
293+
265294
if ($env:SKIP_OPENOCD -ne '1') {
266295
# Package OpenOCD separately as well
267296

build_linux.sh

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ SKIP_RISCV=${SKIP_RISCV-0}
77
SKIP_OPENOCD=${SKIP_OPENOCD-0}
88

99
# Install prerequisites
10-
sudo apt install -y jq cmake libtool automake libusb-1.0-0-dev libhidapi-dev libftdi1-dev
10+
sudo apt install -y jq cmake libtool automake libusb-1.0-0-dev libhidapi-dev libftdi1-dev bison flex
1111
# RISC-V prerequisites
1212
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
1313
# RPi Only prerequisites
@@ -51,6 +51,7 @@ if [[ "$SKIP_RISCV" != 1 ]]; then
5151
../packages/linux/riscv/build-riscv-gcc.sh
5252
fi
5353
../packages/linux/picotool/build-picotool.sh
54+
../packages/linux/dtc/build-dtc.sh
5455
cd ..
5556

5657
topd=$PWD
@@ -77,6 +78,15 @@ pushd "$builddir/picotool-install/"
7778
tar -a -cf "$topd/bin/$filename" * .keep
7879
popd
7980

81+
# Package dtc separately as well
82+
version=$("./$builddir/dtc-install/bin/dtc" --version | awk '{print $3}')
83+
echo "Device Tree Compiler version $version"
84+
filename="dtc-${version}-${suffix}.zip"
85+
echo "Saving dtc package to $filename"
86+
pushd "$builddir/dtc-install/"
87+
tar -a -cf "$topd/bin/$filename" * .keep
88+
popd
89+
8090
if [[ "$SKIP_OPENOCD" != 1 ]]; then
8191
# Package OpenOCD separately as well
8292

build_macos.sh

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ SKIP_RISCV=${SKIP_RISCV-0}
77
SKIP_OPENOCD=${SKIP_OPENOCD-0}
88

99
# Install prerequisites
10-
arch -x86_64 /usr/local/bin/brew install jq libtool libusb automake hidapi --quiet
11-
arch -arm64 /opt/homebrew/bin/brew install jq libtool libusb automake hidapi --quiet
10+
arch -x86_64 /usr/local/bin/brew install jq libtool libusb automake hidapi bison flex pkgconf --quiet
11+
arch -arm64 /opt/homebrew/bin/brew install jq libtool libusb automake hidapi bison flex pkgconf --quiet
1212
# RISC-V prerequisites
1313
echo "Listing local"
1414
ls /usr/local/bin
@@ -60,6 +60,9 @@ fi
6060
arch -x86_64 ../packages/macos/picotool/build-picotool.sh
6161
arch -arm64 ../packages/macos/picotool/build-picotool.sh
6262
../packages/macos/picotool/merge-picotool.sh
63+
64+
arch -x86_64 ../packages/macos/dtc/build-dtc.sh
65+
arch -arm64 ../packages/macos/dtc/build-dtc.sh
6366
cd ..
6467

6568
topd=$PWD
@@ -85,6 +88,15 @@ pushd "$builddir/picotool-install/"
8588
tar -a -cf "$topd/bin/$filename" * .keep
8689
popd
8790

91+
# Package dtc separately as well
92+
version=$("./$builddir/dtc-install/bin/dtc" --version | awk '{print $3}')
93+
echo "Device Tree Compiler version $version"
94+
filename="dtc-${version}-${suffix}.zip"
95+
echo "Saving dtc package to $filename"
96+
pushd "$builddir/dtc-install/"
97+
zip -yr "$topd/bin/$filename" * .keep
98+
popd
99+
88100
if [[ "$SKIP_OPENOCD" != 1 ]] && [[ $(uname -m) == 'arm64' ]]; then
89101
# Package OpenOCD separately as well
90102

config/repositories.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@
1919
{
2020
"href": "https://github.com/gcc-mirror/gcc",
2121
"tree": "releases/gcc-14"
22+
},
23+
{
24+
"href": "https://git.kernel.org/pub/scm/utils/dtc/dtc.git",
25+
"tree": "v1.7.2"
2226
}
2327
]
2428
}

packages/linux/dtc/build-dtc.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/bin/bash
2+
3+
set -euo pipefail
4+
5+
cd dtc
6+
7+
# build
8+
make clean
9+
make -j$(nproc) NO_PYTHON=1
10+
11+
INSTALLDIR="$PWD/../dtc-install"
12+
make NO_PYTHON=1 DESTDIR="$INSTALLDIR" PREFIX="" install

packages/macos/dtc/build-dtc.sh

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#!/bin/zsh
2+
3+
set -euo pipefail
4+
5+
# Drop git repo of dtc as we use brew to build
6+
rm -rf dtc
7+
mkidr -p dtc-install
8+
cd dtc-install
9+
10+
arch -x86_64 /usr/local/bin/brew install --build-from-source dtc
11+
arch -arm64 /opt/homebrew/bin/brew install --build-from-source dtc
12+
13+
# Copy the dtc binaries to the build directory
14+
BREW_PREFIX_X86=$(arch -x86_64 /usr/local/bin/brew --prefix)
15+
BREW_PREFIX_ARM64=$(arch -arm64 /opt/homebrew/bin/brew --prefix)
16+
17+
cp -R "$BREW_PREFIX_X86/Cellar/dtc/$(arch -x86_64 /usr/local/bin/brew list --versions dtc | awk '{print $2}')" ./dtc-x86
18+
cp -R "$BREW_PREFIX_ARM64/Cellar/dtc/$(arch -arm64 /opt/homebrew/bin/brew list --versions dtc | awk '{print $2}')" ./dtc-arm64
19+
20+
# Create universal distribution
21+
mkdir -p dtc-universal/{bin,lib}
22+
23+
for binary in dtc fdtdump fdtoverlay fdtput fdtget dtdiff convert-dtsv0; do
24+
lipo -create \
25+
dtc-arm64/bin/$binary \
26+
dtc-x86/bin/$binary \
27+
-output dtc-universal/bin/$binary
28+
done
29+
30+
VERSIONED_DYLIB=$(basename "$(find dtc-arm64/lib -name 'libfdt.dylib.*' | head -n 1)")
31+
32+
lipo -create \
33+
dtc-arm64/lib/$VERSIONED_DYLIB \
34+
dtc-x86/lib/$VERSIONED_DYLIB \
35+
-output dtc-universal/lib/$VERSIONED_DYLIB
36+
37+
lipo -create \
38+
dtc-arm64/lib/libfdt.a \
39+
dtc-x86/lib/libfdt.a \
40+
-output dtc-universal/lib/libfdt.a
41+
42+
# Recreate symlinks
43+
cd dtc-universal/lib
44+
ln -sf $VERSIONED_DYLIB libfdt.1.dylib
45+
ln -sf libfdt.1.dylib libfdt.dylib
46+
cd ../../
47+
48+
cp -R dtc-arm64/include dtc-universal/
49+
cp -R dtc-arm64/README.md dtc-universal/
50+
51+
# clean up
52+
rm -rf dtc-arm64
53+
rm -rf dtc-x86
54+
55+
# move every folder and file from dtc-universal to .
56+
mv dtc-universal/* .
57+
rmdir dtc-universal
58+
59+
cd ..

packages/windows/dtc/build-dtc.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/bin/bash
2+
3+
set -euo pipefail
4+
5+
BUILDDIR=$(pwd)
6+
INSTALLDIR="dtc-install"
7+
8+
cd dtc
9+
make clean
10+
make -j$(nproc) NO_PYTHON=1
11+
12+
make NO_PYTHON=1 DESTDIR="$BUILDDIR/$INSTALLDIR" PREFIX="" install
13+
14+
cd "$BUILDDIR/$INSTALLDIR/${MSYSTEM,,}/bin"
15+
"$BUILDDIR/../packages/windows/copy-deps.sh"

0 commit comments

Comments
 (0)