mkits.sh 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. #!/bin/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-r ==> include ramdisk"
  28. echo -e "\t-z ==> ramdisk compression type"
  29. echo -e "\t-o ==> create output file 'its_file'"
  30. exit 1
  31. }
  32. while getopts ":A:a:C:D:d:e:k:o:v:r:z:" OPTION
  33. do
  34. case $OPTION in
  35. A ) ARCH=$OPTARG;;
  36. a ) LOAD_ADDR=$OPTARG;;
  37. C ) COMPRESS=$OPTARG;;
  38. D ) DEVICE=$OPTARG;;
  39. d ) DTB=$OPTARG;;
  40. e ) ENTRY_ADDR=$OPTARG;;
  41. k ) KERNEL=$OPTARG;;
  42. o ) OUTPUT=$OPTARG;;
  43. v ) VERSION=$OPTARG;;
  44. r ) RAMDISK=$OPTARG;;
  45. z ) RD_COMPRESS=$OPTARG;;
  46. * ) echo "Invalid option passed to '$0' (options:$@)"
  47. usage;;
  48. esac
  49. done
  50. # Make sure user entered all required parameters
  51. if [ -z "${ARCH}" ] || [ -z "${COMPRESS}" ] || [ -z "${LOAD_ADDR}" ] || \
  52. [ -z "${ENTRY_ADDR}" ] || [ -z "${VERSION}" ] || [ -z "${KERNEL}" ] || \
  53. [ -z "${OUTPUT}" ]; then
  54. usage
  55. fi
  56. ARCH_UPPER=`echo $ARCH | tr '[:lower:]' '[:upper:]'`
  57. # Conditionally create fdt information
  58. if [ -n "${DTB}" ]; then
  59. FDT="
  60. fdt@1 {
  61. description = \"${ARCH_UPPER} OpenWrt ${DEVICE} device tree blob\";
  62. data = /incbin/(\"${DTB}\");
  63. type = \"flat_dt\";
  64. arch = \"${ARCH}\";
  65. compression = \"none\";
  66. hash@1 {
  67. algo = \"crc32\";
  68. };
  69. hash@2 {
  70. algo = \"sha1\";
  71. };
  72. };
  73. "
  74. CONF=" fdt = \"fdt@1\";"
  75. fi
  76. # Conditionally create ramdisk node
  77. if [ -n "${RAMDISK}" ]; then
  78. RD_COMPRESS=${RD_COMPRESS:-none}
  79. RD="
  80. ramdisk@1 {
  81. description = \"${ARCH_UPPER} OpenWrt ${DEVICE} ramdisk\";
  82. data = /incbin/(\"${RAMDISK}\");
  83. type = \"ramdisk\";
  84. arch = \"${ARCH}\";
  85. os = \"linux\";
  86. compression = \"${RD_COMPRESS}\";
  87. hash@1 {
  88. algo = \"crc32\";
  89. };
  90. hash@2 {
  91. algo = \"sha1\";
  92. };
  93. };
  94. "
  95. if [ -z "${CONF}" ]; then
  96. CONF=" ramdisk = \"ramdisk@1\";"
  97. else
  98. CONF="$CONF
  99. ramdisk = \"ramdisk@1\";"
  100. fi
  101. fi
  102. # Create a default, fully populated DTS file
  103. DATA="/dts-v1/;
  104. / {
  105. description = \"${ARCH_UPPER} OpenWrt FIT (Flattened Image Tree)\";
  106. #address-cells = <1>;
  107. images {
  108. kernel@1 {
  109. description = \"${ARCH_UPPER} OpenWrt Linux-${VERSION}\";
  110. data = /incbin/(\"${KERNEL}\");
  111. type = \"kernel\";
  112. arch = \"${ARCH}\";
  113. os = \"linux\";
  114. compression = \"${COMPRESS}\";
  115. load = <${LOAD_ADDR}>;
  116. entry = <${ENTRY_ADDR}>;
  117. hash@1 {
  118. algo = \"crc32\";
  119. };
  120. hash@2 {
  121. algo = \"sha1\";
  122. };
  123. };
  124. ${RD}
  125. ${FDT}
  126. };
  127. configurations {
  128. default = \"config@1\";
  129. config@1 {
  130. description = \"OpenWrt\";
  131. kernel = \"kernel@1\";
  132. ${CONF}
  133. };
  134. };
  135. };"
  136. # Write .its file to disk
  137. echo "$DATA" > ${OUTPUT}