UART communication in Gem5 with ARM Bare-metal

依然范特西╮ 提交于 2019-12-20 02:35:36

问题


I am currently working with Gem5 and I have to access via UART from my Host to ARMv8 bare-metal option, so i tried lots way but i stocked yet.

could you please let me know, how can i map my host's Serial port to ARMv8's Serial Port in bare-metal type programming.

Any help would be appreciated


回答1:


Working setups

This repository contains a highly automated working example. Features:

  • works on both QEMU and gem5
  • works on both arm and aarch64
  • newlib allows using the standard C library optionally
  • semihosting exemplified
  • works on both RealViewPBX and VExpress_GEM5_V1. You should prefer VExpress_GEM5_V1 as it is a more modern platform.
  • pristine toolchain built with crosstool-NG

Key implementation points are described below.

https://github.com/tukl-msd/gem5.bare-metal contains another working setup and is more minimal, but it has less features currently.

arm

There is nothing special for ARM, you just need to find out the UART address and entry point address, exactly as for QEMU.

The UART address can be found on the gem5 source code src/dev/arm/RealView.py:

class RealViewPBX(RealView):
    uart = Pl011(pio_addr=0x10009000, int_num=44)

class VExpress_GEM5_V1(RealView):
    uart0 = Pl011(pio_addr=0x1c090000, int_num=37)

The entry point is deduced from the ELF directly, but TODO some values are not valid. I just step debugged until I found these values:

    if common.machine == 'VExpress_GEM5_V1':
        entry_address = 0x80000000
    elif common.machine == 'RealViewPBX':
        entry_address = 0x10000

aarch64

Similar to arm, but requires a few extra steps.

First you must build your toolchain yourself if you want Newlib since Ubuntu does not have the aarch64 package. I've adapted the existing arm config and reached this working config.

Then, as of 6fa49382ef22e1b01fb24503e3bbe5ab3556750a you must pass the CLI options:

fs.py --param 'system.highest_el_is_64 = True' \
      --param 'system.auto_reset_addr = True'

(auto_reset_addr_64 before 6fa49382ef22e1b01fb24503e3bbe5ab3556750a) otherwise it fails with:

fatal: Kernel is mapped to invalid location (not memory). kernelStart 0x(400000) - kernelEnd 0x(0) 0x400000:0

The other key patch is: https://github.com/gem5/gem5/commit/3c3ca64b5f0dd9eef7b1ce1c65cc6e8e9147dd38

Alternatively, you could also patch fs.py as:

diff --git a/configs/example/fs.py b/configs/example/fs.py
index 3997ed76c..286e0bca6 100644
--- a/configs/example/fs.py
+++ b/configs/example/fs.py
@@ -376,5 +376,9 @@ if buildEnv['TARGET_ISA'] == "arm" and options.generate_dtb:
             sys = getattr(root, sysname)
             sys.dtb_filename = create_dtb_for_system(sys, '%s.dtb' % sysname)

+from m5.objects import ArmSemihosting
+test_sys.semihosting = ArmSemihosting()
+test_sys.highest_el_is_64 = True
+test_sys.auto_reset_addr_64 = True
 Simulation.setWorkCountOptions(test_sys, options)
 Simulation.run(options, root, test_sys, FutureClass)

The semihosting part is optional, but super convenient, see: How to enable ARM semihosting in gem5? The other options are mandatory.

Tested in Ubuntu 18.04 host.



来源:https://stackoverflow.com/questions/43682311/uart-communication-in-gem5-with-arm-bare-metal

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!