1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-26 08:08:51 +00:00
trezor-firmware/script/fullbuild

96 lines
2.2 KiB
Plaintext
Raw Normal View History

2018-06-25 16:09:52 +00:00
#!/bin/bash
# script/build: Build the TREZOR firmware in a clean working tree.
#
set -eu
cd "$(dirname "$0")/.."
readonly ARTIFACT_EXTENSIONS=(bin elf)
readonly BUILD_DIR="$(readlink -f build)"
readonly BOOTLOADER_DIR="$BUILD_DIR/bootloader"
readonly BOOTLOADER_FILENAME="bootloader/bootloader.bin"
readonly BOOTLOADER_PATH="$BOOTLOADER_DIR/$BOOTLOADER_FILENAME"
readonly FIRMWARE_DIR="$BUILD_DIR/firmware"
readonly FIRMWARE_FILENAME="firmware/trezor.bin"
readonly FIRMWARE_PATH="$FIRMWARE_DIR/$FIRMWARE_FILENAME"
worktree_setup() {
local path="$1"
local commit="$2"
rm -rf "$path"
git clone -n --reference=. . "$path" --recurse-submodules
# Use `git rev-parse` so that we can use any reference from the working repository.
git -C "$path" checkout "$(git rev-parse "$commit")"
( cd "$path" && script/setup )
}
worktree_build() {
local path="$1"
( cd "$path" && script/cibuild )
}
worktree_copy() {
local path="$1"
local filename="$2"
local pattern="$3"
local describe="$(git -C "$path" describe --tags --match "$pattern")"
local src="$path/$filename"
local basename="$(basename "$filename")"
local dest="$BUILD_DIR/${basename%.*}-$describe.${basename##*.}"
for extension in "${ARTIFACT_EXTENSIONS[@]}"; do
2018-06-27 16:12:18 +00:00
install -Dm0644 \
"${src%.*}.$extension" \
"${dest%.*}.$extension"
2018-06-25 16:09:52 +00:00
done
printf "%s" "$dest"
}
main() {
local bootloader_commit="$1"
local firmware_commit="$2"
script/bootstrap
2018-06-25 16:09:52 +00:00
worktree_setup "$BOOTLOADER_DIR" "$bootloader_commit"
worktree_build "$BOOTLOADER_DIR"
local bootloader_path="$(worktree_copy \
2018-06-27 16:12:18 +00:00
"$BOOTLOADER_DIR" \
"$BOOTLOADER_FILENAME" \
"bl*")"
2018-06-25 16:09:52 +00:00
worktree_setup "$FIRMWARE_DIR" "$firmware_commit"
cp "$BOOTLOADER_PATH" "$FIRMWARE_DIR/$BOOTLOADER_FILENAME"
worktree_build "$FIRMWARE_DIR"
local firmware_path="$(worktree_copy \
2018-06-27 16:12:18 +00:00
"$FIRMWARE_DIR" \
"$FIRMWARE_FILENAME" \
"v*")"
2018-06-25 16:09:52 +00:00
printf "\n\n"; script/fingerprint \
2018-06-27 16:12:18 +00:00
"$bootloader_path" \
--max-size 32768 \
--double
2018-06-25 16:09:52 +00:00
printf "\n\n"; script/fingerprint \
2018-06-27 16:12:18 +00:00
"$firmware_path" \
--offset 256 \
--max-size 491520
2018-06-25 16:09:52 +00:00
}
main "$@"