genimage.sh 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #!/usr/bin/env bash
  2. set -e
  3. die() {
  4. cat <<EOF >&2
  5. Error: $@
  6. Usage: ${0} -c GENIMAGE_CONFIG_FILE
  7. EOF
  8. exit 1
  9. }
  10. # Parse arguments and put into argument list of the script
  11. opts="$(getopt -n "${0##*/}" -o c: -- "$@")" || exit $?
  12. eval set -- "$opts"
  13. GENIMAGE_TMP="${BUILD_DIR}/genimage.tmp"
  14. while true ; do
  15. case "$1" in
  16. -c)
  17. GENIMAGE_CFG="${2}";
  18. shift 2 ;;
  19. --) # Discard all non-option parameters
  20. shift 1;
  21. break ;;
  22. *)
  23. die "unknown option '${1}'" ;;
  24. esac
  25. done
  26. [ -n "${GENIMAGE_CFG}" ] || die "Missing argument"
  27. # Pass an empty rootpath. genimage makes a full copy of the given rootpath to
  28. # ${GENIMAGE_TMP}/root so passing TARGET_DIR would be a waste of time and disk
  29. # space. We don't rely on genimage to build the rootfs image, just to insert a
  30. # pre-built one in the disk image.
  31. trap 'rm -rf "${ROOTPATH_TMP}"' EXIT
  32. ROOTPATH_TMP="$(mktemp -d)"
  33. rm -rf "${GENIMAGE_TMP}"
  34. genimage \
  35. --rootpath "${ROOTPATH_TMP}" \
  36. --tmppath "${GENIMAGE_TMP}" \
  37. --inputpath "${BINARIES_DIR}" \
  38. --outputpath "${BINARIES_DIR}" \
  39. --config "${GENIMAGE_CFG}"
  40. if grep -Eq "^BR2_PACKAGE_HOST_BMAP_TOOLS=y$" "${BR2_CONFIG}"; then
  41. while IFS= read -r image; do
  42. image_path="${BINARIES_DIR}/${image}"
  43. if ! test -f "${image_path}"; then
  44. continue
  45. fi
  46. bmaptool create "${image_path}" -o "${image_path}.bmap"
  47. done < <(grep '^image ' "${GENIMAGE_CFG}" | cut -d ' ' -f 2)
  48. fi