Hoa Nguyen has uploaded this change for review. ( https://gem5-review.googlesource.com/c/public/gem5/+/58791 )

Change subject: stdlib: Allow riscv-board to take more than 1 disk image
......................................................................

stdlib: Allow riscv-board to take more than 1 disk image

This is done by,
- Decoupling (PIO/VirtIO devices connection/device tree generation) and
the (set disk image workload function).
- Creating an abstract method for finializing all connections and device
tree generation in KernelDiskWorkload.
- The board now takes the `addtional_disk_array` parameter, which contains
a list of disk image resources. Those images should not be mounted during
kernel booting.
- The old `disk_image` parameter will now become the root disk image param.
This disk image should be mounted as '/' by the kernel.

Change-Id: I560496a4db5b4d91d3e3e90901487d8d40bf581b
Signed-off-by: Hoa Nguyen <hoangu...@ucdavis.edu>
---
M src/python/gem5/components/boards/kernel_disk_workload.py
M src/python/gem5/components/boards/riscv_board.py
2 files changed, 85 insertions(+), 26 deletions(-)



diff --git a/src/python/gem5/components/boards/kernel_disk_workload.py b/src/python/gem5/components/boards/kernel_disk_workload.py
index 031fc60..bfd5aa6 100644
--- a/src/python/gem5/components/boards/kernel_disk_workload.py
+++ b/src/python/gem5/components/boards/kernel_disk_workload.py
@@ -97,6 +97,17 @@
         """
         raise NotImplementedError

+    @abstractmethod
+    def _finalize_workload(self) -> None:
+        """
+        Finalizes the board setup dependent on the workload.
+        This function connects the IO devices to the board, generates the
+ device tree and expose the location of the dtb to the gem5's workload + object. This function should be called after all IO devices are set up
+        (e.g. disk images, PIO devices.)
+        """
+        raise NotImplementedError
+
     def get_disk_root_partition(
         cls, disk_image: AbstractResource
     ) -> Optional[str]:
@@ -132,7 +143,8 @@
     def set_kernel_disk_workload(
         self,
         kernel: AbstractResource,
-        disk_image: AbstractResource,
+        root_disk_image: AbstractResource,
+        additional_disk_array: List[AbstractResource],
         readfile: Optional[str] = None,
         readfile_contents: Optional[str] = None,
         kernel_args: Optional[List[str]] = None,
@@ -143,7 +155,10 @@
         and a disk image.

         :param kernel: The kernel to boot.
-        :param disk_image: The disk image to mount.
+ :param root_disk_image: The disk image containing the '/' mount point.
+        :param additional_disk_array: An array of disk images to be mount
+        manually (they are not mounted at durring the Linux kernel booting
+        process).
:param readfile: An optional parameter stating the file to be read by
         by `m5 readfile`.
:param readfile_contents: An optional parameter stating the contents of
@@ -163,7 +178,9 @@
         self.workload.command_line = (
             " ".join(kernel_args or self.get_default_kernel_args())
         ).format(
- root_value=self.get_default_kernel_root_val(disk_image=disk_image)
+            root_value=self.get_default_kernel_root_val(
+                disk_image=root_disk_image
+            )
         )

         # Set the readfile.
@@ -178,7 +195,12 @@
             file.write(readfile_contents)
             file.close()

-        self._add_disk_to_board(disk_image=disk_image)
+        self._add_disk_to_board(disk_image=root_disk_image)
+        for disk_image in additional_disk_array:
+            self._add_disk_to_board(disk_image=disk_image)
+
+        # Finalize the setup after all components of the workload are set.
+        self._finalize_workload()

         # Set whether to exit on work items.
-        self.exit_on_work_items = exit_on_work_items
\ No newline at end of file
+        self.exit_on_work_items = exit_on_work_items
diff --git a/src/python/gem5/components/boards/riscv_board.py b/src/python/gem5/components/boards/riscv_board.py
index f72b31d..b227b39 100644
--- a/src/python/gem5/components/boards/riscv_board.py
+++ b/src/python/gem5/components/boards/riscv_board.py
@@ -116,12 +116,7 @@
         self.iobus.default = self.iobus.badaddr_responder.pio

         # The virtio disk
-        self.disk = RiscvMmioVirtIO(
-            vio=VirtIOBlock(),
-            interrupt_id=0x8,
-            pio_size=4096,
-            pio_addr=0x10008000,
-        )
+        self.disk_array = []

         # The virtio rng
         self.rng = RiscvMmioVirtIO(
@@ -134,7 +129,8 @@
# Note: This overrides the platform's code because the platform isn't
         # general enough.
         self._on_chip_devices = [self.platform.clint, self.platform.plic]
-        self._off_chip_devices = [self.platform.uart, self.disk, self.rng]
+        self._off_chip_devices = [self.platform.uart, self.rng] \
+                                    + self.disk_array

     def _setup_io_devices(self) -> None:
         """Connect the I/O devices to the I/O bus"""
@@ -338,16 +334,17 @@
         soc_node.append(uart_node)

         # VirtIO MMIO disk node
-        disk = self.disk
-        disk_node = disk.generateBasicPioDeviceNode(
-            soc_state, "virtio_mmio", disk.pio_addr, disk.pio_size
-        )
- disk_node.append(FdtPropertyWords("interrupts", [disk.interrupt_id]))
-        disk_node.append(
-            FdtPropertyWords("interrupt-parent", soc_state.phandle(plic))
-        )
-        disk_node.appendCompatible(["virtio,mmio"])
-        soc_node.append(disk_node)
+        for disk in self.disk_image:
+            disk_node = disk.generateBasicPioDeviceNode(
+                soc_state, "virtio_mmio", disk.pio_addr, disk.pio_size
+            )
+            disk_node.append(FdtPropertyWords("interrupts",
+                                              [disk.interrupt_id]))
+            disk_node.append(
+ FdtPropertyWords("interrupt-parent", soc_state.phandle(plic))
+            )
+            disk_node.appendCompatible(["virtio,mmio"])
+            soc_node.append(disk_node)

         # VirtIO MMIO rng node
         rng = self.rng
@@ -374,15 +371,34 @@

     @overrides(KernelDiskWorkload)
     def _add_disk_to_board(self, disk_image: AbstractResource):
+        new_disk_pio_addr = 0x10008000 + 0x1000 * len(self.disk_array)
+        new_disk = RiscvMmioVirtIO(
+            vio=VirtIOBlock(),
+            interrupt_id=0x8,
+            pio_size=0x1000,
+            pio_addr=new_disk_pio_addr,
+        )
+
         image = CowDiskImage(
             child=RawDiskImage(read_only=True), read_only=False
         )
         image.child.image_file = disk_image.get_local_path()
-        self.disk.vio.image = image
+        new_disk.vio.image = image

- # Note: The below is a bit of a hack. We need to wait to generate the
-        # device tree until after the disk is set up. Now that the disk and
-        # workload are set, we can generate the device tree file.
+        # Default DTB address if bbl is built with --with-dts option
+        self.workload.dtb_addr = 0x87E00000
+
+        self.disk_array.append(new_disk)
+
+    @overrides(KernelDiskWorkload)
+    def _finalize_workload(self):
+        """
+        This function finalizes the board setup dependent on the workload.
+ This function will generate the device tree and expose the location of
+        the dtb to the gem5's workload object.
+        This function should be called after all IO devices are set up
+        (e.g. disk images, PIO devices.)
+        """
         self._setup_io_devices()
         self._setup_pma()


--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/58791
To unsubscribe, or for help writing mail filters, visit https://gem5-review.googlesource.com/settings

Gerrit-Project: public/gem5
Gerrit-Branch: develop
Gerrit-Change-Id: I560496a4db5b4d91d3e3e90901487d8d40bf581b
Gerrit-Change-Number: 58791
Gerrit-PatchSet: 1
Gerrit-Owner: Hoa Nguyen <hoangu...@ucdavis.edu>
Gerrit-MessageType: newchange
_______________________________________________
gem5-dev mailing list -- gem5-dev@gem5.org
To unsubscribe send an email to gem5-dev-le...@gem5.org
%(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s

Reply via email to