diff --git a/scripts/xtensa-build-zephyr.sh b/scripts/xtensa-build-zephyr.sh index cf208807d..741286afd 100755 --- a/scripts/xtensa-build-zephyr.sh +++ b/scripts/xtensa-build-zephyr.sh @@ -5,9 +5,11 @@ # stop on most errors set -e +SOF_TOP=$(cd "$(dirname "$0")" && cd .. && pwd) + SUPPORTED_PLATFORMS=(apl cnl icl tgl-h) -# By default use "zephyr" in the current directory -ZEPHYR_ROOT=zephyr +# Default value, can be overridden on the command line +WEST_TOP="${SOF_TOP}"/zephyrproject BUILD_JOBS=$(nproc --all) RIMAGE_KEY=modules/audio/sof/keys/otc_private_key.pem PLATFORMS=() @@ -31,41 +33,43 @@ platform's _defconfig file. usage: $0 [options] platform(s) -a Build all platforms. - -c Clone the complete Zephyr and SOF trees before building. -j n Set number of make build jobs. Jobs=#cores by default. Infinite when not specified. -k Path to a non-default rimage signing key. - -p Zephyr root directory. + -c recursively clones Zephyr inside sof before building. + Incompatible with -p. + -p Existing Zephyr project directory. Incompatible with -c. + If modules/audio/sof is missing there then a symbolic + link pointing to ${SOF_TOP} will be added. Supported platforms ${SUPPORTED_PLATFORMS[*]} EOF } +# Downloads zephyrproject inside sof/ and create a ../../.. symbolic +# link back to sof/ clone() { - # Check out Zephyr + SOF - type -p west || die "Install west and a west toolchain following https://docs.zephyrproject.org/latest/getting_started/index.html" type -p git || die "Install git" - [ -e "$ZEPHYR_ROOT" ] && die "$ZEPHYR_ROOT already exists" - mkdir -p "$ZEPHYR_ROOT" - cd "$ZEPHYR_ROOT" - west init - west update - cd modules/audio/sof - git remote add sof https://github.com/thesofproject/sof.git - git remote update sof - git checkout sof/main - git clone --recurse-submodules https://github.com/thesofproject/rimage.git - cd - + [ -e "$WEST_TOP" ] && die "$WEST_TOP already exists" + mkdir -p "$WEST_TOP" + git clone --depth=5 https://github.com/zephyrproject-rtos/zephyr \ + "$WEST_TOP"/zephyr + west init -l "${WEST_TOP}"/zephyr + ( cd "${WEST_TOP}" + mkdir -p modules/audio + ln -s ../../.. modules/audio/sof + # Do NOT "west update sof"!! + west update zephyr hal_xtensa + ) } build() { - [ -d "$ZEPHYR_ROOT" ] || die "$ZEPHYR_ROOT doesn't exists" - cd "$ZEPHYR_ROOT" + cd "$WEST_TOP" # Build rimage RIMAGE_DIR=build-rimage @@ -107,6 +111,8 @@ build() main() { + local zeproj + # parse the args while getopts "acj:k:p:" OPTION; do case "$OPTION" in @@ -114,12 +120,28 @@ main() c) DO_CLONE=yes ;; j) BUILD_JOBS="$OPTARG" ;; k) RIMAGE_KEY="$OPTARG" ;; - p) ZEPHYR_ROOT="$OPTARG" ;; + p) zeproj="$OPTARG" ;; *) print_usage; exit 1 ;; esac done shift $((OPTIND-1)) + if [ -n "$zeproj" ] && [ x"$DO_CLONE" = xyes ]; then + die 'Cannot use -p with -c, -c supports %s only' "${WEST_TOP}" + fi + + if [ -n "$zeproj" ]; then + + [ -d "$zeproj" ] || + die "$zeproj is not a directory, try -c instead of -p?" + + ( cd "$zeproj" + test "$(realpath "$(west topdir)")" = "$(/bin/pwd)" + ) || die '%s is not a zephyrproject' "$WEST_TOP" + + WEST_TOP="$zeproj" + fi + # parse platform args for arg in "$@"; do platform=none @@ -148,6 +170,17 @@ main() if [ "x$DO_CLONE" == "xyes" ]; then clone + else + # Link to ourselves if no sof module yet + test -e "${WEST_TOP}"/modules/audio/sof || + ln -s "$SOF_TOP" "${WEST_TOP}"/modules/audio/sof + + # Support for submodules in west is too recent, cannot + # rely on it + test -d "${WEST_TOP}"/modules/audio/sof/rimage/CMakeLists.txt || ( + cd "${WEST_TOP}"/modules/audio/sof + git submodule update --init --recursive + ) fi build