Skip to contentSkip to conversation

runfvp: switch working directory to allow path relative to fvpconf

RFC In review Clément Péron 2 participants 5 messages May 11, 2023 – May 15, 2023

lore
Share & tools
lore
#0 lore raw

RFC 1/2 runfvp: switch working directory to allow path relative to fvpconf

fvpconf file contains absolute path that leak builder path.

Allow to add relative path by changing the chdir before loading the config file.

---
 scripts/runfvp | 6 ++++++
 1 file changed, 6 insertions(+)
scripts/runfvp +6 -0
index e4b00abc..f0d821be 100755
@@ -87,6 +87,12 @@ def runfvp(cli_args):
         config_file = args.config
     else:
         config_file = conffile.find(args.config)
+
+    # Path inside the config could be relative to the config file
+    working_directory = os.path.dirname(config_file)
+    logger.debug(f"Switching the working directory to {working_directory}")
+    os.chdir(working_directory)
+
     logger.debug(f"Loading {config_file}")
     config = conffile.load(config_file)
     start_fvp(args, config, extra_args)
Signature · 1 line
2.40.1
#1 lore raw

RFC 2/2 runfvp: update filepath in fvpconf to relative path

Using absolute path in fvpconf will leak the host machine path.

This is a bit annoying when the builder and the runner doesn't use the same filepath hierachy.

Switch to relative path instead of absolute.

---
 documentation/runfvp.md                           |  8 ++++----
 meta-arm-bsp/conf/machine/corstone1000-fvp.conf   |  6 +++---
 meta-arm-bsp/conf/machine/corstone500.conf        |  4 ++--
 meta-arm-bsp/conf/machine/fvp-baser-aemv8r64.conf |  4 ++--
 meta-arm-bsp/conf/machine/include/fvp-common.inc  | 10 +++++-----
 meta-arm-bsp/conf/machine/tc1.conf                |  8 ++++----
 6 files changed, 20 insertions(+), 20 deletions(-)
documentation/runfvp.md +4 -4
index 01b13693..b3c6467f 100644
@@ -64,7 +64,7 @@ If `FVP_PROVIDER` is not set then it is assumed that `FVP_EXE` is installed on t
 Parameters passed to the FVP with the `--parameter`/`-C` option.  These are expressed as variable flags so individual parameters can be altered easily. For example:
 
 ```
-FVP_CONFIG[bp.flashloader0.fname] = "${DEPLOY_DIR_IMAGE}/fip-fvp.bin"
+FVP_CONFIG[bp.flashloader0.fname] = "fip-fvp.bin"
 ```
 
 ### `FVP_DATA`
@@ -72,8 +72,8 @@ FVP_CONFIG[bp.flashloader0.fname] = "${DEPLOY_DIR_IMAGE}/fip-fvp.bin"
 Specify raw data to load at the specified address, passed to the FVP with the `--data` option.  This is a space-separated list of parameters in the format `[INST=]FILE@[MEMSPACE:]ADDRESS`. For example:
 
 ```
-FVP_DATA = "cluster0.cpu0=${DEPLOY_DIR_IMAGE}/Image@0x80080000 \
-            cluster0.cpu0=${DEPLOY_DIR_IMAGE}/fvp-base-revc.dtb@0x83000000"
+FVP_DATA = "cluster0.cpu0=Image@0x80080000 \
+            cluster0.cpu0=fvp-base-revc.dtb@0x83000000"
 ```
 
 ### `FVP_APPLICATIONS`
@@ -81,7 +81,7 @@ FVP_DATA = "cluster0.cpu0=${DEPLOY_DIR_IMAGE}/Image@0x80080000 \
 Applications to load on the cores, passed to the FVP with the `--application` option.  These are expressed as variable flags with the flag name being the instance and flag value the filename, for example:
 
 ```
-FVP_APPLICATIONS[cluster0] = "${DEPLOY_DIR_IMAGE}/linux-system.axf"
+FVP_APPLICATIONS[cluster0] = "linux-system.axf"
 ```
 
 Note that symbols are not allowed in flag names, so if you need to use a wildcard in the instance then you'll need to use `FVP_EXTRA_ARGS` and `--application` directly.
meta-arm-bsp/conf/machine/corstone1000-fvp.conf +3 -3
index 03577b8e..66236515 100644
@@ -17,7 +17,7 @@ FVP_EXE ?= "FVP_Corstone-1000"
 FVP_CONSOLE ?= "host_terminal_0"
 
 # FVP Parameters
-FVP_CONFIG[se.trustedBootROMloader.fname] ?= "${DEPLOY_DIR_IMAGE}/bl1.bin"
+FVP_CONFIG[se.trustedBootROMloader.fname] ?= "bl1.bin"
 FVP_CONFIG[board.xnvm_size] ?= "64"
 FVP_CONFIG[se.trustedSRAM_config] ?= "6"
 FVP_CONFIG[se.BootROM_config] ?= "3"
@@ -32,10 +32,10 @@ FVP_CONFIG[se.nvm.update_raw_image] ?= "0"
 FVP_CONFIG[se.cryptocell.USER_OTP_FILTERING_DISABLE] ?= "1"
 
 # Boot image
-FVP_DATA ?= "board.flash0=${DEPLOY_DIR_IMAGE}/${IMAGE_NAME}.rootfs.wic@0x68000000"
+FVP_DATA ?= "board.flash0=${IMAGE_NAME}.rootfs.wic@0x68000000"
 
 # External system (cortex-M3)
-FVP_CONFIG[extsys_harness0.extsys_flashloader.fname] ?= "${DEPLOY_DIR_IMAGE}/es_flashfw.bin"
+FVP_CONFIG[extsys_harness0.extsys_flashloader.fname] ?= "es_flashfw.bin"
 
 # FVP Terminals
 FVP_TERMINALS[host.host_terminal_0] ?= "Normal World Console"
meta-arm-bsp/conf/machine/corstone500.conf +2 -2
index a599660c..c13c86c0 100644
@@ -38,8 +38,8 @@ TEST_SUITES = "linuxboot"
 
 FVP_PROVIDER ?= "fvp-corstone500-native"
 FVP_EXE ?= "FVP_Corstone-500"
-FVP_CONFIG[board.flashloader0.fname] ?= "${DEPLOY_DIR_IMAGE}/bl1.bin"
-FVP_DATA ?= "css.cluster.cpu0=${DEPLOY_DIR_IMAGE}/${IMAGE_NAME}.rootfs.wic.nopt@0x80000000"
+FVP_CONFIG[board.flashloader0.fname] ?= "bl1.bin"
+FVP_DATA ?= "css.cluster.cpu0=${IMAGE_NAME}.rootfs.wic.nopt@0x80000000"
 FVP_CONSOLE ?= "terminal_0"
 FVP_TERMINALS[css.terminal_0] ?= "console"
 FVP_TERMINALS[css.terminal_1] ?= ""
meta-arm-bsp/conf/machine/fvp-baser-aemv8r64.conf +2 -2
index 0c2ea122..62c9cbd0 100644
@@ -34,7 +34,7 @@ TEST_SUITES = "linuxboot"
 TEST_TARGET_IP ?= "127.0.0.1:8022"
 TEST_SERVER_IP ?= "127.0.1.1"
 
-FVP_EXTRA_ARGS = "-a cluster0*=${DEPLOY_DIR_IMAGE}/linux-system.axf"
+FVP_EXTRA_ARGS = "-a cluster0*=linux-system.axf"
 FVP_PROVIDER ?= "fvp-base-r-aem-native"
 FVP_EXE ?= "FVP_BaseR_AEMv8R"
 FVP_CONSOLE ?= "terminal_0"
@@ -50,7 +50,7 @@ FVP_CONFIG[bp.virtio_net.hostbridge.userNetworking] ?= "1"
 FVP_CONFIG[bp.virtio_net.secure_accesses] = "1"
 FVP_CONFIG[bp.virtio_rng.enabled] ?= "1"
 FVP_CONFIG[bp.virtio_rng.secure_accesses] = "1"
-FVP_CONFIG[bp.virtioblockdevice.image_path] ?= "${DEPLOY_DIR_IMAGE}/${IMAGE_NAME}.rootfs.wic"
+FVP_CONFIG[bp.virtioblockdevice.image_path] ?= "${IMAGE_NAME}.rootfs.wic"
 FVP_CONFIG[bp.virtioblockdevice.secure_accesses] = "1"
 FVP_CONFIG[cache_state_modelled] ?= "0"
 FVP_CONFIG[cci400.force_on_from_start] = "1"
meta-arm-bsp/conf/machine/include/fvp-common.inc +5 -5
index 233c734f..47b7ffce 100644
@@ -33,15 +33,15 @@ FVP_CONFIG[bp.virtio_net.hostbridge.userNetworking] ?= "1"
 # Tell testimage to connect to localhost:8022, and forward that to SSH in the FVP.
 FVP_CONFIG[bp.virtio_net.hostbridge.userNetPorts] = "8022=22"
 FVP_CONFIG[cache_state_modelled] ?= "0"
-FVP_CONFIG[bp.secureflashloader.fname] ?= "${DEPLOY_DIR_IMAGE}/bl1-fvp.bin"
-FVP_CONFIG[bp.flashloader0.fname] ?= "${DEPLOY_DIR_IMAGE}/fip-fvp.bin"
-FVP_CONFIG[bp.virtioblockdevice.image_path] ?= "${DEPLOY_DIR_IMAGE}/${IMAGE_NAME}.rootfs.wic"
+FVP_CONFIG[bp.secureflashloader.fname] ?= "bl1-fvp.bin"
+FVP_CONFIG[bp.flashloader0.fname] ?= "fip-fvp.bin"
+FVP_CONFIG[bp.virtioblockdevice.image_path] ?= "${IMAGE_NAME}.rootfs.wic"
 # Set the baseline to ARMv8.4, as the default is 8.0.
 FVP_CONFIG[cluster0.has_arm_v8-4] = "1"
 FVP_CONFIG[cluster1.has_arm_v8-4] = "1"
 FVP_CONSOLE ?= "terminal_0"
-FVP_DATA ?= "cluster0.cpu0=${DEPLOY_DIR_IMAGE}/${KERNEL_IMAGETYPE}@0x80080000 \
-             cluster0.cpu0=${DEPLOY_DIR_IMAGE}/fvp-base-revc.dtb@0x8fc00000"
+FVP_DATA ?= "cluster0.cpu0=${KERNEL_IMAGETYPE}@0x80080000 \
+             cluster0.cpu0=fvp-base-revc.dtb@0x8fc00000"
 FVP_TERMINALS[bp.terminal_0] ?= "Console"
 FVP_TERMINALS[bp.terminal_1] ?= ""
 FVP_TERMINALS[bp.terminal_2] ?= ""
meta-arm-bsp/conf/machine/tc1.conf +4 -4
index f99bfd2b..5f68cc7a 100644
@@ -14,9 +14,9 @@ FVP_PROVIDER ?= "fvp-tc1-native"
 FVP_EXE ?= "FVP_TC1"
 
 # FVP Parameters
-FVP_CONFIG[css.scp.ROMloader.fname] ?= "${DEPLOY_DIR_IMAGE}/scp_romfw.bin"
-FVP_CONFIG[css.trustedBootROMloader.fname] ?= "${DEPLOY_DIR_IMAGE}/bl1-tc.bin"
-FVP_CONFIG[board.flashloader0.fname] ?= "${DEPLOY_DIR_IMAGE}/fip_gpt-tc.bin"
+FVP_CONFIG[css.scp.ROMloader.fname] ?= "scp_romfw.bin"
+FVP_CONFIG[css.trustedBootROMloader.fname] ?= "bl1-tc.bin"
+FVP_CONFIG[board.flashloader0.fname] ?= "fip_gpt-tc.bin"
 
 #FVP_CONFIG[board.hostbridge.userNetworking] ?= "true"
 #FVP_CONFIG[board.hostbridge.userNetPorts] ?= "8022=22"
@@ -28,4 +28,4 @@ FVP_TERMINALS[soc.terminal_s0] ?= "Secure Console"
 FVP_TERMINALS[soc.terminal_s1] ?= "Console"
 
 # Boot image
-FVP_DATA ?= "board.dram=${DEPLOY_DIR_IMAGE}/fitImage-core-image-minimal-tc1-tc1@0x20000000"
+FVP_DATA ?= "board.dram=fitImage-core-image-minimal-tc1-tc1@0x20000000"
Signature · 1 line
2.40.1
#2 lore raw
In reply to Clément Péron

Hi Clement,

Quoted 4 lines · Clément Péron via lists.yoctoproject.org

fvpconf file contains absolute path that leak builder path.

Allow to add relative path by changing the chdir before loading the config file.

The fvpconf file is read by both runfvp and also a custom OE testimage controller [1] which we use heavily for runtime validation - I think these patches will break this use case.

It should be possible to set the 'cwd' argument of subprocess.Popen in the common code [2]. It might require another patch to move conffile loading into the common code though so that its filename is accessible...

We also have an oe-selftest for this common code [3], which may need updating.

[1] https://git.yoctoproject.org/meta-arm/tree/meta-arm/lib/oeqa/controllers/fvp.py
[2] https://git.yoctoproject.org/meta-arm/tree/meta-arm/lib/fvp/runner.py#n99
[3] https://git.yoctoproject.org/meta-arm/tree/meta-arm/lib/oeqa/selftest/cases/runfvp.py

Peter

Quoted 32 lines
---
  scripts/runfvp | 6 ++++++
  1 file changed, 6 insertions(+)
scripts/runfvp +6 -1
index e4b00abc..f0d821be 100755
@@ -87,6 +87,12 @@ def runfvp(cli_args):
          config_file = args.config
      else:
          config_file = conffile.find(args.config)
+
+    # Path inside the config could be relative to the config file
+    working_directory = os.path.dirname(config_file)
+    logger.debug(f"Switching the working directory to {working_directory}")
+    os.chdir(working_directory)
+
      logger.debug(f"Loading {config_file}")
      config = conffile.load(config_file)
      start_fvp(args, config, extra_args)
 
-=-=-=-=-=-=-=-=-=-=-=-

Links: You receive all messages sent to this group.
View/Reply Online (#4641): https://lists.yoctoproject.org/g/meta-arm/message/4641
Mute This Topic: https://lists.yoctoproject.org/mt/98830760/5715260
Group Owner: [email protected]
Unsubscribe: https://lists.yoctoproject.org/g/meta-arm/unsub [[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-

#3 lore raw

Hi Peter,

Quoted 4 lines · Peter Hoyes

Hi Clement,

On 11/05/2023 17:01, Clément Péron via lists.yoctoproject.org wrote:

Quoted 8 lines
Quoted 4 lines

fvpconf file contains absolute path that leak builder path.

Allow to add relative path by changing the chdir before loading the config file.

The fvpconf file is read by both runfvp and also a custom OE testimage controller [1] which we use heavily for runtime validation - I think these patches will break this use case.

Thanks for the review and the explanation,

So this will make the config read multiple times right? one time in the caller and one time in the callee.

What about passing the conf working directory as a param of FVPRunner.start() ?

Something like this:
def start(self, fvpconf, extra_args=[], terminal_choice="none", stdout=subprocess.PIPE, fvp_cwd=None):

Regards,
Clement

Quoted 49 lines

It should be possible to set the 'cwd' argument of subprocess.Popen in the common code [2]. It might require another patch to move conffile loading into the common code though so that its filename is accessible...

We also have an oe-selftest for this common code [3], which may need updating.

[1]
https://git.yoctoproject.org/meta-arm/tree/meta-arm/lib/oeqa/controllers/fvp.py
[2]
https://git.yoctoproject.org/meta-arm/tree/meta-arm/lib/fvp/runner.py#n99
[3]
https://git.yoctoproject.org/meta-arm/tree/meta-arm/lib/oeqa/selftest/cases/runfvp.py

Peter

Quoted 32 lines
---
  scripts/runfvp | 6 ++++++
  1 file changed, 6 insertions(+)
scripts/runfvp +6 -1
index e4b00abc..f0d821be 100755
@@ -87,6 +87,12 @@ def runfvp(cli_args):
          config_file = args.config
      else:
          config_file = conffile.find(args.config)
+
+    # Path inside the config could be relative to the config file
+    working_directory = os.path.dirname(config_file)
+    logger.debug(f"Switching the working directory to {working_directory}")
+    os.chdir(working_directory)
+
      logger.debug(f"Loading {config_file}")
      config = conffile.load(config_file)
      start_fvp(args, config, extra_args)
 
-=-=-=-=-=-=-=-=-=-=-=-

Links: You receive all messages sent to this group.
View/Reply Online (#4641): https://lists.yoctoproject.org/g/meta-arm/message/4641
Mute This Topic: https://lists.yoctoproject.org/mt/98830760/5715260
Group Owner: [email protected]
Unsubscribe: https://lists.yoctoproject.org/g/meta-arm/unsub [[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-

#4 lore raw
Quoted 6 lines · Clément Péron

Hi Peter,

Quoted 3 lines · Peter Hoyes

Hi Clement,

On 11/05/2023 17:01, Clément Péron via lists.yoctoproject.org wrote:

Quoted 8 lines
Quoted 7 lines
Quoted 4 lines

fvpconf file contains absolute path that leak builder path.

Allow to add relative path by changing the chdir before loading the config file.

The fvpconf file is read by both runfvp and also a custom OE testimage controller [1] which we use heavily for runtime validation - I think these patches will break this use case.

Thanks for the review and the explanation,

Thanks for pursuing this refactor.

Quoted 3 lines

So this will make the config read multiple times right? one time in the caller and one time in the callee.

I'm not sure I understand fully, but the suggestion is to move all config reading logic inside FVPRunner.start() so that we only call conffile.load() in one place and the number of arguments to FVPRunner.start() is reduced.

Quoted 6 lines

What about passing the conf working directory as a param of FVPRunner.start() ?

Something like this:
def start(self, fvpconf, extra_args=[], terminal_choice="none", stdout=subprocess.PIPE, fvp_cwd=None):

I think it would make more sense to derive the cwd from the fvpconf filename? If the fvpconf file contents are inherently dependent on the cwd I don't think it makes sense to support alternate cwds.

Peter

Quoted 52 lines

Regards,
Clement

Quoted 47 lines

It should be possible to set the 'cwd' argument of subprocess.Popen in the common code [2]. It might require another patch to move conffile loading into the common code though so that its filename is accessible...

We also have an oe-selftest for this common code [3], which may need updating.

[1]
https://git.yoctoproject.org/meta-arm/tree/meta-arm/lib/oeqa/controllers/fvp.py
[2]
https://git.yoctoproject.org/meta-arm/tree/meta-arm/lib/fvp/runner.py#n99
[3]
https://git.yoctoproject.org/meta-arm/tree/meta-arm/lib/oeqa/selftest/cases/runfvp.py

Peter

Quoted 31 lines
---
   scripts/runfvp | 6 ++++++
   1 file changed, 6 insertions(+)
scripts/runfvp +6 -1
index e4b00abc..f0d821be 100755
@@ -87,6 +87,12 @@ def runfvp(cli_args):
           config_file = args.config
       else:
           config_file = conffile.find(args.config)
+
+    # Path inside the config could be relative to the config file
+    working_directory = os.path.dirname(config_file)
+    logger.debug(f"Switching the working directory to {working_directory}")
+    os.chdir(working_directory)
+
       logger.debug(f"Loading {config_file}")
       config = conffile.load(config_file)
       start_fvp(args, config, extra_args)
 
-=-=-=-=-=-=-=-=-=-=-=-

Links: You receive all messages sent to this group.
View/Reply Online (#4641): https://lists.yoctoproject.org/g/meta-arm/message/4641
Mute This Topic: https://lists.yoctoproject.org/mt/98830760/5715260
Group Owner: [email protected]
Unsubscribe: https://lists.yoctoproject.org/g/meta-arm/unsub [[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-