gen_netgear_rootfs_node.sh 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. #!/bin/sh
  2. #
  3. # SPDX-License-Identifier: GPL-2.0-or-later
  4. #
  5. # Author: Jascha Sundaresan <[email protected]>
  6. #
  7. # This helper script generates a top-level 'rootfs' node for inclusion
  8. # in a Flattened Image Tree (FIT) source (.its) file. The node includes
  9. # the size and SHA1 hash of a given root filesystem image and is used by
  10. # certain Netgear devices which expect this metadata at the top level of
  11. # the FIT structure.
  12. #
  13. # The resulting block is written to standard output and can be appended
  14. # or inserted into an existing .its file by the OpenWrt build system.
  15. # Example:
  16. # scripts/gen_netgear_rootfs_node.sh build_dir/.../root.squashfs > node.txt
  17. #
  18. # See also: scripts/mkits.sh, which generates the main FIT .its source.
  19. ROOTFS_FILE="$1"
  20. ROOTFS_SIZE=$(stat -c %s "${ROOTFS_FILE}")
  21. ROOTFS_SHA1=$(
  22. sha1sum "${ROOTFS_FILE}" | awk '{ print "<0x" substr($0, 1, 8) \
  23. " 0x" substr($0, 9, 8) \
  24. " 0x" substr($0, 17, 8) \
  25. " 0x" substr($0, 25, 8) \
  26. " 0x" substr($0, 33, 8) ">" }'
  27. )
  28. cat <<EOF | sed 's/^/\t/'
  29. rootfs {
  30. size = <${ROOTFS_SIZE}>;
  31. hash-1 {
  32. value = ${ROOTFS_SHA1};
  33. algo = "sha1";
  34. };
  35. };
  36. EOF