This is an automated email from Gerrit.

"ahmed BOUDJELIDA <aboudjel...@nanoxplore.com>" just uploaded a new patch set 
to Gerrit, which you can find at https://review.openocd.org/c/openocd/+/8737

-- gerrit

commit d6f2cd0f35c9c48617ed853a5da7c5b94c791fde
Author: Ahmed BOUDJELIDA <aboudjel...@nanoxplore.com>
Date:   Mon Jan 27 14:34:48 2025 +0100

    jtag/drivers: add virtualbox detection for angie driver
    
    When running OpenOcd on a VirtualBox linux, we need to
    add more delay for FX2 microcontroller renumeration.
    so we need to detect when we are on a virtualBox
    machine and add the delay.
    
    Change-Id: I92192e1e6d52505e7959221db0abeeb4cb31c008
    Signed-off-by: Ahmed BOUDJELIDA <aboudjel...@nanoxplore.com>

diff --git a/src/jtag/drivers/angie.c b/src/jtag/drivers/angie.c
index 89f284e8b5..6ee243df07 100644
--- a/src/jtag/drivers/angie.c
+++ b/src/jtag/drivers/angie.c
@@ -30,6 +30,7 @@
 
 /* system includes */
 #include <string.h>
+#include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
 #include <sys/time.h>
@@ -65,7 +66,7 @@
 #define FIRMWARE_ADDR  0x0000
 
 /** Delay (in microseconds) to wait while EZ-USB performs ReNumeration. */
-#define ANGIE_RENUMERATION_DELAY_US    2500000
+uint32_t ANGIE_RENUMERATION_DELAY_US;
 
 /** Default location of ANGIE firmware image. */
 #define ANGIE_FIRMWARE_FILE    PKGDATADIR "/angie/angie_firmware.bin"
@@ -627,7 +628,7 @@ static int angie_load_bitstream(struct angie *device, const 
char *filename)
        h_u32_to_be(gpifcnt, bitstream_size);
        ret = jtag_libusb_control_transfer(device->usbdev,
                                                                        
LIBUSB_ENDPOINT_OUT | LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_RECIPIENT_DEVICE,
-                                                                       
VR_CFGOPEN, 0, 0, (char *)gpifcnt, 4, 100, &transferred);
+                                                                       
VR_CFGOPEN, 0, 0, (char *)gpifcnt, 4, 1000, &transferred);
        if (ret != ERROR_OK) {
                LOG_ERROR("Failed opencfg");
                return ERROR_FAIL;
@@ -1175,6 +1176,30 @@ static int angie_quit(void)
        return ERROR_OK;
 }
 
+/**
+ * Angie virtualbox detection method
+ *
+ * @return error code
+ */
+static bool is_virtualbox(void)
+{
+       FILE *dmi = fopen("/sys/class/dmi/id/product_name", "r");
+       char buffer[256];
+       if (!dmi) {
+               LOG_ERROR("fopen");
+               return false;
+       }
+       if (fgets(buffer, sizeof(buffer), dmi)) {
+               if (strstr(buffer, "VirtualBox")) {
+                       fclose(dmi);
+                       LOG_INFO("Detected VirtualBox");
+                       return true;
+               }
+       }
+       fclose(dmi);
+       return false;
+}
+
 /**
  * Angie initialization method
  *
@@ -1184,6 +1209,11 @@ static int angie_init(void)
 {
        int ret = ERROR_OK;
 
+       if (is_virtualbox())
+               ANGIE_RENUMERATION_DELAY_US = 2500000;
+       else
+               ANGIE_RENUMERATION_DELAY_US = 800000;
+
        angie_handle = calloc(1, sizeof(*angie_handle));
        if (!angie_handle) {
                ret = ERROR_FAIL;
@@ -1294,6 +1324,35 @@ static int angie_speed_div(int divisor, int *khz)
        return ERROR_OK;
 }
 
+/**
+ * Handle the AT91SAM9 CLE command for specifying the address line to use for
+ * writing commands to a NAND device.
+ */
+COMMAND_HANDLER(handle_vm_activate_command)
+{
+       bool activate = false;
+
+       if (CMD_ARGC != 1) {
+               LOG_ERROR("Usage: vm_activate <true|false>");
+               return ERROR_COMMAND_SYNTAX_ERROR;
+       }
+
+       if (strcmp(CMD_ARGV[0], "true") == 0) {
+               activate = true;
+               ANGIE_RENUMERATION_DELAY_US = 2500000;
+       } else if (strcmp(CMD_ARGV[0], "false") == 0) {
+               activate = false;
+               ANGIE_RENUMERATION_DELAY_US = 800000;
+       } else {
+               LOG_ERROR("Invalid argument, use 'true' or 'false'");
+               return ERROR_COMMAND_ARGUMENT_INVALID;
+       }
+
+       LOG_INFO("VM activate set to %s", activate ? "true" : "false");
+
+       return ERROR_OK;
+}
+
 /**
  * Angie custom command memaccess_tck
  *
@@ -1339,6 +1398,13 @@ static const struct command_registration 
angie_subcommand_handlers[] = {
                .usage = "",
                .help = "Modify memaccess count for runtest iteration",
        },
+       {
+               .name = "vm_activate",
+               .handler = handle_vm_activate_command,
+               .mode = COMMAND_CONFIG,
+               .help = "set command vm delay activate",
+               .usage = "<true|false>",
+       },
        COMMAND_REGISTRATION_DONE
 };
 

-- 

Reply via email to