genimage.sh 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #!/bin/bash
  2. ##################################################################
  3. ## ##
  4. ## SPDX-License-Identifier: GPL-2.0-or-later ##
  5. ## ##
  6. ## Copyright (C) 2018-2022 Starfive Technology ##
  7. ## ##
  8. ## Author: Andy Hu <andy.hu@starfivetech.com> ##
  9. ## Date: 2022-07-27 ##
  10. ## Description: This script used to generate img file ##
  11. ## which could be burned to tf card through dd or ##
  12. ## rpi-imager or balenaEtcher tool. ##
  13. ## Run it after the usdk initramfs and rootfs had been built ##
  14. ## ##
  15. ##################################################################
  16. COLOR_NORMAL="\033[0m"
  17. COLOR_GREEN="\033[1;32m"
  18. COLOR_YELLOW="\033[1;33m"
  19. COLOR_RED="\033[1;31m"
  20. COLOR_GREY="\033[1;30m"
  21. HWBOARD=visionfive2
  22. TOPDIR=`dirname $0`
  23. BUILD_DIR=$TOPDIR/work
  24. INPUT_DIR=$TOPDIR
  25. OUTPUT_DIR=$TOPDIR/work
  26. if [ $HWBOARD == "visionfive2" ]; then
  27. GENIMAGE_CFG=$TOPDIR/conf/genimage-vf2.cfg
  28. else
  29. GENIMAGE_CFG=$TOPDIR/conf/genimage.cfg
  30. fi
  31. GENIMAGE=$TOPDIR/work/buildroot_initramfs/host/bin/genimage
  32. if [ ! -f $GENIMAGE ]; then
  33. printf $COLOR_RED
  34. echo "Error: $GENIMAGE not found. need building the usdk first"
  35. printf $COLOR_NORMAL
  36. exit 1
  37. fi
  38. GENIMAGE_TMP="${BUILD_DIR}/genimage.tmp"
  39. # Pass an empty rootpath. genimage makes a full copy of the given rootpath to
  40. # ${GENIMAGE_TMP}/root so passing TARGET_DIR would be a waste of time and disk
  41. # space. We don't rely on genimage to build the rootfs image, just to insert a
  42. # pre-built one in the disk image.
  43. trap 'rm -rf "${ROOTPATH_TMP}"' EXIT
  44. ROOTPATH_TMP="$(mktemp -d)"
  45. rm -rf "${GENIMAGE_TMP}"
  46. $GENIMAGE \
  47. --rootpath "${ROOTPATH_TMP}" \
  48. --tmppath "${GENIMAGE_TMP}" \
  49. --inputpath "${INPUT_DIR}" \
  50. --outputpath "${OUTPUT_DIR}" \
  51. --config "${GENIMAGE_CFG}"