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

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
---
M configs/example/components-library/riscv_fs.py
M src/python/gem5/boards/riscv_board.py
2 files changed, 26 insertions(+), 56 deletions(-)



diff --git a/configs/example/components-library/riscv_fs.py b/configs/example/components-library/riscv_fs.py
index 7629936..3312012 100644
--- a/configs/example/components-library/riscv_fs.py
+++ b/configs/example/components-library/riscv_fs.py
@@ -33,31 +33,25 @@
 * 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
 from m5.objects import Root

-from gem5.runtime import get_runtime_isa
-from gem5.boards.riscv_board import RiscvBoard
 from gem5.memory.single_channel import SingleChannelDDR3_1600
 from gem5.processors.simple_processor import SimpleProcessor
 from gem5.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.cachehierarchies.classic.private_l1_private_l2_cache_hierarchy \
-    import (
-        PrivateL1PrivateL2CacheHierarchy,
-    )
+        import PrivateL1PrivateL2CacheHierarchy
 from gem5.boards.riscv_board import RiscvBoard

# Setup the cache hierarchy. PrivateL1PrivateL2 and NoCache have been tested.
@@ -81,43 +75,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/boards/riscv_board.py b/src/python/gem5/boards/riscv_board.py
index 97e32f0..66dbcb0 100644
--- a/src/python/gem5/boards/riscv_board.py
+++ b/src/python/gem5/boards/riscv_board.py
@@ -3,7 +3,7 @@
 #
 # Redistribution and use in source and binary forms, with or without
 # modification, are permitted provided that the following conditions are
-# met: redistributions of source code must retain the above copyright
+# met: redistributions of source code must retTheain the above copyright
 # notice, this list of conditions and the following disclaimer;
 # redistributions in binary form must reproduce the above copyright
 # notice, this list of conditions and the following disclaimer in the
@@ -34,7 +34,8 @@
 from ..memory.abstract_memory_system import AbstractMemorySystem
from ..cachehierarchies.abstract_cache_hierarchy import AbstractCacheHierarchy
 from ..isas import ISA
-from ..runtime import get_runtime_isa
+from ..resources.resource import AbstractResource
+from ..utils.requires import requires

 import m5

@@ -85,11 +86,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 +174,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 +194,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: 1
Gerrit-Owner: Bobby R. Bruce <[email protected]>
Gerrit-MessageType: newchange
_______________________________________________
gem5-dev mailing list -- [email protected]
To unsubscribe send an email to [email protected]
%(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s

Reply via email to