This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx-apps.git


The following commit(s) were added to refs/heads/master by this push:
     new d6edbd0ce Improve nxdiag example for Espressif devices
d6edbd0ce is described below

commit d6edbd0cec72cb44ceb9d0f5b932cbd7a2b96288
Author: Eren Terzioglu <[email protected]>
AuthorDate: Wed Oct 23 11:55:19 2024 +0200

    Improve nxdiag example for Espressif devices
---
 system/nxdiag/Kconfig  |   6 +++
 system/nxdiag/Makefile |   4 ++
 system/nxdiag/nxdiag.c |  10 +++++
 tools/host_sysinfo.py  | 119 +++++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 139 insertions(+)

diff --git a/system/nxdiag/Kconfig b/system/nxdiag/Kconfig
index 6a9f5c1e9..ceec711f8 100644
--- a/system/nxdiag/Kconfig
+++ b/system/nxdiag/Kconfig
@@ -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
diff --git a/system/nxdiag/Makefile b/system/nxdiag/Makefile
index 743610166..f25d17aac 100644
--- a/system/nxdiag/Makefile
+++ b/system/nxdiag/Makefile
@@ -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
diff --git a/system/nxdiag/nxdiag.c b/system/nxdiag/nxdiag.c
index b3e56240e..b7d94ff7e 100644
--- a/system/nxdiag/nxdiag.c
+++ b/system/nxdiag/nxdiag.c
@@ -345,6 +345,16 @@ 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);
+      printf("Flash status: %s\n\n", ESPRESSIF_FLASH_STAT);
+      printf("MAC address: %s\n\n", ESPRESSIF_MAC_ADDR);
+#endif
 #endif
     }
 
diff --git a/tools/host_sysinfo.py b/tools/host_sysinfo.py
index 4904038f0..2d25a0e0f 100755
--- a/tools/host_sysinfo.py
+++ b/tools/host_sysinfo.py
@@ -30,6 +30,82 @@ class validate_flags_arg(argparse.Action):
 # 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):
     """
     Get the bootloader version for Espressif chips from the bootloader binary. 
This
@@ -557,6 +633,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
@@ -590,6 +700,9 @@ if __name__ == "__main__":
             --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
@@ -647,6 +760,12 @@ if __name__ == "__main__":
         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:

Reply via email to