:name: Versatile
:description: This script runs Linux on Versatile.
# log in with username "root"

using sysbus
$name?="Versatile"
mach create $name

machine LoadPlatformDescription @platforms/boards/versatile.repl

sysbus Redirect 0xC0000000 0x0 0x10000000

$bin?=@https://dl.antmicro.com/projects/renode/versatile--vmlinux-versatile-buildroot--b2f53187e2d5fd0f74e1b0c8922378605052915e
$rootfs?=@https://dl.antmicro.com/projects/renode/flash_versatile.img-s_33554432-6c62cf05cbf82eeb7b2343cb7f063a7c0eee6b32

### create externals ###

showAnalyzer sysbus.uart0

emulation CreateSwitch "switch"
connector Connect smc91x switch

machine CFIFlashFromFile $rootfs 0x34000000 "flash" nonPersistent=true

macro reset
"""
    ### set registers ###

    sysbus.cpu SetRegister 0 0x0
    sysbus.cpu SetRegister 1 0x183     # board id
    sysbus.cpu SetRegister 2 0x100     # atags

    ### load binaries ###

    sysbus LoadELF $bin false

    sysbus LoadAtags "console=ttyAMA0,115200 noinitrd root=/dev/mtdblock0 rw rootfstype=jffs2 mtdparts=armflash.0:64m@0x0 earlyprintk mem=256M" 0x10000000 0x100
    cpu PC 0x8000
"""

runMacro $reset
