Skip to content

Commit

Permalink
Improve nxdiag example for Espressif devices
Browse files Browse the repository at this point in the history
  • Loading branch information
eren-terzioglu committed Nov 1, 2024
1 parent 34ca696 commit 3034162
Show file tree
Hide file tree
Showing 4 changed files with 122 additions and 0 deletions.
6 changes: 6 additions & 0 deletions system/nxdiag/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,10 @@ config SYSTEM_NXDIAG_ESPRESSIF
---help---
Enable Espressif-specific information and checks.

config SYSTEM_NXDIAG_ESPRESSIF_CHIP
bool "Espressif Chip"
default n
---help---
Enable Espressif-specific information about chip. Chip must be connected during build process.

endif # SYSTEM_NXDIAG
4 changes: 4 additions & 0 deletions system/nxdiag/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ else
NXDIAG_FLAGS += --espressif "$(TOPDIR)" "$(HALDIR)"
endif

ifeq ($(CONFIG_SYSTEM_NXDIAG_ESPRESSIF_CHIP),y)
NXDIAG_FLAGS += --espressif_chip
endif

endif

# Common build
Expand Down
9 changes: 9 additions & 0 deletions system/nxdiag/nxdiag.c
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,15 @@ int main(int argc, char *argv[])
print_array(ESPRESSIF_TOOLCHAIN, ESPRESSIF_TOOLCHAIN_ARRAY_SIZE);
printf("Esptool version: %s\n\n", ESPRESSIF_ESPTOOL);
printf("HAL version: %s\n\n", ESPRESSIF_HAL);
#ifdef CONFIG_SYSTEM_NXDIAG_ESPRESSIF_CHIP
printf("CHIP ID: %s\n\n", ESPRESSIF_CHIP_ID);
printf("Flash ID:\n");
print_array(ESPRESSIF_FLASH_ID, ESPRESSIF_FLASH_ID_ARRAY_SIZE);
printf("Security information:\n");
print_array(ESPRESSIF_SECURITY_INFO, ESPRESSIF_SECURITY_INFO_ARRAY_SIZE);

Check failure on line 353 in system/nxdiag/nxdiag.c

View workflow job for this annotation

GitHub Actions / check

Long line found
printf("Flash status: %s\n\n", ESPRESSIF_FLASH_STAT);
printf("MAC address: %s\n\n", ESPRESSIF_MAC_ADDR);
#endif
#endif
}

Expand Down
103 changes: 103 additions & 0 deletions tools/host_sysinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,66 @@ def __call__(self, parser, namespace, values, option_string=None):

# Espressif #

def run_espressif_tool(cmd):
tool = "esptool.py"
strings_out = ""
command = "{} {}".format(tool, cmd)

strings_out = subprocess.run(
command, universal_newlines=True, shell=True, capture_output=True
)

return strings_out.stdout

def get_espressif_chip_id():
output = run_espressif_tool("chip_id")
string_out = next((s for s in output.split("\n") if "Chip ID" in s), "Not found")
if string_out != "Not found":
string_out = string_out.split("Warning: ")[-1]
return string_out

def get_espressif_flash_id():
strings_out = []
output = run_espressif_tool("flash_id")

strings_out.append(next((s for s in output.split("\n") if "Manufacturer" in s), "Manufacturer: Not found"))
strings_out.append(next((s for s in output.split("\n") if "Device" in s), "Device: Not found"))

return strings_out

def get_espressif_security_info():
output = run_espressif_tool("get_security_info")

start_string = "====================="
stop_string = "Hard resetting via RTS pin..."
output = output.split("\n")
strings_out = []

str_out = next((s for s in output if start_string in s), "Not found")
if str_out != "Not found":
start_index = output.index(start_string) + 1
stop_index = output.index(stop_string)
strings_out = output[start_index:stop_index]
else:
strings_out.append(str_out)

return strings_out

def get_espressif_flash_status():
output = run_espressif_tool("read_flash_status")

string_out = next((s for s in output.split("\n") if "Status value" in s), "Not found")
if string_out != "Not found":
string_out = string_out.split("Status value: ")[-1]
return string_out

def get_espressif_mac_address():
output = run_espressif_tool("read_mac")

string_out = next((s for s in output.split("\n") if "MAC" in s), "Not found")
if string_out != "Not found":
string_out = string_out.split("MAC: ")[-1]
return string_out

def get_espressif_bootloader_version(bindir):
"""
Expand Down Expand Up @@ -557,6 +617,40 @@ def generate_header(args):
info["ESPRESSIF_HAL"]
)

if args.espressif_chip and info["ESPRESSIF_ESPTOOL"] not in "Not found":
info["ESPRESSIF_CHIP_ID"] = get_espressif_chip_id()
output += 'static const char ESPRESSIF_CHIP_ID[] = "{}";\n\n'.format(
info["ESPRESSIF_CHIP_ID"]
)

info["ESPRESSIF_FLASH_ID"] = get_espressif_flash_id()
output += "#define ESPRESSIF_FLASH_ID_ARRAY_SIZE {}\n".format(
len(info["ESPRESSIF_FLASH_ID"])
)
output += "static const char *ESPRESSIF_FLASH_ID[ESPRESSIF_FLASH_ID_ARRAY_SIZE] =\n{\n"
for each_item in info["ESPRESSIF_FLASH_ID"]:
output += ' "{}",\n'.format(each_item)
output += "};\n\n"

info["ESPRESSIF_SECURITY_INFO"] = get_espressif_security_info()
output += "#define ESPRESSIF_SECURITY_INFO_ARRAY_SIZE {}\n".format(
len(info["ESPRESSIF_SECURITY_INFO"])
)
output += "static const char *ESPRESSIF_SECURITY_INFO[ESPRESSIF_SECURITY_INFO_ARRAY_SIZE] =\n{\n"
for each_item in info["ESPRESSIF_SECURITY_INFO"]:
output += ' "{}",\n'.format(each_item)
output += "};\n\n"

info["ESPRESSIF_FLASH_STAT"] = get_espressif_flash_status()
output += 'static const char ESPRESSIF_FLASH_STAT[] = "{}";\n\n'.format(
info["ESPRESSIF_FLASH_STAT"]
)

info["ESPRESSIF_MAC_ADDR"] = get_espressif_mac_address()
output += 'static const char ESPRESSIF_MAC_ADDR[] = "{}";\n\n'.format(
info["ESPRESSIF_MAC_ADDR"]
)

output += "#endif /* __SYSTEM_INFO_H */\n"

return output
Expand Down Expand Up @@ -590,6 +684,9 @@ def generate_header(args):
--espressif <ESPTOOL_BINDIR>:
Get Espressif specific information.
Requires the path to the bootloader binary directory.
--espressif_chip:
Get Espressif specific information about chip.
Requires device connection during build.
"""

# Generic arguments
Expand Down Expand Up @@ -647,6 +744,12 @@ def generate_header(args):
help="Get Espressif specific information. Requires the path to the bootloader binary and ESP HAL directories.",
)

parser.add_argument(
"--espressif_chip",
action='store_true',
help="Get Espressif specific information about chip. Requires device connection during build.",
)

# Parse arguments

if len(sys.argv) == 1:
Expand Down

0 comments on commit 3034162

Please sign in to comment.