mkits.sh 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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-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. # Create a default, fully populated DTS file
  54. DATA="/dts-v1/;
  55. / {
  56. description = \"${ARCH_UPPER} libreCMC FIT (Flattened Image Tree)\";
  57. #address-cells = <1>;
  58. images {
  59. kernel@1 {
  60. description = \"${ARCH_UPPER} libreCMC Linux-${VERSION}\";
  61. data = /incbin/(\"${KERNEL}\");
  62. type = \"kernel\";
  63. arch = \"${ARCH}\";
  64. os = \"linux\";
  65. compression = \"${COMPRESS}\";
  66. load = <${LOAD_ADDR}>;
  67. entry = <${ENTRY_ADDR}>;
  68. hash@1 {
  69. algo = \"crc32\";
  70. };
  71. hash@2 {
  72. algo = \"sha1\";
  73. };
  74. };
  75. fdt@1 {
  76. description = \"${ARCH_UPPER} libreCMC ${DEVICE} device tree blob\";
  77. data = /incbin/(\"${DTB}\");
  78. type = \"flat_dt\";
  79. arch = \"${ARCH}\";
  80. compression = \"none\";
  81. hash@1 {
  82. algo = \"crc32\";
  83. };
  84. hash@2 {
  85. algo = \"sha1\";
  86. };
  87. };
  88. };
  89. configurations {
  90. default = \"config@1\";
  91. config@1 {
  92. description = \"libreCMC\";
  93. kernel = \"kernel@1\";
  94. fdt = \"fdt@1\";
  95. };
  96. };
  97. };"
  98. # Conditionally strip fdt information out of tree
  99. if [ -z "${DTB}" ]; then
  100. DATA=`echo "$DATA" | sed '/start fdt/,/end fdt/d'`
  101. DATA=`echo "$DATA" | sed '/fdt/d'`
  102. fi
  103. # Write .its file to disk
  104. echo "$DATA" > ${OUTPUT}