mkits.sh 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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="
  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. fi
  73. # Create a default, fully populated DTS file
  74. DATA="/dts-v1/;
  75. / {
  76. description = \"${ARCH_UPPER} libreCMC FIT (Flattened Image Tree)\";
  77. #address-cells = <1>;
  78. images {
  79. kernel@1 {
  80. description = \"${ARCH_UPPER} libreCMC Linux-${VERSION}\";
  81. data = /incbin/(\"${KERNEL}\");
  82. type = \"kernel\";
  83. arch = \"${ARCH}\";
  84. os = \"linux\";
  85. compression = \"${COMPRESS}\";
  86. load = <${LOAD_ADDR}>;
  87. entry = <${ENTRY_ADDR}>;
  88. hash@1 {
  89. algo = \"crc32\";
  90. };
  91. hash@2 {
  92. algo = \"sha1\";
  93. };
  94. };
  95. ${FDT}
  96. };
  97. configurations {
  98. default = \"${CONFIG}\";
  99. ${CONFIG} {
  100. description = \"libreCMC\";
  101. kernel = \"kernel@1\";
  102. fdt = \"fdt@1\";
  103. };
  104. };
  105. };"
  106. # Write .its file to disk
  107. echo "$DATA" > ${OUTPUT}