Fork of the espurna firmware for `mhsw` switches
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

111 lines
3.7 KiB

6 years ago
  1. #!/usr/bin/env python
  2. from __future__ import print_function
  3. import os
  4. import sys
  5. from subprocess import call
  6. import click
  7. Import("env", "projenv")
  8. # ------------------------------------------------------------------------------
  9. # Utils
  10. # ------------------------------------------------------------------------------
  11. class Color(object):
  12. BLACK = '\x1b[1;30m'
  13. RED = '\x1b[1;31m'
  14. GREEN = '\x1b[1;32m'
  15. YELLOW = '\x1b[1;33m'
  16. BLUE = '\x1b[1;34m'
  17. MAGENTA = '\x1b[1;35m'
  18. CYAN = '\x1b[1;36m'
  19. WHITE = '\x1b[1;37m'
  20. LIGHT_GREY = '\x1b[0;30m'
  21. LIGHT_RED = '\x1b[0;31m'
  22. LIGHT_GREEN = '\x1b[0;32m'
  23. LIGHT_YELLOW = '\x1b[0;33m'
  24. LIGHT_BLUE = '\x1b[0;34m'
  25. LIGHT_MAGENTA = '\x1b[0;35m'
  26. LIGHT_CYAN = '\x1b[0;36m'
  27. LIGHT_WHITE = '\x1b[0;37m'
  28. def clr(color, text):
  29. return color + str(text) + '\x1b[0m'
  30. def print_warning(message, color=Color.LIGHT_YELLOW):
  31. print(clr(color, message), file=sys.stderr)
  32. def print_filler(fill, color=Color.WHITE, err=False):
  33. width, _ = click.get_terminal_size()
  34. if len(fill) > 1:
  35. fill = fill[0]
  36. out = sys.stderr if err else sys.stdout
  37. print(clr(color, fill * width), file=out)
  38. # ------------------------------------------------------------------------------
  39. # Callbacks
  40. # ------------------------------------------------------------------------------
  41. def remove_float_support():
  42. flags = " ".join(env['LINKFLAGS'])
  43. flags = flags.replace("-u _printf_float", "")
  44. flags = flags.replace("-u _scanf_float", "")
  45. newflags = flags.split()
  46. env.Replace(
  47. LINKFLAGS = newflags
  48. )
  49. def cpp_check(target, source, env):
  50. print("Started cppcheck...\n")
  51. call(["cppcheck", os.getcwd()+"/espurna", "--force", "--enable=all"])
  52. print("Finished cppcheck...\n")
  53. def check_size(target, source, env):
  54. (binary,) = target
  55. path = binary.get_abspath()
  56. size = os.stat(path).st_size
  57. print(clr(Color.LIGHT_BLUE, "Binary size: {} bytes".format(size)))
  58. # Warn 1MB variants about exceeding OTA size limit
  59. flash_size = int(env.BoardConfig().get("upload.maximum_size", 0))
  60. if (flash_size == 1048576) and (size >= 512000):
  61. print_filler("*", color=Color.LIGHT_YELLOW, err=True)
  62. print_warning("File is too large for OTA! Here you can find instructions on how to flash it:")
  63. print_warning("https://github.com/xoseperez/espurna/wiki/TwoStepUpdates", color=Color.LIGHT_CYAN)
  64. print_filler("*", color=Color.LIGHT_YELLOW, err=True)
  65. def dummy_ets_printf(target, source, env):
  66. (postmortem_src_file, ) = source
  67. (postmortem_obj_file, ) = target
  68. cmd = ["xtensa-lx106-elf-objcopy"]
  69. # recent Core switched to cpp+newlib & ets_printf_P
  70. cmd.extend(["--redefine-sym", "ets_printf=dummy_ets_printf"])
  71. cmd.extend(["--redefine-sym", "ets_printf_P=dummy_ets_printf"])
  72. cmd.append(postmortem_obj_file.get_abspath())
  73. env.Execute(env.VerboseAction(" ".join(cmd), "Removing ets_printf / ets_printf_P"))
  74. env.Depends(postmortem_obj_file,"$BUILD_DIR/src/dummy_ets_printf.c.o")
  75. # ------------------------------------------------------------------------------
  76. # Hooks
  77. # ------------------------------------------------------------------------------
  78. # Always show warnings for project code
  79. projenv.ProcessUnFlags("-w")
  80. # 2.4.0 and up
  81. remove_float_support()
  82. # two-step update hint when using 1MB boards
  83. env.AddPostAction("$BUILD_DIR/${PROGNAME}.bin", check_size)
  84. # disable postmortem printing to the uart. another one is in eboot, but this is what causes the most harm
  85. if "DISABLE_POSTMORTEM_STACKDUMP" in env["CPPFLAGS"]:
  86. env.AddPostAction("$BUILD_DIR/FrameworkArduino/core_esp8266_postmortem.c.o", dummy_ets_printf)
  87. env.AddPostAction("$BUILD_DIR/FrameworkArduino/core_esp8266_postmortem.cpp.o", dummy_ets_printf)