mkits.sh 3.1 KB

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