forked from system76/ec
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.sh
executable file
·81 lines (68 loc) · 2.16 KB
/
build.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/usr/bin/env bash
# SPDX-License-Identifier: MIT
errorExit() {
errorMessage="$1"
echo "$errorMessage"
exit 1
}
errorCheck() {
errorCode=$?
errorMessage="$1"
[ "$errorCode" -ne 0 ] && errorExit "$errorMessage : ($errorCode)"
return $errorCode
}
usage() {
cat <<EOF
Usage: ./$(basename "${0}")
Environmental variables:
EC_BOARD_VENDOR name of the board vendor (required)
EC_BOARD_MODEL name of the board model (required)
Example usage to build for NovaCustom NV40 series:
EC_BOARD_VENDOR=clevo EC_BOARD_MODEL=nv40mz ./$(basename "$0")
EOF
exit 0
}
if [ -z "$EC_BOARD_VENDOR" ]; then
echo "EC_BOARD_VENDOR not given"
usage
fi
if [ -z "$EC_BOARD_MODEL" ]; then
echo "EC_BOARD_MODEL not given"
usage
fi
EC_GIT_DATE="$(git show -s --format=%cs HEAD)"
EC_GIT_REV="$(git rev-parse --short HEAD)"
EC_BUILD_DIR="build/${EC_BOARD_VENDOR}/${EC_BOARD_MODEL}/${EC_GIT_DATE}_${EC_GIT_REV:0:7}"
EC_ROM="${EC_BUILD_DIR}/ec.rom"
EC_ARTIFACT="${EC_BOARD_VENDOR}_${EC_BOARD_MODEL}_ec.rom"
# For already released boards, keep the original names (already present in the
# released firmwares) to avoid the necessity of force-flashing during EC
# firmware update:
# - clevo/nv40mz for novacustom/nv4x_tgl:
# - https://docs.dasharo.com/variants/novacustom_nv4x_tgl/releases/#v130-2022-10-18
# - clevo/ns50mu for novacustom/ns5x_tgl:
# - https://docs.dasharo.com/variants/novacustom_ns5x_tgl/releases/#v130-2022-09-01
#
if [ "$EC_BOARD_VENDOR" = "novacustom" ] ; then
mkdir -p build/novacustom/
case "$EC_BOARD_MODEL" in
"nv4x_tgl")
ln -s ../clevo/nv40mz build/novacustom/nv4x_tgl
EC_BOARD_VENDOR="clevo"
EC_BOARD_MODEL="nv40mz"
;;
"ns5x_tgl")
ln -s ../clevo/ns50mu build/novacustom/ns5x_tgl
EC_BOARD_VENDOR="clevo"
EC_BOARD_MODEL="ns50mu"
;;
*)
esac
fi
docker run --rm -v "$PWD":"$PWD" -w "$PWD" -u "$(id -u)" \
ghcr.io/dasharo/ec-sdk:main make BOARD="${EC_BOARD_VENDOR}/${EC_BOARD_MODEL}"
errorCheck "Failed to build EC firmware"
cp "$EC_ROM" "$EC_ARTIFACT"
errorCheck "Failed to rename EC firmware"
dd if=/dev/zero of="$EC_ARTIFACT" bs=1 seek=128k count=0
errorCheck "Failed to extend EC firmware"