mkits.sh 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. #!/bin/bash
  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. echo "Usage: `basename $0` -A arch -C comp -a addr -e entry" \
  18. "-v version -k kernel [-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 ==> include Device Tree Blob 'dtb'"
  26. echo -e "\t-o ==> create output file 'its_file'"
  27. exit 1
  28. }
  29. while getopts ":A:C:a:d:e:k:o:v:" OPTION
  30. do
  31. case $OPTION in
  32. A ) ARCH=$OPTARG;;
  33. C ) COMPRESS=$OPTARG;;
  34. a ) LOAD_ADDR=$OPTARG;;
  35. d ) DTB=$OPTARG;;
  36. e ) ENTRY_ADDR=$OPTARG;;
  37. k ) KERNEL=$OPTARG;;
  38. o ) OUTPUT=$OPTARG;;
  39. v ) VERSION=$OPTARG;;
  40. * ) echo "Invalid option passed to '$0' (options:$@)"
  41. usage;;
  42. esac
  43. done
  44. # Make sure user entered all required parameters
  45. if [ -z "${ARCH}" ] || [ -z "${COMPRESS}" ] || [ -z "${LOAD_ADDR}" ] || \
  46. [ -z "${ENTRY_ADDR}" ] || [ -z "${VERSION}" ] || [ -z "${KERNEL}" ] || \
  47. [ -z "${OUTPUT}" ]; then
  48. usage
  49. fi
  50. # Create a default, fully populated DTS file
  51. DATA="/dts-v1/;
  52. / {
  53. description = \"Linux kernel ${VERSION}\";
  54. #address-cells = <1>;
  55. images {
  56. kernel@1 {
  57. description = \"Linux Kernel ${VERSION}\";
  58. data = /incbin/(\"${KERNEL}\");
  59. type = \"kernel\";
  60. arch = \"${ARCH}\";
  61. os = \"linux\";
  62. compression = \"${COMPRESS}\";
  63. load = <${LOAD_ADDR}>;
  64. entry = <${ENTRY_ADDR}>;
  65. hash@1 {
  66. algo = \"crc32\";
  67. };
  68. hash@2 {
  69. algo = \"sha1\";
  70. };
  71. };
  72. fdt@1 { /* start fdt */
  73. description = \"Flattened Device Tree blob\";
  74. data = /incbin/(\"${DTB}\");
  75. type = \"flat_dt\";
  76. arch = \"${ARCH}\";
  77. compression = \"none\";
  78. hash@1 {
  79. algo = \"crc32\";
  80. };
  81. hash@2 {
  82. algo = \"sha1\";
  83. };
  84. }; /* end fdt */
  85. };
  86. configurations {
  87. default = \"config@1\";
  88. config@1 {
  89. description = \"Default Linux kernel\";
  90. kernel = \"kernel@1\";
  91. fdt = \"fdt@1\";
  92. };
  93. };
  94. };"
  95. # Conditionally strip fdt information out of tree
  96. if [ -z "${DTB}" ]; then
  97. DATA=`echo "$DATA" | sed '/start fdt/,/end fdt/d'`
  98. DATA=`echo "$DATA" | sed '/fdt/d'`
  99. fi
  100. # Write .its file to disk
  101. echo "$DATA" > ${OUTPUT}