Skip to content

Commit d6edbd0

Browse files
eren-terziogluxiaoxiang781216
authored andcommitted
Improve nxdiag example for Espressif devices
1 parent 6c3ca23 commit d6edbd0

File tree

4 files changed

+139
-0
lines changed

4 files changed

+139
-0
lines changed

system/nxdiag/Kconfig

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,4 +68,10 @@ config SYSTEM_NXDIAG_ESPRESSIF
6868
---help---
6969
Enable Espressif-specific information and checks.
7070

71+
config SYSTEM_NXDIAG_ESPRESSIF_CHIP
72+
bool "Espressif Chip"
73+
default n
74+
---help---
75+
Enable Espressif-specific information about chip. Chip must be connected during build process.
76+
7177
endif # SYSTEM_NXDIAG

system/nxdiag/Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,10 @@ else
8989
NXDIAG_FLAGS += --espressif "$(TOPDIR)" "$(HALDIR)"
9090
endif
9191

92+
ifeq ($(CONFIG_SYSTEM_NXDIAG_ESPRESSIF_CHIP),y)
93+
NXDIAG_FLAGS += --espressif_chip
94+
endif
95+
9296
endif
9397

9498
# Common build

system/nxdiag/nxdiag.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,16 @@ int main(int argc, char *argv[])
345345
print_array(ESPRESSIF_TOOLCHAIN, ESPRESSIF_TOOLCHAIN_ARRAY_SIZE);
346346
printf("Esptool version: %s\n\n", ESPRESSIF_ESPTOOL);
347347
printf("HAL version: %s\n\n", ESPRESSIF_HAL);
348+
#ifdef CONFIG_SYSTEM_NXDIAG_ESPRESSIF_CHIP
349+
printf("CHIP ID: %s\n\n", ESPRESSIF_CHIP_ID);
350+
printf("Flash ID:\n");
351+
print_array(ESPRESSIF_FLASH_ID, ESPRESSIF_FLASH_ID_ARRAY_SIZE);
352+
printf("Security information:\n");
353+
print_array(ESPRESSIF_SECURITY_INFO,
354+
ESPRESSIF_SECURITY_INFO_ARRAY_SIZE);
355+
printf("Flash status: %s\n\n", ESPRESSIF_FLASH_STAT);
356+
printf("MAC address: %s\n\n", ESPRESSIF_MAC_ADDR);
357+
#endif
348358
#endif
349359
}
350360

tools/host_sysinfo.py

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,82 @@ def __call__(self, parser, namespace, values, option_string=None):
3030
# Espressif #
3131

3232

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+
33109
def get_espressif_bootloader_version(bindir):
34110
"""
35111
Get the bootloader version for Espressif chips from the bootloader binary. This
@@ -557,6 +633,40 @@ def generate_header(args):
557633
info["ESPRESSIF_HAL"]
558634
)
559635

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+
560670
output += "#endif /* __SYSTEM_INFO_H */\n"
561671

562672
return output
@@ -590,6 +700,9 @@ def generate_header(args):
590700
--espressif <ESPTOOL_BINDIR>:
591701
Get Espressif specific information.
592702
Requires the path to the bootloader binary directory.
703+
--espressif_chip:
704+
Get Espressif specific information about chip.
705+
Requires device connection during build.
593706
"""
594707

595708
# Generic arguments
@@ -647,6 +760,12 @@ def generate_header(args):
647760
help="Get Espressif specific information. Requires the path to the bootloader binary and ESP HAL directories.",
648761
)
649762

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+
650769
# Parse arguments
651770

652771
if len(sys.argv) == 1:

0 commit comments

Comments
 (0)