[chip dv] Set +sw_images as comma-separated list

The `+sw_images` plusarg is currently set as a space separated list,
which requires it to be quoted. This plusarg is a part of `run_opts`,
which is yet another list of options that requires to be quoted too
(this means the quotes used in `+sw_images` need to be escaped).

The entire make command further needs to be set as a string when
launching over bsub / Google Cloud, which requires ... (see where I am
going?). `shlex.quote` does not work unfortunately.

Rather than have to deal with the headache of having properly escaped
quotes within escaped quotes, this change makes the `+sw_images` plusarg
a comma-separated list instead.

It also fixes a bug in the wildcard substitution code that processes
`{eval_cmd}`.

Signed-off-by: Srikrishna Iyer <sriyer@google.com>
diff --git a/hw/top_earlgrey/dv/chip_sim_cfg.hjson b/hw/top_earlgrey/dv/chip_sim_cfg.hjson
index 10e02db..7ee6a0e 100644
--- a/hw/top_earlgrey/dv/chip_sim_cfg.hjson
+++ b/hw/top_earlgrey/dv/chip_sim_cfg.hjson
@@ -104,7 +104,8 @@
       sw_images: ["sw/device/otp_img/otp_img:3"],
       run_opts: ["+sw_build_bin_dir={sw_build_dir}/build-bin",
                  "+sw_build_device={sw_build_device}",
-                 "+sw_images='{sw_images}'"]
+                 // Separate individual SW images supplied to +sw_images plusarg by comma.
+                 "+sw_images={eval_cmd} echo {sw_images} | sed -E 's/\\s+/,/g'"]
     }
     {
       name: sw_test_mode
diff --git a/hw/top_earlgrey/dv/env/chip_env_cfg.sv b/hw/top_earlgrey/dv/env/chip_env_cfg.sv
index 3df3c9e..0fde328 100644
--- a/hw/top_earlgrey/dv/env/chip_env_cfg.sv
+++ b/hw/top_earlgrey/dv/env/chip_env_cfg.sv
@@ -134,7 +134,7 @@
     string sw_images_split[$];
 
     // Split sw_images with space.
-    str_utils_pkg::str_split(sw_images_string, sw_images_split);
+    str_utils_pkg::str_split(sw_images_string, sw_images_split, ",");
     `DV_CHECK_GT_FATAL(sw_images_split.size(), 0)
 
     foreach (sw_images_split[i]) begin
diff --git a/util/dvsim/utils.py b/util/dvsim/utils.py
index cb4ad2b..dd2cce2 100644
--- a/util/dvsim/utils.py
+++ b/util/dvsim/utils.py
@@ -165,7 +165,7 @@
             # command and we're done.
             cmd_matches = list(wildcard_re.finditer(cmd))
             if not cmd_matches:
-                var = var[:idx] + run_cmd(cmd)
+                var = var[:match.start()] + run_cmd(cmd)
                 continue
 
             # Otherwise, check that each of them is ignored, or that