@@ -30,6 +30,82 @@ def __call__(self, parser, namespace, values, option_string=None):
30
30
# Espressif #
31
31
32
32
33
+ def run_espressif_tool (cmd ):
34
+ tool = "esptool.py"
35
+ strings_out = ""
36
+ command = "{} {}" .format (tool , cmd )
37
+
38
+ strings_out = subprocess .run (
39
+ command , universal_newlines = True , shell = True , capture_output = True
40
+ )
41
+
42
+ return strings_out .stdout
43
+
44
+
45
+ def get_espressif_chip_id ():
46
+ output = run_espressif_tool ("chip_id" )
47
+ string_out = next ((s for s in output .split ("\n " ) if "Chip ID" in s ), "Not found" )
48
+ if string_out != "Not found" :
49
+ string_out = string_out .split ("Warning: " )[- 1 ]
50
+ return string_out
51
+
52
+
53
+ def get_espressif_flash_id ():
54
+ strings_out = []
55
+ output = run_espressif_tool ("flash_id" )
56
+
57
+ strings_out .append (
58
+ next (
59
+ (s for s in output .split ("\n " ) if "Manufacturer" in s ),
60
+ "Manufacturer: Not found" ,
61
+ )
62
+ )
63
+ strings_out .append (
64
+ next ((s for s in output .split ("\n " ) if "Device" in s ), "Device: Not found" )
65
+ )
66
+
67
+ return strings_out
68
+
69
+
70
+ def get_espressif_security_info ():
71
+ output = run_espressif_tool ("get_security_info" )
72
+
73
+ start_string = "====================="
74
+ stop_string = "Hard resetting via RTS pin..."
75
+ output = output .split ("\n " )
76
+ strings_out = []
77
+
78
+ str_out = next ((s for s in output if start_string in s ), "Not found" )
79
+ if str_out != "Not found" :
80
+ start_index = output .index (start_string ) + 1
81
+ stop_index = output .index (stop_string )
82
+ strings_out = output [start_index :stop_index ]
83
+ else :
84
+ strings_out .append (str_out )
85
+
86
+ return strings_out
87
+
88
+
89
+ def get_espressif_flash_status ():
90
+ output = run_espressif_tool ("read_flash_status" )
91
+
92
+ string_out = next (
93
+ (s for s in output .split ("\n " ) if "Status value" in s ), "Not found"
94
+ )
95
+ if string_out != "Not found" :
96
+ string_out = string_out .split ("Status value: " )[- 1 ]
97
+ return string_out
98
+
99
+
100
+ def get_espressif_mac_address ():
101
+ output = run_espressif_tool ("read_mac" )
102
+
103
+ string_out = next ((s for s in output .split ("\n " ) if "MAC" in s ), "Not found" )
104
+ if string_out != "Not found" :
105
+ string_out = string_out .split ("MAC: " )[- 1 ]
106
+ return string_out
107
+
108
+
33
109
def get_espressif_bootloader_version (bindir ):
34
110
"""
35
111
Get the bootloader version for Espressif chips from the bootloader binary. This
@@ -557,6 +633,40 @@ def generate_header(args):
557
633
info ["ESPRESSIF_HAL" ]
558
634
)
559
635
636
+ if args .espressif_chip and info ["ESPRESSIF_ESPTOOL" ] not in "Not found" :
637
+ info ["ESPRESSIF_CHIP_ID" ] = get_espressif_chip_id ()
638
+ output += 'static const char ESPRESSIF_CHIP_ID[] = "{}";\n \n ' .format (
639
+ info ["ESPRESSIF_CHIP_ID" ]
640
+ )
641
+
642
+ info ["ESPRESSIF_FLASH_ID" ] = get_espressif_flash_id ()
643
+ output += "#define ESPRESSIF_FLASH_ID_ARRAY_SIZE {}\n " .format (
644
+ len (info ["ESPRESSIF_FLASH_ID" ])
645
+ )
646
+ output += "static const char *ESPRESSIF_FLASH_ID[ESPRESSIF_FLASH_ID_ARRAY_SIZE] =\n {\n "
647
+ for each_item in info ["ESPRESSIF_FLASH_ID" ]:
648
+ output += ' "{}",\n ' .format (each_item )
649
+ output += "};\n \n "
650
+
651
+ info ["ESPRESSIF_SECURITY_INFO" ] = get_espressif_security_info ()
652
+ output += "#define ESPRESSIF_SECURITY_INFO_ARRAY_SIZE {}\n " .format (
653
+ len (info ["ESPRESSIF_SECURITY_INFO" ])
654
+ )
655
+ output += "static const char *ESPRESSIF_SECURITY_INFO[ESPRESSIF_SECURITY_INFO_ARRAY_SIZE] =\n {\n "
656
+ for each_item in info ["ESPRESSIF_SECURITY_INFO" ]:
657
+ output += ' "{}",\n ' .format (each_item )
658
+ output += "};\n \n "
659
+
660
+ info ["ESPRESSIF_FLASH_STAT" ] = get_espressif_flash_status ()
661
+ output += 'static const char ESPRESSIF_FLASH_STAT[] = "{}";\n \n ' .format (
662
+ info ["ESPRESSIF_FLASH_STAT" ]
663
+ )
664
+
665
+ info ["ESPRESSIF_MAC_ADDR" ] = get_espressif_mac_address ()
666
+ output += 'static const char ESPRESSIF_MAC_ADDR[] = "{}";\n \n ' .format (
667
+ info ["ESPRESSIF_MAC_ADDR" ]
668
+ )
669
+
560
670
output += "#endif /* __SYSTEM_INFO_H */\n "
561
671
562
672
return output
@@ -590,6 +700,9 @@ def generate_header(args):
590
700
--espressif <ESPTOOL_BINDIR>:
591
701
Get Espressif specific information.
592
702
Requires the path to the bootloader binary directory.
703
+ --espressif_chip:
704
+ Get Espressif specific information about chip.
705
+ Requires device connection during build.
593
706
"""
594
707
595
708
# Generic arguments
@@ -647,6 +760,12 @@ def generate_header(args):
647
760
help = "Get Espressif specific information. Requires the path to the bootloader binary and ESP HAL directories." ,
648
761
)
649
762
763
+ parser .add_argument (
764
+ "--espressif_chip" ,
765
+ action = "store_true" ,
766
+ help = "Get Espressif specific information about chip. Requires device connection during build." ,
767
+ )
768
+
650
769
# Parse arguments
651
770
652
771
if len (sys .argv ) == 1 :
0 commit comments