genimage.sh 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. TOPDIR=`dirname $0`
  22. BUILD_DIR=$TOPDIR/work
  23. INPUT_DIR=$TOPDIR
  24. OUTPUT_DIR=$TOPDIR/work
  25. GENIMAGE_CFG=$TOPDIR/conf/genimage.cfg
  26. GENIMAGE=$TOPDIR/work/buildroot_initramfs/host/bin/genimage
  27. if [ ! -f $GENIMAGE ]; then
  28. printf $COLOR_RED
  29. echo "Error: $GENIMAGE not found. need building the usdk first"
  30. printf $COLOR_NORMAL
  31. exit 1
  32. fi
  33. GENIMAGE_TMP="${BUILD_DIR}/genimage.tmp"
  34. # Pass an empty rootpath. genimage makes a full copy of the given rootpath to
  35. # ${GENIMAGE_TMP}/root so passing TARGET_DIR would be a waste of time and disk
  36. # space. We don't rely on genimage to build the rootfs image, just to insert a
  37. # pre-built one in the disk image.
  38. trap 'rm -rf "${ROOTPATH_TMP}"' EXIT
  39. ROOTPATH_TMP="$(mktemp -d)"
  40. rm -rf "${GENIMAGE_TMP}"
  41. $GENIMAGE \
  42. --rootpath "${ROOTPATH_TMP}" \
  43. --tmppath "${GENIMAGE_TMP}" \
  44. --inputpath "${INPUT_DIR}" \
  45. --outputpath "${OUTPUT_DIR}" \
  46. --config "${GENIMAGE_CFG}"