Bobby R. Bruce has submitted this change. ( https://gem5-review.googlesource.com/c/public/gem5/+/49867 )


13 is the latest approved patch-set.
No files were changed between the latest approved patch-set and the submitted one.
Change subject: arch-riscv,configs,python: Update riscv_fs.py/riscv_board.py
......................................................................

arch-riscv,configs,python: Update riscv_fs.py/riscv_board.py

This patch incoporates improvements to the riscv_fs.py and
riscv_board.py:

* Adds 'Resource' objects to download needed resources.
* Adds 'requires' function calls where necessary.

Change-Id: I2ae4f34221d781ed6d71c9f69d56833845f537c4
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/49867
Tested-by: kokoro <noreply+kok...@google.com>
Reviewed-by: Bobby R. Bruce <bbr...@ucdavis.edu>
Reviewed-by: Jason Lowe-Power <power...@gmail.com>
Maintainer: Bobby R. Bruce <bbr...@ucdavis.edu>
---
M configs/example/components-library/riscv_fs.py
M src/python/gem5/components/boards/riscv_board.py
2 files changed, 25 insertions(+), 51 deletions(-)

Approvals:
  Jason Lowe-Power: Looks good to me, approved
  Bobby R. Bruce: Looks good to me, approved; Looks good to me, approved
  kokoro: Regressions pass




diff --git a/configs/example/components-library/riscv_fs.py b/configs/example/components-library/riscv_fs.py
index 807e35f..eadac8b 100644
--- a/configs/example/components-library/riscv_fs.py
+++ b/configs/example/components-library/riscv_fs.py
@@ -33,6 +33,8 @@
 * Runs exclusively on the RISC-V ISA with the classic caches
 * Assumes that the kernel is compiled into the bootloader
 * Automatically generates the DTB file
+* Will boot but requires a user to login using `m5term` (username: `root`,
+  password: `root`)
 """

 import m5
@@ -44,21 +46,16 @@
 from gem5.components.processors.simple_processor import SimpleProcessor
 from gem5.components.processors.cpu_types import CPUTypes
 from gem5.isas import ISA
-
-import os
-import subprocess
-import gzip
-import shutil
+from gem5.utils.requires import requires
+from gem5.resources.resource import Resource

 # Run a check to ensure the right version of gem5 is being used.
-if get_runtime_isa() != ISA.RISCV:
-    raise EnvironmentError("The riscv_fs.py should be run with RISCV ISA.")
+requires(isa_required=ISA.RISCV)

from gem5.components.cachehierarchies.classic.private_l1_private_l2_cache_hierarchy \
     import (
         PrivateL1PrivateL2CacheHierarchy,
     )
-from gem5.boards.riscv_board import RiscvBoard

# Setup the cache hierarchy. PrivateL1PrivateL2 and NoCache have been tested.
 cache_hierarchy = PrivateL1PrivateL2CacheHierarchy(
@@ -81,43 +78,19 @@

 board.connect_things()

-# Download the resources as necessary.
-thispath = os.path.dirname(os.path.realpath(__file__))
-
-bootloader_url = (
-    "http://dist.gem5.org/dist/develop/kernels/";
-    "riscv/static/bootloader-vmlinux-5.10"
-)
-bootloader_path = os.path.join(thispath, "bootloader-vmlinux-5.10")
-if not os.path.exists(bootloader_path):
-    subprocess.run(["wget", "-P", thispath, bootloader_url])
-
-boot_img_url = (
-    "http://dist.gem5.org/dist/develop/images/riscv/busybox/riscv-disk.img.gz";
-)
-boot_img_path_gz = os.path.join(thispath, "riscv-disk.img.gz")
-boot_img_path = os.path.join(thispath, "riscv-disk.img")
-
-if not os.path.exists(boot_img_path):
-    subprocess.run(["wget", "-P", thispath, boot_img_url])
-    with gzip.open(boot_img_path_gz, "rb") as f:
-        with open(boot_img_path, "wb") as o:
-            shutil.copyfileobj(f, o)
-
 # Set the Full System workload.
-board.set_workload(disk_image=boot_img_path, bootloader=bootloader_path)
-
-
-# Begin running of the simulation. This will exit once the Linux system boot
-# is complete.
-print("Running with ISA: " + get_runtime_isa().name)
-print()
+board.set_workload(disk_image=Resource("riscv-disk-img"),
+                   bootloader=Resource("riscv-bootloader-vmlinux-5.10"))

 root = Root(full_system=True, system=board)

 m5.instantiate()

 print("Beginning simulation!")
+# Note: This simulation will never stop. You can access the terminal upon boot +# using m5term (`./util/term`): `./m5term localhost <port>`. Note the `<port>`
+# value is obtained from the gem5 terminal stdout. Look out for
+# "system.platform.terminal: Listening for connections on port <port>".
 exit_event = m5.simulate()
 print(
"Exiting @ tick {} because {}.".format(m5.curTick(), exit_event.getCause()) diff --git a/src/python/gem5/components/boards/riscv_board.py b/src/python/gem5/components/boards/riscv_board.py
index dc8f799..2cc151d 100644
--- a/src/python/gem5/components/boards/riscv_board.py
+++ b/src/python/gem5/components/boards/riscv_board.py
@@ -33,8 +33,10 @@
 from ..processors.abstract_processor import AbstractProcessor
 from ..memory.abstract_memory_system import AbstractMemorySystem
from ..cachehierarchies.abstract_cache_hierarchy import AbstractCacheHierarchy
+from ...resources.resource import AbstractResource
+
 from ...isas import ISA
-from ...runtime import get_runtime_isa
+from ...utils.requires import requires

 import m5

@@ -85,11 +87,8 @@
     ) -> None:
         super().__init__(clk_freq, processor, memory, cache_hierarchy)

-        if get_runtime_isa() != ISA.RISCV:
-            raise EnvironmentError(
-                "RiscvBoard will only work with the RISC-V ISA. Please"
-                " recompile gem5 with ISA=RISCV."
-            )
+        requires(isa_required=ISA.RISCV)
+
         if cache_hierarchy.is_ruby():
raise EnvironmentError("RiscvBoard is not compatible with Ruby")

@@ -176,8 +175,9 @@
         memory.set_memory_range(self.mem_ranges)

     def set_workload(
- self, bootloader: str, disk_image: str, command: Optional[str] = None
-    ):
+        self, bootloader: AbstractResource, disk_image: AbstractResource,
+        command: Optional[str] = None
+    ) -> None:
         """Setup the full system files

         See http://resources.gem5.org/resources/riscv-fs for the currently
@@ -195,18 +195,19 @@
         * Disk must be configured correctly to use the command option
         * This board doesn't support the command option

- :param bootloader: The compiled bootloader with the kernel as a payload
-        :param disk_image: A disk image containing the OS data. The first
-            partition should be the root partition.
+ :param bootloader: The resource encapsulating the compiled bootloader
+            with the kernel as a payload
+ :param disk_image: The resource encapsulating the disk image containing
+            the OS data. The first partition should be the root partition.
:param command: The command(s) to run with bash once the OS is booted
         """

-        self.workload.object_file = bootloader
+        self.workload.object_file = bootloader.get_local_path()

         image = CowDiskImage(
             child=RawDiskImage(read_only=True), read_only=False
         )
-        image.child.image_file = disk_image
+        image.child.image_file = disk_image.get_local_path()
         self.disk.vio.image = image

         self.workload.command_line = "console=ttyS0 root=/dev/vda ro"

--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/49867
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: I2ae4f34221d781ed6d71c9f69d56833845f537c4
Gerrit-Change-Number: 49867
Gerrit-PatchSet: 16
Gerrit-Owner: Bobby R. Bruce <bbr...@ucdavis.edu>
Gerrit-Reviewer: Andreas Sandberg <andreas.sandb...@arm.com>
Gerrit-Reviewer: Bobby R. Bruce <bbr...@ucdavis.edu>
Gerrit-Reviewer: Jason Lowe-Power <ja...@lowepower.com>
Gerrit-Reviewer: Jason Lowe-Power <power...@gmail.com>
Gerrit-Reviewer: kokoro <noreply+kok...@google.com>
Gerrit-MessageType: merged
_______________________________________________
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