mkits.sh 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. #!/bin/sh
  2. #
  3. # Licensed under the terms of the GNU GPL License version 2 or later.
  4. #
  5. # Author: Peter Tyser <[email protected]>
  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. printf "Usage: %s -A arch -C comp -a addr -e entry" "$(basename "$0")"
  18. printf " -v version -k kernel [-D name -n address -d dtb] -o its_file"
  19. printf "\n\t-A ==> set architecture to 'arch'"
  20. printf "\n\t-C ==> set compression type 'comp'"
  21. printf "\n\t-c ==> set config name 'config'"
  22. printf "\n\t-a ==> set load address to 'addr' (hex)"
  23. printf "\n\t-e ==> set entry point to 'entry' (hex)"
  24. printf "\n\t-v ==> set kernel version to 'version'"
  25. printf "\n\t-k ==> include kernel image 'kernel'"
  26. printf "\n\t-D ==> human friendly Device Tree Blob 'name'"
  27. printf "\n\t-n ==> fdt unit-address 'address'"
  28. printf "\n\t-d ==> include Device Tree Blob 'dtb'"
  29. printf "\n\t-o ==> create output file 'its_file'\n"
  30. exit 1
  31. }
  32. FDTNUM=1
  33. while getopts ":A:a:c:C:D:d:e:k:n:o:v:" OPTION
  34. do
  35. case $OPTION in
  36. A ) ARCH=$OPTARG;;
  37. a ) LOAD_ADDR=$OPTARG;;
  38. c ) CONFIG=$OPTARG;;
  39. C ) COMPRESS=$OPTARG;;
  40. D ) DEVICE=$OPTARG;;
  41. d ) DTB=$OPTARG;;
  42. e ) ENTRY_ADDR=$OPTARG;;
  43. k ) KERNEL=$OPTARG;;
  44. n ) FDTNUM=$OPTARG;;
  45. o ) OUTPUT=$OPTARG;;
  46. v ) VERSION=$OPTARG;;
  47. * ) echo "Invalid option passed to '$0' (options:$*)"
  48. usage;;
  49. esac
  50. done
  51. # Make sure user entered all required parameters
  52. if [ -z "${ARCH}" ] || [ -z "${COMPRESS}" ] || [ -z "${LOAD_ADDR}" ] || \
  53. [ -z "${ENTRY_ADDR}" ] || [ -z "${VERSION}" ] || [ -z "${KERNEL}" ] || \
  54. [ -z "${OUTPUT}" ] || [ -z "${CONFIG}" ]; then
  55. usage
  56. fi
  57. ARCH_UPPER=$(echo "$ARCH" | tr '[:lower:]' '[:upper:]')
  58. # Conditionally create fdt information
  59. if [ -n "${DTB}" ]; then
  60. FDT_NODE="
  61. fdt@$FDTNUM {
  62. description = \"${ARCH_UPPER} OpenWrt ${DEVICE} device tree blob\";
  63. data = /incbin/(\"${DTB}\");
  64. type = \"flat_dt\";
  65. arch = \"${ARCH}\";
  66. compression = \"none\";
  67. hash@1 {
  68. algo = \"crc32\";
  69. };
  70. hash@2 {
  71. algo = \"sha1\";
  72. };
  73. };
  74. "
  75. FDT_PROP="fdt = \"fdt@$FDTNUM\";"
  76. fi
  77. # Create a default, fully populated DTS file
  78. DATA="/dts-v1/;
  79. / {
  80. description = \"${ARCH_UPPER} OpenWrt FIT (Flattened Image Tree)\";
  81. #address-cells = <1>;
  82. images {
  83. kernel@1 {
  84. description = \"${ARCH_UPPER} OpenWrt Linux-${VERSION}\";
  85. data = /incbin/(\"${KERNEL}\");
  86. type = \"kernel\";
  87. arch = \"${ARCH}\";
  88. os = \"linux\";
  89. compression = \"${COMPRESS}\";
  90. load = <${LOAD_ADDR}>;
  91. entry = <${ENTRY_ADDR}>;
  92. hash@1 {
  93. algo = \"crc32\";
  94. };
  95. hash@2 {
  96. algo = \"sha1\";
  97. };
  98. };
  99. ${FDT_NODE}
  100. };
  101. configurations {
  102. default = \"${CONFIG}\";
  103. ${CONFIG} {
  104. description = \"OpenWrt\";
  105. kernel = \"kernel@1\";
  106. ${FDT_PROP}
  107. };
  108. };
  109. };"
  110. # Write .its file to disk
  111. echo "$DATA" > "${OUTPUT}"