2
0

mkits.sh 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. #!/usr/bin/env bash
  2. #
  3. # Licensed under the terms of the GNU GPL License version 2 or later.
  4. #
  5. # Author: Peter Tyser <ptyser@xes-inc.com>
  6. #
  7. # U-Boot firmware supports the booting of images in the Flattened Image
  8. # Tree (FIT) format. The FIT format uses a device tree structure to
  9. # describe a kernel image, device tree blob, ramdisk, etc. This script
  10. # creates an Image Tree Source (.its file) which can be passed to the
  11. # 'mkimage' utility to generate an Image Tree Blob (.itb file). The .itb
  12. # file can then be booted by U-Boot (or other bootloaders which support
  13. # FIT images). See doc/uImage.FIT/howto.txt in U-Boot source code for
  14. # additional information on FIT images.
  15. #
  16. usage() {
  17. echo "Usage: `basename $0` -A arch -C comp -a addr -e entry" \
  18. "-v version -k kernel [-D name -d dtb] -o its_file"
  19. echo -e "\t-A ==> set architecture to 'arch'"
  20. echo -e "\t-C ==> set compression type 'comp'"
  21. echo -e "\t-a ==> set load address to 'addr' (hex)"
  22. echo -e "\t-e ==> set entry point to 'entry' (hex)"
  23. echo -e "\t-v ==> set kernel version to 'version'"
  24. echo -e "\t-k ==> include kernel image 'kernel'"
  25. echo -e "\t-D ==> human friendly Device Tree Blob 'name'"
  26. echo -e "\t-d ==> include Device Tree Blob 'dtb'"
  27. echo -e "\t-o ==> create output file 'its_file'"
  28. exit 1
  29. }
  30. while getopts ":A:a:C:D:d:e:k:o:v:" OPTION
  31. do
  32. case $OPTION in
  33. A ) ARCH=$OPTARG;;
  34. a ) LOAD_ADDR=$OPTARG;;
  35. C ) COMPRESS=$OPTARG;;
  36. D ) DEVICE=$OPTARG;;
  37. d ) DTB=$OPTARG;;
  38. e ) ENTRY_ADDR=$OPTARG;;
  39. k ) KERNEL=$OPTARG;;
  40. o ) OUTPUT=$OPTARG;;
  41. v ) VERSION=$OPTARG;;
  42. * ) echo "Invalid option passed to '$0' (options:$@)"
  43. usage;;
  44. esac
  45. done
  46. # Make sure user entered all required parameters
  47. if [ -z "${ARCH}" ] || [ -z "${COMPRESS}" ] || [ -z "${LOAD_ADDR}" ] || \
  48. [ -z "${ENTRY_ADDR}" ] || [ -z "${VERSION}" ] || [ -z "${KERNEL}" ] || \
  49. [ -z "${OUTPUT}" ]; then
  50. usage
  51. fi
  52. ARCH_UPPER=`echo $ARCH | tr '[:lower:]' '[:upper:]'`
  53. # Conditionally create fdt information
  54. if [ -n "${DTB}" ]; then
  55. FDT="
  56. fdt@1 {
  57. description = \"${ARCH_UPPER} OpenWrt ${DEVICE} device tree blob\";
  58. data = /incbin/(\"${DTB}\");
  59. type = \"flat_dt\";
  60. arch = \"${ARCH}\";
  61. compression = \"none\";
  62. hash@1 {
  63. algo = \"crc32\";
  64. };
  65. hash@2 {
  66. algo = \"sha1\";
  67. };
  68. };
  69. "
  70. fi
  71. # Create a default, fully populated DTS file
  72. DATA="/dts-v1/;
  73. / {
  74. description = \"${ARCH_UPPER} OpenWrt FIT (Flattened Image Tree)\";
  75. #address-cells = <1>;
  76. images {
  77. kernel@1 {
  78. description = \"${ARCH_UPPER} OpenWrt Linux-${VERSION}\";
  79. data = /incbin/(\"${KERNEL}\");
  80. type = \"kernel\";
  81. arch = \"${ARCH}\";
  82. os = \"linux\";
  83. compression = \"${COMPRESS}\";
  84. load = <${LOAD_ADDR}>;
  85. entry = <${ENTRY_ADDR}>;
  86. hash@1 {
  87. algo = \"crc32\";
  88. };
  89. hash@2 {
  90. algo = \"sha1\";
  91. };
  92. };
  93. ${FDT}
  94. };
  95. configurations {
  96. default = \"config@1\";
  97. config@1 {
  98. description = \"OpenWrt\";
  99. kernel = \"kernel@1\";
  100. fdt = \"fdt@1\";
  101. };
  102. };
  103. };"
  104. # Write .its file to disk
  105. echo "$DATA" > ${OUTPUT}