|
1 | 1 | #!/usr/bin/env bash |
2 | | -# Takes the architecture as a parameter |
3 | | -# Currently supported values: arm64 |
| 2 | +# Takes a list of architectures to build images for as the parameter |
| 3 | + |
| 4 | +function download_br() { |
| 5 | + mkdir -p src |
| 6 | + TARBALL=buildroot-${BUILDROOT_VERSION}.tar.gz |
| 7 | + rm -f "${TARBALL}" |
| 8 | + curl -LO https://buildroot.org/downloads/"${TARBALL}" |
| 9 | + if ! sha256sum --quiet -c "${TARBALL}".sha256; then |
| 10 | + echo "Downloaded tarball's hash does not match known good one! Please try redownloading." |
| 11 | + exit 1 |
| 12 | + fi |
| 13 | + tar -xzf "${TARBALL}" -C src --strip-components=1 |
| 14 | + rm -f "${TARBALL}" |
| 15 | +} |
4 | 16 |
|
5 | 17 | # Make sure we don't have any unset variables |
6 | 18 | set -u |
7 | 19 |
|
8 | | -# Clean up |
9 | | -rm -rf build |
10 | | -mkdir -p build |
| 20 | +# Move into the folder that contains this script |
| 21 | +cd "$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")" || exit 1 |
| 22 | + |
| 23 | +# Generate list of configs to build |
| 24 | +CONFIGS=() |
| 25 | +while (( ${#} )); do |
| 26 | + case ${1} in |
| 27 | + all) for CONFIG in *.config; do CONFIGS+=( "../${CONFIG}" ); done ;; |
| 28 | + arm64|arm|ppc32|ppc64le|x86_64) CONFIGS+=( "../${1}.config" ) ;; |
| 29 | + *) echo "Unknown parameter '${1}', exiting!"; exit 1 ;; |
| 30 | + esac |
| 31 | + shift |
| 32 | +done |
11 | 33 |
|
12 | 34 | # Download latest buildroot release |
13 | | -curl https://buildroot.org/downloads/buildroot-2019.02.3.tar.gz | tar -xzf - -C build --strip-components=1 |
14 | | -cd build || exit 1 |
15 | | - |
16 | | -# Use the config in the parent folder |
17 | | -CONFIG=../${1}.config |
18 | | -if [[ ! -f ${CONFIG} ]]; then |
19 | | - echo "${CONFIG} does not exist! Is your parameter correct?" |
20 | | - exit 1 |
21 | | -fi |
22 | | -BR2_DEFCONFIG=${CONFIG} make defconfig |
23 | | -if [[ -n ${EDITCONFIG:-} ]]; then |
24 | | - make menuconfig |
25 | | - make savedefconfig |
| 35 | +BUILDROOT_VERSION=2019.02.3 |
| 36 | +if [[ -d src ]]; then |
| 37 | + if [[ $(cd src && make print-version | cut -d - -f 1 2>/dev/null) != "${BUILDROOT_VERSION}" ]]; then |
| 38 | + rm -rf src |
| 39 | + download_br |
| 40 | + fi |
| 41 | +else |
| 42 | + download_br |
26 | 43 | fi |
| 44 | +cd src || exit 1 |
27 | 45 |
|
28 | | -# Build images |
29 | | -make -j"$(nproc)" |
| 46 | +# Build the images for the architectures requested |
| 47 | +for CONFIG in "${CONFIGS[@]}"; do |
| 48 | + # Clean up artifacts from the last build |
| 49 | + make clean |
30 | 50 |
|
31 | | -# Make sure images folder exists |
32 | | -IMAGES_FOLDER=../../images/${1} |
33 | | -[[ ! -d ${IMAGES_FOLDER} ]] && mkdir -p "${IMAGES_FOLDER}" |
34 | | - |
35 | | -# Copy new images |
36 | | -# Make sure images exist before moving them |
37 | | -IMAGES=( "output/images/rootfs.cpio" "output/images/rootfs.ext4" ) |
38 | | -for IMAGE in "${IMAGES[@]}"; do |
39 | | - if [[ ! -f ${IMAGE} ]]; then |
40 | | - echo "${IMAGE} could not be found! Did the build error?" |
41 | | - exit 1 |
| 51 | + BR2_DEFCONFIG=${CONFIG} make defconfig |
| 52 | + if [[ -n ${EDITCONFIG:-} ]]; then |
| 53 | + make menuconfig |
| 54 | + make savedefconfig |
42 | 55 | fi |
43 | | - cp -v "${IMAGE}" "${IMAGES_FOLDER}" |
| 56 | + |
| 57 | + # Build images |
| 58 | + make -j"$(nproc)" |
| 59 | + |
| 60 | + # Get the architecture from the name of the config: ../<arch>.config |
| 61 | + # basename strips ../ |
| 62 | + # ${CONFIG//.config} strips .config |
| 63 | + ARCH=$(basename "${CONFIG//.config}") |
| 64 | + |
| 65 | + # Make sure images folder exists |
| 66 | + IMAGES_FOLDER=../../images/${ARCH} |
| 67 | + [[ ! -d ${IMAGES_FOLDER} ]] && mkdir -p "${IMAGES_FOLDER}" |
| 68 | + |
| 69 | + # Copy new images |
| 70 | + # Make sure images exist before moving them |
| 71 | + IMAGES=( "output/images/rootfs.cpio" "output/images/rootfs.ext4" ) |
| 72 | + for IMAGE in "${IMAGES[@]}"; do |
| 73 | + if [[ ! -f ${IMAGE} ]]; then |
| 74 | + echo "${IMAGE} could not be found! Did the build error?" |
| 75 | + exit 1 |
| 76 | + fi |
| 77 | + cp -v "${IMAGE}" "${IMAGES_FOLDER}" |
| 78 | + done |
44 | 79 | done |
0 commit comments