check_placements.py 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. #!/usr/bin/env python
  2. #
  3. # Copyright 2020 Espressif Systems (Shanghai) PTE LTD
  4. #
  5. # Licensed under the Apache License, Version 2.0 (the "License");
  6. # you may not use this file except in compliance with the License.
  7. # You may obtain a copy of the License at
  8. #
  9. # http://www.apache.org/licenses/LICENSE-2.0
  10. #
  11. # Unless required by applicable law or agreed to in writing, software
  12. # distributed under the License is distributed on an "AS IS" BASIS,
  13. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. # See the License for the specific language governing permissions and
  15. # limitations under the License.
  16. #
  17. # Check placements in this test app for main
  18. # specified in main/linker.lf
  19. import argparse
  20. import subprocess
  21. from pyparsing import LineEnd, LineStart, Literal, Optional, Word, alphanums, hexnums
  22. argparser = argparse.ArgumentParser()
  23. argparser.add_argument('objdump')
  24. argparser.add_argument('elf')
  25. args = argparser.parse_args()
  26. contents = subprocess.check_output([args.objdump, '-t', args.elf]).decode()
  27. def check_location(symbol, expected):
  28. pattern = (LineStart() + Word(hexnums).setResultsName('address')
  29. + Optional(Word(alphanums, exact=1))
  30. + Optional(Word(alphanums,exact=1))
  31. + Word(alphanums + '._*').setResultsName('actual')
  32. + Word(hexnums)
  33. + Literal(symbol)
  34. + LineEnd())
  35. try:
  36. results = pattern.searchString(contents)[0]
  37. except IndexError:
  38. raise Exception("check placement fail: '%s' was not found" % (symbol))
  39. if results.actual != expected:
  40. raise Exception("check placement fail: '%s' was placed in '%s', not in '%s'" % (symbol, results.actual, expected))
  41. print("check placement pass: '%s' was successfully placed in '%s'" % (symbol, results.actual))
  42. return int(results.address, 16)
  43. # src1:func1 (noflash) - explicit mapping for func2 using 'rtc' scheme
  44. # should have been dropped since it is unreferenced.
  45. func1 = check_location('func1', '.iram0.text')
  46. sym1_start = check_location('_sym1_start', '*ABS*')
  47. sym1_end = check_location('_sym1_end', '*ABS*')
  48. assert func1 >= sym1_start, 'check placement fail: func1 comes before __sym1_start'
  49. assert func1 < sym1_end, 'check placement fail: func1 comes after __sym1_end'
  50. assert sym1_start % 9 == 0, '_sym1_start is not aligned as specified in linker fragment'
  51. assert sym1_end % 12 == 0, '_sym1_end is not aligned as specified in linker fragment'
  52. print('check placement pass: _sym1_start < func1 < __sym1_end and alignments checked')
  53. # src1:func2 (rtc) - explicit mapping for func2 using 'rtc' scheme
  54. check_location('func2', '.rtc.text')
  55. # src1 (default) - only func3 in src1 remains that has not been
  56. # mapped using a different scheme
  57. check_location('func3', '.flash.text')
  58. check_location('func4', '.iram0.text')