Search code examples
gem5

Gem 5 IOError: Can't find a path to system files. Full System X86 simulation setup


I've already got Gem5 installed. I'm trying to do a full system simulation. I added M5_PATH

echo "export M5_PATH==/home/sam/security/gem5/full/" >> ~/.bashrc

I put all the system image and config files under following directory:

  :~/security/gem5/full$ ls
binaries  configs  config-x86.tar.bz2  disks  x86-system.tar.bz2  x86-system.tar.bz2.1

I changed the path in the SysPaths.py file to following:

                paths = [ '/dist/m5/system', 'full' ]

And updated the following line in Benchmark.py

            return env.get('LINUX_IMAGE', disk('linux-x86.img'))

Gem5 is compiled successfully and I'm running the following:

 ./build/X86/gem5.opt configs/example/fs.py  --disk-image=/home/sam/security/gem5/full/disks/linux-x86.img 

But I get an error that it can't find a path to system files.

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "build/X86/python/m5/main.py", line 438, in main
    exec(filecode, scope)
  File "configs/example/fs.py", line 335, in <module>
    test_sys = build_test_system(np)
  File "configs/example/fs.py", line 93, in build_test_system
    cmdline=cmdline)
  File "/home/sam/security/gem5/configs/common/FSConfig.py", line 614, in makeLinuxX86System
    makeX86System(mem_mode, numCPUs, mdesc, self, Ruby)
  File "/home/sam/security/gem5/configs/common/FSConfig.py", line 539, in makeX86System
    disk0.childImage(mdesc.disk())
  File "/home/sam/security/gem5/configs/common/Benchmarks.py", line 59, in disk
    return disk(self.diskname)
  File "/home/sam/security/gem5/configs/common/SysPaths.py", line 63, in __call__
    raise IOError("Can't find a path to system files.")
IOError: Can't find a path to system files.

Solution

  • Update 2020-01

    As of 82f6d6e90f36e400db1f38eef5fe17430313458e reviewed at https://gem5-review.googlesource.com/c/public/gem5/+/23672/7 the CLI insanity has reduced substantially:

    • M5_PATH is not required anymore on X86 if you point to all required files explicitly:

      fs.py --kernel path/to/vmlinux --disk-image path/to/rootfs.ext2
      

      The second disk named linux-bigswap2.img and x86_64-vmlinux-2.6.22.9 are not needed anymore, and you can pass multiple disks at will with multiple --disk-image options, see: How to attach multiple disk images in a simulation with gem5 fs.py?

    • on ARM, M5_PATH can also be dispensed, but you also need to point the bootloader with:

      fs.py --bootloader ./system/arm/bootloader/arm64/boot.arm64
      

    If you miss any of those files, M5_PATH gets used.

    Note that just like the PATH search algorithm, paths without / are only searched under M5_PATH, so if you want to point to a file in the current directory you need to add ./ as in:

    fs.py --kernel ./vmlinux
    

    see also: Why do you need ./ (dot-slash) before executable or script name to run it in bash?

    Old answer

    gem5 is picky about some path names, but you don't need to patch it to achieve a decent image setup.

    For example, this working setup with gem5 e2656006df442a995bf80ee03fa9700d6ec14537 essentially runs:

    M5_PATH=/full/path/to/system \
      build/X86/gem5.opt \
      configs/example/fs.py \
      --disk-image /any/path/to/rootfs.ext2 \
      --kernel /any/path/to/vmlinux
    

    and /full/path/to/system contains:

    ./disks/linux-bigswap2.img
    ./binaries/x86_64-vmlinux-2.6.22.9
    

    Both of those files are dummies which I generated from here with:

    dd if=/dev/zero of=./binaries/linux-bigswap2.img count=1 bs=16k
    touch disks/x86_64-vmlinux-2.6.22.9
    

    Yes, this is a horrible workaround to gem5's opinionated image searching... someone should really patch gem5 to not look for those images if you pass --disk-image and --kernel yourself...

    As always, have a try at debugging it with prints and PDB: it should then be simple to figure out why something didn't work for you.