You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

103 lines
3.0 KiB

  1. #!/bin/sh
  2. # SPDX-License-Identifier: GPL-3.0+
  3. set -e
  4. ## import variables
  5. . ./common/variables.sh
  6. ################################################################################
  7. ## Menu
  8. ################################################################################
  9. ## Parse avialble models from directory names
  10. AVAILABLE_MODELS=$(find ./ -maxdepth 1 -mindepth 1 -type d | sed 's/\.\///g' | grep -Ev "common|git")
  11. ## Help menu
  12. usage()
  13. {
  14. echo "Usage: "
  15. echo
  16. echo " $0 [-t <TAG>] [-c <COMMIT>] [--config] [--bleeding-edge] [--clean-slate] <model>"
  17. echo
  18. echo " --bleeding-edge Build from the latest commit"
  19. echo " --clean-slate Purge previous build directory and config"
  20. echo " -c, --commit <commit> Git commit hash"
  21. echo " --flash Flash BIOS if build is successful"
  22. echo " -h, --help Show this help"
  23. echo " -i, --config Execute with interactive make config"
  24. echo " -t, --tag <tag> Git tag/version"
  25. echo
  26. echo "If a tag, commit or bleeding-edge flag is not given, the latest Coreboot release will be built."
  27. echo
  28. echo
  29. echo "Available models:"
  30. for AVAILABLE_MODEL in $AVAILABLE_MODELS; do
  31. echo "$(printf '\t')$AVAILABLE_MODEL"
  32. done
  33. }
  34. ## Iterate through command line parameters
  35. while :
  36. do
  37. case "$1" in
  38. --bleeding-edge)
  39. COREBOOT_COMMIT="master"
  40. shift 1;;
  41. --clean-slate)
  42. CLEAN_SLATE=true
  43. shift 1;;
  44. -c | --commit)
  45. COREBOOT_COMMIT="$2"
  46. shift 2;;
  47. --flash)
  48. FLASH_AFTER_BUILD=true
  49. shift 1;;
  50. -h | --help)
  51. usage >&2
  52. exit 0;;
  53. -i | --config)
  54. COREBOOT_CONFIG=true
  55. shift 1;;
  56. -t | --tag)
  57. COREBOOT_TAG="$2"
  58. shift 2;;
  59. -*)
  60. echo "Error: Unknown option: $1" >&2
  61. usage >&2
  62. exit 1;;
  63. *)
  64. break;;
  65. esac
  66. done
  67. ## Validate and normalize given model number
  68. MODEL=$(echo "$@" | tr -d '[:space:]' | tr '[:upper:]' '[:lower:]');
  69. ## Check if valid model
  70. if [ -z "$MODEL" ] || [ ! -d "$PWD/$MODEL" ]; then
  71. usage
  72. exit 1;
  73. fi;
  74. ################################################################################
  75. ################################################################################
  76. if [ ! -d "$PWD/$MODEL/build" ]; then
  77. mkdir "$PWD/$MODEL/build"
  78. elif [ "$CLEAN_SLATE" ]; then
  79. rm -rf "$PWD/$MODEL/build" || true
  80. mkdir "$PWD/$MODEL/build"
  81. fi
  82. ## Run Docker
  83. docker run --rm -it \
  84. --user "$(id -u):$(id -g)" \
  85. -v "$PWD/$MODEL/build:$DOCKER_COREBOOT_DIR" \
  86. -v "$PWD/$MODEL:$DOCKER_SCRIPT_DIR" \
  87. -v "$PWD/common:$DOCKER_COMMON_SCRIPT_DIR" \
  88. -v "$PWD/$MODEL/stock_bios:$DOCKER_STOCK_BIOS_DIR:ro" \
  89. -e COREBOOT_COMMIT="$COREBOOT_COMMIT" \
  90. -e COREBOOT_TAG="$COREBOOT_TAG" \
  91. -e COREBOOT_CONFIG="$COREBOOT_CONFIG" \
  92. coreboot/coreboot-sdk:"$COREBOOT_SDK_VERSION" \
  93. /home/coreboot/scripts/compile.sh && [ -n "$FLASH_AFTER_BUILD" ] && ./flash.sh "$MODEL"