check_esp_memory_utils_headers.sh 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #!/usr/bin/env bash
  2. set -euo pipefail
  3. # Some memory utility functions need to be defined both in bootloader and app contexts.
  4. # To avoid adding bootloader_support as a public dependency of every component,
  5. # and to avoid adding esp_hw_support as a bootloader dependency, some code is duplicated
  6. # between two memory utils files. This script checks that the duplicated code is in sync.
  7. esp_hw_support_header="${IDF_PATH}/components/esp_hw_support/include/esp_memory_utils.h"
  8. bootloader_support_header="${IDF_PATH}/components/bootloader_support/include/bootloader_memory_utils.h"
  9. bootloader_support_start="The content of this file is to be kept in sync with the common section of esp_memory_utils.h"
  10. bootloader_support_end="End of the common section that has to be in sync with esp_memory_utils.h"
  11. esp_hw_support_start="Common functions, to be kept in sync with bootloader_memory_utils.h"
  12. esp_hw_support_end="End of common functions to be kept in sync with bootloader_memory_utils.h"
  13. # get_file_part <input> <output> <from> <to>
  14. # Extract lines of <input> starting with a line which matches <from>
  15. # and ending with a line which matches <to>, and write the result to <output>.
  16. function get_file_part
  17. {
  18. input_file=$1
  19. output_file=$2
  20. from_line=$3
  21. to_line=$4
  22. awk "/${from_line}/{print START; select=1; next} /${to_line}/{print \"END\"; select=0} select{print \$0}" "${input_file}" > "${output_file}"
  23. }
  24. esp_hw_support_part_file=esp_hw_support_part.h
  25. bootloader_support_part_file=bootloader_support_part.h
  26. get_file_part "${esp_hw_support_header}" "${esp_hw_support_part_file}" "${esp_hw_support_start}" "${esp_hw_support_end}"
  27. get_file_part "${bootloader_support_header}" "${bootloader_support_part_file}" "${bootloader_support_start}" "${bootloader_support_end}"
  28. if ! diff --unified "${esp_hw_support_part_file}" "${bootloader_support_part_file}"; then
  29. echo ""
  30. echo " The content of common sections in esp_memory_utils.h and bootloader_memory_utils.h is different."
  31. echo " If you made changes to one of these files, please update the other one with the same changes."
  32. echo " See ${esp_hw_support_part_file} and ${bootloader_support_part_file} for details."
  33. exit 1
  34. fi
  35. echo "esp_memory_utils.h and bootloader_memory_utils.h are in sync."
  36. rm -f "${esp_hw_support_part_file}" "${bootloader_support_part_file}"