emulation: complete initial emulation of spinor/flash

Emulate both the SPINOR block as well as the OSPI flash attached to it.

With this change, the PDDB can now be initialized and resets itself
properly. Additionally, data persists across virtual reboots.

Data does not persist across runs of the emulator. That will follow in
an upcoming patch.

Signed-off-by: Sean Cross <sean@xobs.io>
This commit is contained in:
Sean Cross 2022-02-17 18:03:45 +08:00
parent 1f21d8a43c
commit 317f3136aa
8 changed files with 5536 additions and 146 deletions

View file

@ -0,0 +1,287 @@
//
// Copyright (c) 2010-2019 Antmicro
//
// This file is licensed under the MIT License.
// Full license text is available in 'licenses/MIT.txt'.
//
using System;
using System.Collections.Generic;
using Antmicro.Renode.Core;
using Antmicro.Renode.Core.Structure;
using Antmicro.Renode.Core.Structure.Registers;
using Antmicro.Renode.Logging;
using Antmicro.Renode.Peripherals.Bus;
using Antmicro.Renode.Utilities;
namespace Antmicro.Renode.Peripherals.SPI
{
[AllowedTranslations(AllowedTranslation.ByteToDoubleWord | AllowedTranslation.WordToDoubleWord)]
public class BetrustedSpinor : NullRegistrationPointPeripheralContainer<ISPIPeripheral>, IDoubleWordPeripheral, IKnownSize
{
public BetrustedSpinor(Machine machine) : base(machine)
{
// bbHelper = new BitBangHelper(8, loggingParent: this, outputMsbFirst: true);
txQueue = new Queue<byte>(256);
rxQueue = new Queue<byte>(256);
IRQ = new GPIO();
var registers = new Dictionary<long, DoubleWordRegister>
{
{(long)Registers.Config, new DoubleWordRegister(this)
.WithValueField(0, 5, name: "dummy")
},
{(long)Registers.DelayConfig, new DoubleWordRegister(this)
.WithValueField(0, 5, name: "d")
.WithFlag(5, name: "load")
},
{(long)Registers.DelayStatus, new DoubleWordRegister(this)
.WithValueField(0, 5, name: "q")
},
{(long)Registers.Command, new DoubleWordRegister(this)
.WithValueField(0, 32, FieldMode.Write, writeCallback: (_, data) => {
var wakeup = BitHelper.IsBitSet(data, 0);
var exec_cmd = BitHelper.IsBitSet(data, 1);
cmdCode = (byte)BitHelper.GetValue(data, 2, 8);
hasArg = BitHelper.IsBitSet(data, 10);
dummyCycles = (uint)BitHelper.GetValue(data, 11, 5);
dataWords = (uint)BitHelper.GetValue(data, 16, 8);
lockReads = BitHelper.IsBitSet(data, 24);
if (exec_cmd) {
// Ensure the device is in OPI mode. This may change due to a system reset.
SwitchSpiToOpi();
this.Log(LogLevel.Noisy, "Executing command! cmdCode: {0:X2} hasArg? {1} ({6:X8}) dummyCycles: {2} dataWords: {3} txFifo.Count: {4} rxFifo.Count: {5}",
cmdCode, hasArg, dummyCycles, dataWords, txQueue.Count, rxQueue.Count, cmdArg.Value);
if (RegisteredPeripheral == null) {
this.Log(LogLevel.Error, "Unable to get SPI chip device!");
return;
}
// In OPI mode, send the command, followed by the inverse of the command
RegisteredPeripheral.Transmit(cmdCode);
RegisteredPeripheral.Transmit((byte)~cmdCode);
if (dummyCycles == 0) {
if (hasArg) {
RegisteredPeripheral.Transmit((byte)(cmdArg.Value >> 24));
RegisteredPeripheral.Transmit((byte)(cmdArg.Value >> 16));
RegisteredPeripheral.Transmit((byte)(cmdArg.Value >> 8));
RegisteredPeripheral.Transmit((byte)(cmdArg.Value >> 0));
}
// Is Write
for (var i = 0; i < dataWords; i++) {
RegisteredPeripheral.Transmit((txQueue.Count > 0) ? txQueue.Dequeue() : (byte)0xff);
RegisteredPeripheral.Transmit((txQueue.Count > 0) ? txQueue.Dequeue() : (byte)0xff);
}
} else {
// Is Read
// Transmit the dummy data
for (var i = 0; i < dummyCycles; i++) {
if (hasArg && (i == 0)) {
RegisteredPeripheral.Transmit((byte)(cmdArg.Value >> 24));
} else if (hasArg && (i == 1)) {
RegisteredPeripheral.Transmit((byte)(cmdArg.Value >> 16));
} else if (hasArg && (i == 2)) {
RegisteredPeripheral.Transmit((byte)(cmdArg.Value >> 8));
} else if (hasArg && (i == 3)) {
RegisteredPeripheral.Transmit((byte)(cmdArg.Value >> 0));
} else {
RegisteredPeripheral.Transmit(0xff);
}
}
// Receive data back, two transmissions per word since it's in
// units of 16 bits.
for (var i = 0; i < dataWords; i++) {
rxQueue.Enqueue((byte)(RegisteredPeripheral.Transmit(0xff)));
rxQueue.Enqueue((byte)(RegisteredPeripheral.Transmit(0xff) >> 8));
}
}
RegisteredPeripheral.FinishTransmission();
}
})
},
{(long)Registers.CmdArg, new DoubleWordRegister(this)
.WithValueField(0, 32, out cmdArg, FieldMode.Read | FieldMode.Write, name: "cmd_arg")
},
{(long)Registers.CmdRbkData, new DoubleWordRegister(this)
.WithValueField(0, 32, FieldMode.Read, valueProviderCallback: (_) => HandleRxFifoRead(), name: "cmd_rbk_data")
},
{(long)Registers.Status, new DoubleWordRegister(this)
.WithFlag(0, name: "wip")
},
{(long)Registers.WData, new DoubleWordRegister(this)
.WithValueField(0, 16, FieldMode.Write, writeCallback: (_, data) => HandleTxFifoWrite(data), name: "wdata")
},
{(long)Registers.EvStatus, new DoubleWordRegister(this)
.WithFlag(0, name: "ecc_error")
},
{(long)Registers.EvPending, new DoubleWordRegister(this)
.WithFlag(0, name: "ecc_error")
},
{(long)Registers.EvEnable, new DoubleWordRegister(this)
.WithFlag(0, name: "ecc_error")
},
{(long)Registers.EccAddress, new DoubleWordRegister(this)
.WithValueField(0, 32, name: "ecc_address")
},
{(long)Registers.EccStatus, new DoubleWordRegister(this)
.WithFlag(0, name: "ecc_error")
.WithFlag(1, name: "ecc_overflow")
},
};
registersCollection = new DoubleWordRegisterCollection(this, registers);
Reset();
}
public override void Reset()
{
registersCollection.Reset();
if (RegisteredPeripheral != null) {
spiIsInOpiMode = false;
RegisteredPeripheral.Reset();
}
}
private void HandleTxFifoWrite(uint value)
{
txQueue.Enqueue((byte)(value));
txQueue.Enqueue((byte)(value >> 8));
}
private uint HandleRxFifoRead()
{
uint ret = 0;
if (rxQueue.Count > 0)
{
ret |= (uint)rxQueue.Dequeue() << 0;
}
if (rxQueue.Count > 0)
{
ret |= (uint)rxQueue.Dequeue() << 8;
}
if (rxQueue.Count > 0)
{
ret |= (uint)rxQueue.Dequeue() << 16;
}
if (rxQueue.Count > 0)
{
ret |= (uint)rxQueue.Dequeue() << 24;
}
return ret;
}
public uint ReadDoubleWord(long offset)
{
return registersCollection.Read(offset);
}
[ConnectionRegionAttribute("xip")]
public uint XipReadDoubleWord(long offset)
{
return (RegisteredPeripheral as IDoubleWordPeripheral)?.ReadDoubleWord(offset) ?? 0;
}
public void WriteDoubleWord(long offset, uint value)
{
registersCollection.Write(offset, value);
}
[ConnectionRegionAttribute("xip")]
public void XipWriteDoubleWord(long offset, uint value)
{
(RegisteredPeripheral as IDoubleWordPeripheral)?.WriteDoubleWord(offset, value);
}
public override void Register(ISPIPeripheral peripheral, NullRegistrationPoint registrationPoint)
{
peripheral.Reset();
base.Register(peripheral, registrationPoint);
SwitchSpiToOpi();
}
private void SwitchSpiToOpi()
{
if (spiIsInOpiMode) {
return;
}
// Wake up from deep sleep
byte[] wakeup = new byte[] { 0xab };
// WREN
byte[] wren = new byte[] { 0x06 };
// Set to 8 dummy cycles to run at 84 MHz
byte[] dummy_cycles_84 = new byte[6];
dummy_cycles_84[0] = 0x72;
dummy_cycles_84[1] = 0x00;
dummy_cycles_84[2] = 0x00;
dummy_cycles_84[3] = 0x03;
dummy_cycles_84[4] = 0x00;
dummy_cycles_84[5] = 0x05;
// Switch to DOPI
byte[] switch_to_ddr_opi = new byte[6];
switch_to_ddr_opi[0] = 0x72;
switch_to_ddr_opi[1] = 0x00;
switch_to_ddr_opi[2] = 0x00;
switch_to_ddr_opi[3] = 0x00;
switch_to_ddr_opi[4] = 0x00;
switch_to_ddr_opi[5] = 0x02;
TransmitTransaction(wakeup);
TransmitTransaction(wren);
TransmitTransaction(dummy_cycles_84);
TransmitTransaction(wren);
TransmitTransaction(switch_to_ddr_opi);
spiIsInOpiMode = true;
}
private void TransmitTransaction(byte[] sequence) {
foreach (var b in sequence) {
RegisteredPeripheral.Transmit(b);
}
RegisteredPeripheral.FinishTransmission();
}
public long Size { get { return 4096; } }
public GPIO IRQ { get; private set; }
private readonly Queue<byte> rxQueue;
private readonly Queue<byte> txQueue;
private readonly DoubleWordRegisterCollection registersCollection;
private uint dataWords;
private uint dummyCycles;
private byte cmdCode;
bool spiIsInOpiMode = false;
private readonly IValueRegisterField cmdArg;
private bool hasArg;
private bool lockReads;
private enum Registers
{
Config = 0x00,
DelayConfig = 0x04,
DelayStatus = 0x08,
Command = 0x0c,
CmdArg = 0x10,
CmdRbkData = 0x14,
Status = 0x18,
WData = 0x1c,
EvStatus = 0x20,
EvPending = 0x24,
EvEnable = 0x28,
EccAddress = 0x2c,
EccStatus = 0x30,
}
}
}

View file

@ -0,0 +1,717 @@
//
// Copyright (c) 2010-2022 Antmicro
//
// This file is licensed under the MIT License.
// Full license text is available in 'licenses/MIT.txt'.
//
using System;
using Antmicro.Renode.Core.Structure.Registers;
using Antmicro.Renode.Exceptions;
using Antmicro.Renode.Logging;
using Antmicro.Renode.Peripherals.Memory;
using Antmicro.Renode.Peripherals.SPI.NORFlash;
using Antmicro.Renode.Utilities;
namespace Antmicro.Renode.Peripherals.SPI
{
public class MXIC_MX66UM1G45G : ISPIPeripheral
{
public MXIC_MX66UM1G45G(MappedMemory underlyingMemory)
{
// original MT25Q supports capacity 8MB to 256MB,
// but we extended it down to 64KB
// to become compatible with N25Q line
if (underlyingMemory.Size < 64.KB() || underlyingMemory.Size > 256.MB() || !Misc.IsPowerOfTwo((ulong)underlyingMemory.Size))
{
throw new ConstructionException("Size of the underlying memory must be a power of 2 value in range 64KB - 256MB");
}
volatileConfigurationRegister = new ByteRegister(this, 0xfb).WithFlag(3, name: "XIP");
nonVolatileConfigurationRegister = new WordRegister(this, 0xffff).WithFlag(0, out numberOfAddressBytes, name: "addressWith3Bytes");
enhancedVolatileConfigurationRegister = new ByteRegister(this, 0xff)
.WithValueField(0, 3, name: "Output driver strength")
.WithReservedBits(3, 1)
.WithTaggedFlag("Reset/hold", 4)
//these flags are intentionally not implemented, as they described physical details
.WithFlag(5, name: "Double transfer rate protocol")
.WithFlag(6, name: "Dual I/O protocol")
.WithFlag(7, name: "Quad I/O protocol");
statusRegister = new ByteRegister(this).WithFlag(1, out enable, name: "writeEnableLatch");
flagStatusRegister = new ByteRegister(this)
.WithFlag(0, FieldMode.Read, valueProviderCallback: _ => numberOfAddressBytes.Value, name: "Addressing")
//other bits indicate either protection errors (not implemented) or pending operations (they already finished)
.WithReservedBits(3, 1)
.WithFlag(7, FieldMode.Read, valueProviderCallback: _ => true, name: "ProgramOrErase");
this.underlyingMemory = underlyingMemory;
underlyingMemory.ResetByte = EmptySegment;
deviceData = GetDeviceData();
}
public void FinishTransmission()
{
this.Log(LogLevel.Noisy, "Transmission finished");
switch (currentOperation.State)
{
case DecodedOperation.OperationState.RecognizeOperation:
case DecodedOperation.OperationState.AccumulateCommandAddressBytes:
case DecodedOperation.OperationState.AccumulateNoDataCommandAddressBytes:
this.Log(LogLevel.Warning, "Transmission finished in the unexpected state: {0}", currentOperation.State);
break;
}
// If an operation has at least 1 data byte or more than 0 address bytes,
// we can clear the write enable flag only when we are finishing a transmission.
switch (currentOperation.Operation)
{
case DecodedOperation.OperationType.Program:
case DecodedOperation.OperationType.Erase:
case DecodedOperation.OperationType.WriteRegister:
//although the docs are not clear, it seems that all register writes should clear the flag
enable.Value = false;
break;
}
currentOperation.State = DecodedOperation.OperationState.RecognizeOperation;
currentOperation = default(DecodedOperation);
temporaryNonVolatileConfiguration = 0;
isFirstOpiByte = true;
}
public void Reset()
{
this.Log(LogLevel.Noisy, "Resetting SPI flash device. Exiting OPI mode.");
opiMode = false;
isFirstOpiByte = true;
statusRegister.Reset();
flagStatusRegister.Reset();
volatileConfigurationRegister.Reset();
nonVolatileConfigurationRegister.Reset();
enhancedVolatileConfigurationRegister.Reset();
currentOperation = default(DecodedOperation);
FinishTransmission();
}
public byte Transmit(byte data)
{
this.Log(LogLevel.Noisy, "Received data 0x{0:X}, current state: {1} OPI mode? {2}", data, currentOperation.State, opiMode);
// Eat the first byte when running in OPI mode. The second byte should be the inverse of the first byte.
if (opiMode)
{
if (isFirstOpiByte)
{
isFirstOpiByte = false;
firstOpiByte = data;
return 0xff;
}
else if (currentOperation.State == DecodedOperation.OperationState.RecognizeOperation)
{
if (data != (byte)~firstOpiByte)
{
this.Log(LogLevel.Error, "Was in OPI mode, but 2nd byte wasn't the inverse of the first byte! (data: {0:X2} first byte: {1:X2}", data, firstOpiByte);
}
data = firstOpiByte;
}
}
switch (currentOperation.State)
{
case DecodedOperation.OperationState.RecognizeOperation:
// When the command is decoded, depending on the operation we will either start accumulating address bytes
// or immediately handle the command bytes
RecognizeOperation(data);
break;
case DecodedOperation.OperationState.AccumulateCommandAddressBytes:
AccumulateAddressBytes(data, DecodedOperation.OperationState.HandleCommand);
break;
case DecodedOperation.OperationState.AccumulateNoDataCommandAddressBytes:
AccumulateAddressBytes(data, DecodedOperation.OperationState.HandleNoDataCommand);
break;
case DecodedOperation.OperationState.HandleCommand:
// Process the remaining command bytes
return HandleCommand(data);
}
// Warning: commands without data require immediate handling after the address was accumulated
if (currentOperation.State == DecodedOperation.OperationState.HandleNoDataCommand)
{
HandleNoDataCommand();
}
return 0;
}
public MappedMemory UnderlyingMemory => underlyingMemory;
private void AccumulateAddressBytes(byte addressByte, DecodedOperation.OperationState nextState)
{
if (currentOperation.TryAccumulateAddress(addressByte))
{
this.Log(LogLevel.Noisy, "Address accumulated: 0x{0:X}", currentOperation.ExecutionAddress);
currentOperation.State = nextState;
}
}
private byte[] GetDeviceData()
{
var data = new byte[4];
data[0] = ManufacturerID;
data[1] = MemoryType;
data[2] = MemoryDensity;
data[3] = 0;
return data;
}
private void RecognizeOperation(byte firstByte)
{
currentOperation.Operation = DecodedOperation.OperationType.None;
// currentOperation.AddressLength = 0;
currentOperation.State = DecodedOperation.OperationState.HandleCommand;
switch (firstByte)
{
case (byte)Commands.ReadID:
currentOperation.Operation = DecodedOperation.OperationType.ReadID;
if (opiMode)
{
currentOperation.State = DecodedOperation.OperationState.AccumulateCommandAddressBytes;
currentOperation.AddressLength = 4;
}
break;
case (byte)Commands.PageProgram4byte:
currentOperation.Operation = DecodedOperation.OperationType.Program;
currentOperation.AddressLength = 4;
currentOperation.State = DecodedOperation.OperationState.AccumulateCommandAddressBytes;
break;
case (byte)Commands.WriteEnable:
this.Log(LogLevel.Noisy, "Setting write enable latch");
currentOperation.Operation = DecodedOperation.OperationType.None;
enable.Value = true;
return; //return to prevent further logging
case (byte)Commands.WriteDisable:
this.Log(LogLevel.Noisy, "Unsetting write enable latch");
currentOperation.Operation = DecodedOperation.OperationType.None;
enable.Value = false;
return; //return to prevent further logging
case (byte)Commands.SubsectorErase4byte4kb:
currentOperation.Operation = DecodedOperation.OperationType.Erase;
currentOperation.EraseSize = DecodedOperation.OperationEraseSize.Subsector4K;
currentOperation.AddressLength = 4;
currentOperation.State = DecodedOperation.OperationState.AccumulateNoDataCommandAddressBytes;
break;
case (byte)Commands.ReadStatusRegister:
currentOperation.Operation = DecodedOperation.OperationType.ReadRegister;
currentOperation.Register = (uint)Register.Status;
if (opiMode)
{
currentOperation.State = DecodedOperation.OperationState.AccumulateCommandAddressBytes;
currentOperation.AddressLength = 4;
}
break;
case (byte)Commands.ReadSecurityRegister:
currentOperation.Operation = DecodedOperation.OperationType.ReadRegister;
currentOperation.Register = (uint)Register.SecurityRegister;
if (opiMode)
{
currentOperation.State = DecodedOperation.OperationState.AccumulateCommandAddressBytes;
currentOperation.AddressLength = 4;
}
break;
case (byte)Commands.WriteStatusRegister:
currentOperation.Operation = DecodedOperation.OperationType.WriteRegister;
currentOperation.Register = (uint)Register.Status;
if (opiMode)
{
currentOperation.State = DecodedOperation.OperationState.AccumulateCommandAddressBytes;
currentOperation.AddressLength = 4;
}
break;
case (byte)Commands.WriteSecurityRegister:
currentOperation.Operation = DecodedOperation.OperationType.WriteRegister;
currentOperation.Register = (uint)Register.SecurityRegister;
if (opiMode)
{
currentOperation.State = DecodedOperation.OperationState.AccumulateCommandAddressBytes;
currentOperation.AddressLength = 4;
}
break;
case (byte)Commands.ReadConfigurationRegister2:
currentOperation.Operation = DecodedOperation.OperationType.ReadRegister;
currentOperation.Register = (uint)Register.ConfigurationRegister2;
currentOperation.AddressLength = 4;
currentOperation.State = DecodedOperation.OperationState.AccumulateCommandAddressBytes;
break;
case (byte)Commands.WriteConfigurationRegister2:
currentOperation.Operation = DecodedOperation.OperationType.WriteRegister;
currentOperation.Register = (uint)Register.ConfigurationRegister2;
currentOperation.AddressLength = 4;
currentOperation.State = DecodedOperation.OperationState.AccumulateCommandAddressBytes;
break;
case (byte)Commands.ReleaseFromDeepPowerdown:
return; //return to prevent further logging
default:
this.Log(LogLevel.Error, "Command decoding failed on byte: 0x{0:X} ({1}).", firstByte, (Commands)firstByte);
return;
}
this.Log(LogLevel.Noisy, "Decoded operation: {0}, write enabled {1}", currentOperation, enable.Value);
}
private byte HandleCommand(byte data)
{
byte result = 0;
switch (currentOperation.Operation)
{
case DecodedOperation.OperationType.ReadFast:
// handle dummy byte and switch to read
currentOperation.Operation = DecodedOperation.OperationType.Read;
currentOperation.CommandBytesHandled--;
this.Log(LogLevel.Noisy, "Handling dummy byte in ReadFast operation");
break;
case DecodedOperation.OperationType.Read:
result = ReadFromMemory();
break;
case DecodedOperation.OperationType.ReadID:
if (currentOperation.CommandBytesHandled < deviceData.Length)
{
result = deviceData[currentOperation.CommandBytesHandled];
}
else
{
this.Log(LogLevel.Error, "Trying to read beyond the length of the device ID table.");
result = 0;
}
break;
case DecodedOperation.OperationType.Program:
if (enable.Value)
{
WriteToMemory(data);
result = data;
}
else
{
this.Log(LogLevel.Error, "Memory write operations are disabled.");
}
break;
case DecodedOperation.OperationType.ReadRegister:
result = ReadRegister((Register)currentOperation.Register);
break;
case DecodedOperation.OperationType.WriteRegister:
WriteRegister((Register)currentOperation.Register, data);
break;
case DecodedOperation.OperationType.None:
break;
default:
this.Log(LogLevel.Warning, "Unhandled operation encountered while processing command bytes: {0}", currentOperation.Operation);
break;
}
currentOperation.CommandBytesHandled++;
this.Log(LogLevel.Noisy, "Handled command: {0}, returning 0x{1:X}", currentOperation, result);
return result;
}
private void WriteRegister(Register register, byte data)
{
if (!enable.Value)
{
this.Log(LogLevel.Error, "Trying to write a register, but write enable latch is not set");
return;
}
switch (register)
{
case Register.VolatileConfiguration:
volatileConfigurationRegister.Write(0, data);
break;
case Register.NonVolatileConfiguration:
if ((currentOperation.CommandBytesHandled) >= 2)
{
this.Log(LogLevel.Error, "Trying to write to register {0} with more than expected 2 bytes.", Register.NonVolatileConfiguration);
break;
}
BitHelper.UpdateWithShifted(ref temporaryNonVolatileConfiguration, data, currentOperation.CommandBytesHandled * 8, 8);
if (currentOperation.CommandBytesHandled == 1)
{
nonVolatileConfigurationRegister.Write(0, (ushort)temporaryNonVolatileConfiguration);
}
break;
//listing all cases as other registers are not writable at all
case Register.EnhancedVolatileConfiguration:
enhancedVolatileConfigurationRegister.Write(0, data);
break;
case Register.SecurityRegister:
return;
case Register.ConfigurationRegister2:
switch (currentOperation.ExecutionAddress)
{
case 0x00000000:
opiMode = ((data & 3) != 0);
if (opiMode)
{
this.Log(LogLevel.Noisy, "OPI mode enabled");
}
else
{
this.Log(LogLevel.Noisy, "OPI mode disabled");
}
break;
case 0x00000200:
break;
case 0x00000300:
break;
case 0x00000400:
break;
case 0x00000500:
// CRC chunk size configuration / enabled
break;
case 0x00000800:
case 0x04000800:
// ECC fail status
break;
case 0x00000c00:
case 0x04000c00:
// ECC fail
break;
case 0x00000d00:
case 0x04000d00:
// ECC fail
break;
case 0x00000e00:
case 0x04000e00:
// ECC fail
break;
case 0x00000f00:
case 0x04000f00:
// ECC fail
break;
case 0x40000000:
// Enable DOPI/SOPI after reset
break;
case 0x80000000:
// CRC error
break;
default:
this.Log(LogLevel.Warning, "Unrecognized CR2 address: {0:X8}", currentOperation.ExecutionAddress);
break;
}
break;
case Register.Status:
default:
this.Log(LogLevel.Warning, "Trying to write 0x{0} to unsupported register \"{1}\"", data, register);
break;
}
}
private byte ReadRegister(Register register)
{
switch (register)
{
case Register.Status:
// The documentation states that at least 1 byte will be read
// If more than 1 byte is read, the same byte is returned
return statusRegister.Read();
case Register.FlagStatus:
// The documentation states that at least 1 byte will be read
// If more than 1 byte is read, the same byte is returned
return flagStatusRegister.Read();
case Register.VolatileConfiguration:
// The documentation states that at least 1 byte will be read
// If more than 1 byte is read, the same byte is returned
return volatileConfigurationRegister.Read();
case Register.NonVolatileConfiguration:
// The documentation states that at least 2 bytes will be read
// After all 16 bits of the register have been read, 0 is returned
if ((currentOperation.CommandBytesHandled) < 2)
{
return (byte)BitHelper.GetValue(nonVolatileConfigurationRegister.Read(), currentOperation.CommandBytesHandled * 8, 8);
}
return 0;
case Register.SecurityRegister:
return 0;
case Register.EnhancedVolatileConfiguration:
return enhancedVolatileConfigurationRegister.Read();
case Register.ConfigurationRegister2:
switch (currentOperation.ExecutionAddress)
{
case 0x00000000:
if (opiMode)
{
return 2;
}
return 0;
case 0x00000200:
return 0;
case 0x00000300:
return 0;
case 0x00000400:
return 0;
case 0x00000500:
// CRC chunk size configuration / enabled
return 0;
case 0x00000800:
case 0x04000800:
// ECC fail status
return 0;
case 0x00000c00:
case 0x04000c00:
// ECC fail
return 0;
case 0x00000d00:
case 0x04000d00:
// ECC fail
return 0;
case 0x00000e00:
case 0x04000e00:
// ECC fail
return 0;
case 0x00000f00:
case 0x04000f00:
// ECC fail
return 0;
case 0x40000000:
// Enable DOPI/SOPI after reset
return 0;
case 0x80000000:
// CRC error
return 0;
default:
this.Log(LogLevel.Warning, "Unrecognized CR2 address: {0:X8}", currentOperation.ExecutionAddress);
return 0;
}
case Register.ExtendedAddress:
default:
this.Log(LogLevel.Warning, "Trying to read from unsupported register \"{0}\"", register);
return 0;
}
}
private void HandleNoDataCommand()
{
// The documentation describes more commands that don't have any data bytes (just code + address)
// but at the moment we have implemented just these ones
switch (currentOperation.Operation)
{
case DecodedOperation.OperationType.Erase:
if (enable.Value)
{
if (currentOperation.ExecutionAddress >= underlyingMemory.Size)
{
this.Log(LogLevel.Error, "Cannot erase memory because current address 0x{0:X} exceeds configured memory size.", currentOperation.ExecutionAddress);
return;
}
switch (currentOperation.EraseSize)
{
case DecodedOperation.OperationEraseSize.Sector:
EraseSector();
break;
case DecodedOperation.OperationEraseSize.Subsector4K:
EraseSubsector4K();
break;
case DecodedOperation.OperationEraseSize.Die:
EraseDie();
break;
default:
this.Log(LogLevel.Warning, "Unsupported erase type: {0}", currentOperation.EraseSize);
break;
}
}
else
{
this.Log(LogLevel.Error, "Erase operations are disabled.");
}
break;
default:
this.Log(LogLevel.Warning, "Encountered unexpected command: {0}", currentOperation);
break;
}
}
private void EraseDie()
{
var position = 0;
var segment = new byte[SegmentSize];
for (var i = 0; i < SegmentSize; i++)
{
segment[i] = EmptySegment;
}
while (position < underlyingMemory.Size)
{
var length = (int)Math.Min(SegmentSize, underlyingMemory.Size - position);
underlyingMemory.WriteBytes(position, segment, length);
position += length;
}
}
private void EraseSector()
{
var segment = new byte[SegmentSize];
for (var i = 0; i < SegmentSize; i++)
{
segment[i] = EmptySegment;
}
// The documentations states that on erase the operation address is
// aligned to the segment size
var position = SegmentSize * (currentOperation.ExecutionAddress / SegmentSize);
underlyingMemory.WriteBytes(position, segment);
}
private void EraseSubsector4K()
{
var segment = new byte[4.KB()];
for (var i = 0; i < 4.KB(); i++)
{
segment[i] = EmptySegment;
}
// The documentations states that on erase the operation address is
// aligned to the segment size
var position = 4.KB() * (currentOperation.ExecutionAddress / 4.KB());
underlyingMemory.WriteBytes(position, segment);
}
private void WriteToMemory(byte val)
{
if (currentOperation.ExecutionAddress + currentOperation.CommandBytesHandled > underlyingMemory.Size)
{
this.Log(LogLevel.Error, "Cannot write to address 0x{0:X} because it is bigger than configured memory size.", currentOperation.ExecutionAddress);
return;
}
var position = currentOperation.ExecutionAddress + currentOperation.CommandBytesHandled;
underlyingMemory.WriteByte(position, val);
}
private byte ReadFromMemory()
{
if (currentOperation.ExecutionAddress + currentOperation.CommandBytesHandled > underlyingMemory.Size)
{
this.Log(LogLevel.Error, "Cannot read from address 0x{0:X} because it is bigger than configured memory size.", currentOperation.ExecutionAddress);
return 0;
}
var position = currentOperation.ExecutionAddress + currentOperation.CommandBytesHandled;
return underlyingMemory.ReadByte(position);
}
private DecodedOperation currentOperation;
private uint temporaryNonVolatileConfiguration; //this should be an ushort, but due to C# type promotions it's easier to use uint
private readonly byte[] deviceData;
private readonly int SegmentSize = 64.KB();
private readonly IFlagRegisterField enable;
private readonly ByteRegister statusRegister;
private readonly ByteRegister flagStatusRegister;
private readonly IFlagRegisterField numberOfAddressBytes;
private readonly ByteRegister volatileConfigurationRegister;
private readonly ByteRegister enhancedVolatileConfigurationRegister;
private readonly WordRegister nonVolatileConfigurationRegister;
private readonly MappedMemory underlyingMemory;
private const byte EmptySegment = 0xff;
private const byte ManufacturerID = 0xC2;
private const byte RemainingIDBytes = 0x10;
private const byte MemoryType = 0x80;
private const byte MemoryDensity = 0x3B;
private const byte DeviceConfiguration = 0x0; // standard
private const byte DeviceGeneration = 0x1; // 2nd generation
private const byte ExtendedDeviceID = DeviceGeneration << 6;
private bool opiMode = false;
private bool isFirstOpiByte = false;
private byte firstOpiByte;
private enum Commands : byte
{
// Software RESET Operations
ResetEnable = 0x66,
ResetMemory = 0x99,
// READ ID Operations
ReadID = 0x9F,
ReadSerialFlashDiscoveryParameter = 0x5A,
// READ MEMORY Operations
Read = 0x03,
FastRead = 0x0B,
// READ MEMORY Operations with 4-Byte Address
Read4byte = 0x13,
FastRead4byte = 0x0C,
// WRITE Operations
WriteEnable = 0x06,
WriteDisable = 0x04,
// READ REGISTER Operations
ReadStatusRegister = 0x05,
ReadConfigurationRegister2 = 0x71,
ReadFastBootRegister = 0x16,
// WRITE REGISTER Operations
WriteStatusRegister = 0x01,
WriteConfigurationRegister2 = 0x72,
WriteFastBootRegister = 0x17,
// PROGRAM Operations
PageProgram = 0x02,
// PROGRAM Operations with 4-Byte Address
PageProgram4byte = 0x12,
// ERASE Operations
SubsectorErase4kb = 0x20,
SectorErase = 0xD8,
DieErase = 0x60,
EraseFastBootRegister = 0x18,
// ERASE Operations with 4-Byte Address
SectorErase4byte = 0xDC,
SubsectorErase4byte4kb = 0x21,
SubsectorErase4byte32kb = 0x5C,
DieErase4byte = 0xC7,
// SUSPEND/RESUME Operations
ProgramEraseSuspend = 0xB0,
ProgramEraseResume = 0x30,
// ONE-TIME PROGRAMMABLE (OTP) Operations
EnterSecuredOtp = 0xB1,
ExitSecuredOtp = 0xC1,
// Deep Power-Down Operations
EnterDeepPowerDown = 0xB9,
ReleaseFromDeepPowerdown = 0xAB,
// ADVANCED SECTOR PROTECTION Operations
ReadSectorProtection = 0x2D,
ProgramSectorProtection = 0x2C,
ReadSpbRegister = 0xE2,
WriteSpbRegister = 0xE3,
EraseSpbRegister = 0xE4,
ReadPassword = 0x27,
WritePassword = 0x28,
UnlockPassword = 0x29,
// ADVANCED SECTOR PROTECTION Operations with 4-Byte Address
ReadDpbRegister = 0xE0,
WriteDpbRegister = 0xE1,
// SECURITY REGISTER
ReadSecurityRegister = 0x2B,
WriteSecurityRegister = 0x2F,
}
private enum Register : uint
{
Status = 1, //starting from 1 to leave 0 as an unused value
ConfigurationRegister2,
SecurityRegister,
// The following are currently unised
FlagStatus,
ExtendedAddress,
NonVolatileConfiguration,
VolatileConfiguration,
EnhancedVolatileConfiguration
}
}
}

View file

@ -1,130 +0,0 @@
//
// Copyright (c) 2010-2021 Antmicro
//
// This file is licensed under the MIT License.
// Full license text is available in 'licenses/MIT.txt'.
//
using System.Collections.Generic;
using Antmicro.Renode.Core;
using Antmicro.Renode.Core.Structure;
using Antmicro.Renode.Exceptions;
using Antmicro.Renode.Logging;
using Antmicro.Renode.Time;
namespace Antmicro.Renode.Peripherals.SPI
{
public static class SPIConnectorExtensions
{
public static void CreateSPIConnector(this Emulation emulation, string name)
{
emulation.ExternalsManager.AddExternal(new SPIConnector(), name);
}
}
public class SPIConnector : IExternal, ISPIPeripheral, IConnectable<ISPIPeripheral>, IConnectable<NullRegistrationPointPeripheralContainer<ISPIPeripheral>>
{
public void Reset()
{
peripheralOutput.Clear();
}
public void AttachTo(NullRegistrationPointPeripheralContainer<ISPIPeripheral> controller)
{
lock(locker)
{
if(controller == this.controller)
{
throw new RecoverableException("Cannot attach to the provided peripheral as it is already registered in this connector.");
}
else if(this.controller != null)
{
this.Log(LogLevel.Warning, "Overwriting controller connection.");
}
this.controller?.Unregister(this);
this.controller = controller;
this.controller.Register(this, NullRegistrationPoint.Instance);
}
}
public void AttachTo(ISPIPeripheral peripheral)
{
lock(locker)
{
if(peripheral == this.peripheral)
{
throw new RecoverableException("Cannot attach to the provided peripheral as it is already registered in this connector.");
}
else if(this.peripheral != null)
{
this.Log(LogLevel.Warning, "Overwriting peripheral connection.");
}
this.peripheral = peripheral;
}
}
public void DetachFrom(NullRegistrationPointPeripheralContainer<ISPIPeripheral> controller)
{
lock(locker)
{
if(controller == this.controller)
{
this.controller.Unregister(this);
this.controller = null;
}
else
{
throw new RecoverableException("Cannot detach from the provided controller as it is not registered in this connector.");
}
}
}
public void DetachFrom(ISPIPeripheral peripheral)
{
lock(locker)
{
if(peripheral == this.peripheral)
{
peripheral = null;
peripheralOutput.Clear();
}
else
{
throw new RecoverableException("Cannot detach from the provided peripheral as it is not registered in this connector.");
}
}
}
public byte Transmit(byte data)
{
lock(locker)
{
if(peripheral == null)
{
this.Log(LogLevel.Warning, "Controller sent data (0x{0:X}), but peripheral is not connected.", data);
return 0x0;
}
peripheral.GetMachine().HandleTimeDomainEvent(InnerTransmit, data, TimeDomainsManager.Instance.VirtualTimeStamp);
return peripheralOutput.Count > 0 ? peripheralOutput.Dequeue() : (byte)0x0;
}
}
public void FinishTransmission()
{
lock(locker)
{
peripheral.GetMachine().HandleTimeDomainEvent<object>(_ => peripheral.FinishTransmission(), null, TimeDomainsManager.Instance.VirtualTimeStamp);
}
}
private void InnerTransmit(byte data)
{
peripheralOutput.Enqueue(peripheral.Transmit(data));
}
private NullRegistrationPointPeripheralContainer<ISPIPeripheral> controller;
private ISPIPeripheral peripheral;
private readonly Queue<byte> peripheralOutput = new Queue<byte>();
private readonly object locker = new object();
}
}

View file

@ -70,23 +70,263 @@ namespace Antmicro.Renode.Peripherals.Miscellaneous
this.locked[i] = false;
}
this.data[0x0] = 0x9516051b;
this.data[0x1] = 0x315aa513;
this.data[0x2] = 0x28417c6;
this.data[0x3] = 0x3c6818d6;
this.data[0x4] = 0x52d8972b;
this.data[0x5] = 0x10e5b388;
this.data[0x6] = 0xa2177e24;
this.data[0x7] = 0xf84ff81f;
this.data[0x8] = 0xf2460da1;
this.data[0x9] = 0xf86d51b5;
this.data[0xa] = 0x4e279ae7;
this.data[0xb] = 0x224a7158;
this.data[0xc] = 0x4676edb1;
this.data[0xd] = 0x297db43b;
this.data[0xe] = 0xeff3cd32;
this.data[0xf] = 0xe2f39301;
this.data[0x10] = 0x560e91d3;
this.data[0x11] = 0xe9439e5e;
this.data[0x12] = 0xa600629c;
this.data[0x13] = 0x3276f5b8;
this.data[0x14] = 0xcca5ba59;
this.data[0x15] = 0x9cbae96e;
this.data[0x16] = 0x96899a9c;
this.data[0x17] = 0xa92c5624;
this.data[0x18] = 0x1c9beae3;
this.data[0x19] = 0x2aeac875;
this.data[0x1a] = 0x07c18094;
this.data[0x1a] = 0x7c18094;
this.data[0x1b] = 0x387eff1c;
this.data[0x1c] = 0x74614282;
this.data[0x1d] = 0xaffd8152;
this.data[0x1e] = 0xd871352e;
this.data[0x1f] = 0xdf3f58bb;
// Words are swapped on this little-endian system.
// this.data[0x18] = 0xe3ea9b1c;
// this.data[0x19] = 0x75c8ea2a;
// this.data[0x1a] = 0x9480c107;
// this.data[0x1b] = 0x1cff7e38;
// this.data[0x1c] = 0x82426174;
// this.data[0x1d] = 0x5281fdaf;
// this.data[0x1e] = 0x2e3571d8;
// this.data[0x1f] = 0xbb583fdf;
this.data[0x20] = 0x0;
this.data[0x21] = 0x0;
this.data[0x22] = 0x0;
this.data[0x23] = 0x0;
this.data[0x24] = 0x0;
this.data[0x25] = 0x0;
this.data[0x26] = 0x0;
this.data[0x27] = 0x0;
this.data[0x28] = 0xf2460da1;
this.data[0x29] = 0xf86d51b5;
this.data[0x2a] = 0x4e279ae7;
this.data[0x2b] = 0x224a7158;
this.data[0x2c] = 0x4676edb1;
this.data[0x2d] = 0x297db43b;
this.data[0x2e] = 0xeff3cd32;
this.data[0x2f] = 0xe2f39301;
this.data[0x30] = 0x0;
this.data[0x31] = 0x0;
this.data[0x32] = 0x0;
this.data[0x33] = 0x0;
this.data[0x34] = 0x0;
this.data[0x35] = 0x0;
this.data[0x36] = 0x0;
this.data[0x37] = 0x0;
this.data[0x38] = 0x0;
this.data[0x39] = 0x0;
this.data[0x3a] = 0x0;
this.data[0x3b] = 0x0;
this.data[0x3c] = 0x0;
this.data[0x3d] = 0x0;
this.data[0x3e] = 0x0;
this.data[0x3f] = 0x0;
this.data[0x40] = 0x0;
this.data[0x41] = 0x0;
this.data[0x42] = 0x0;
this.data[0x43] = 0x0;
this.data[0x44] = 0x0;
this.data[0x45] = 0x0;
this.data[0x46] = 0x0;
this.data[0x47] = 0x0;
this.data[0x48] = 0x0;
this.data[0x49] = 0x0;
this.data[0x4a] = 0x0;
this.data[0x4b] = 0x0;
this.data[0x4c] = 0x0;
this.data[0x4d] = 0x0;
this.data[0x4e] = 0x0;
this.data[0x4f] = 0x0;
this.data[0x50] = 0x0;
this.data[0x51] = 0x0;
this.data[0x52] = 0x0;
this.data[0x53] = 0x0;
this.data[0x54] = 0x0;
this.data[0x55] = 0x0;
this.data[0x56] = 0x0;
this.data[0x57] = 0x0;
this.data[0x58] = 0x0;
this.data[0x59] = 0x0;
this.data[0x5a] = 0x0;
this.data[0x5b] = 0x0;
this.data[0x5c] = 0x0;
this.data[0x5d] = 0x0;
this.data[0x5e] = 0x0;
this.data[0x5f] = 0x0;
this.data[0x60] = 0x0;
this.data[0x61] = 0x0;
this.data[0x62] = 0x0;
this.data[0x63] = 0x0;
this.data[0x64] = 0x0;
this.data[0x65] = 0x0;
this.data[0x66] = 0x0;
this.data[0x67] = 0x0;
this.data[0x68] = 0x0;
this.data[0x69] = 0x0;
this.data[0x6a] = 0x0;
this.data[0x6b] = 0x0;
this.data[0x6c] = 0x0;
this.data[0x6d] = 0x0;
this.data[0x6e] = 0x0;
this.data[0x6f] = 0x0;
this.data[0x70] = 0x0;
this.data[0x71] = 0x0;
this.data[0x72] = 0x0;
this.data[0x73] = 0x0;
this.data[0x74] = 0x0;
this.data[0x75] = 0x0;
this.data[0x76] = 0x0;
this.data[0x77] = 0x0;
this.data[0x78] = 0x0;
this.data[0x79] = 0x0;
this.data[0x7a] = 0x0;
this.data[0x7b] = 0x0;
this.data[0x7c] = 0x0;
this.data[0x7d] = 0x0;
this.data[0x7e] = 0x0;
this.data[0x7f] = 0x0;
this.data[0x80] = 0x0;
this.data[0x81] = 0x0;
this.data[0x82] = 0x0;
this.data[0x83] = 0x0;
this.data[0x84] = 0x0;
this.data[0x85] = 0x0;
this.data[0x86] = 0x0;
this.data[0x87] = 0x0;
this.data[0x88] = 0x0;
this.data[0x89] = 0x0;
this.data[0x8a] = 0x0;
this.data[0x8b] = 0x0;
this.data[0x8c] = 0x0;
this.data[0x8d] = 0x0;
this.data[0x8e] = 0x0;
this.data[0x8f] = 0x0;
this.data[0x90] = 0x0;
this.data[0x91] = 0x0;
this.data[0x92] = 0x0;
this.data[0x93] = 0x0;
this.data[0x94] = 0x0;
this.data[0x95] = 0x0;
this.data[0x96] = 0x0;
this.data[0x97] = 0x0;
this.data[0x98] = 0x0;
this.data[0x99] = 0x0;
this.data[0x9a] = 0x0;
this.data[0x9b] = 0x0;
this.data[0x9c] = 0x0;
this.data[0x9d] = 0x0;
this.data[0x9e] = 0x0;
this.data[0x9f] = 0x0;
this.data[0xa0] = 0x0;
this.data[0xa1] = 0x0;
this.data[0xa2] = 0x0;
this.data[0xa3] = 0x0;
this.data[0xa4] = 0x0;
this.data[0xa5] = 0x0;
this.data[0xa6] = 0x0;
this.data[0xa7] = 0x0;
this.data[0xa8] = 0x0;
this.data[0xa9] = 0x0;
this.data[0xaa] = 0x0;
this.data[0xab] = 0x0;
this.data[0xac] = 0x0;
this.data[0xad] = 0x0;
this.data[0xae] = 0x0;
this.data[0xaf] = 0x0;
this.data[0xb0] = 0x0;
this.data[0xb1] = 0x0;
this.data[0xb2] = 0x0;
this.data[0xb3] = 0x0;
this.data[0xb4] = 0x0;
this.data[0xb5] = 0x0;
this.data[0xb6] = 0x0;
this.data[0xb7] = 0x0;
this.data[0xb8] = 0x0;
this.data[0xb9] = 0x0;
this.data[0xba] = 0x0;
this.data[0xbb] = 0x0;
this.data[0xbc] = 0x0;
this.data[0xbd] = 0x0;
this.data[0xbe] = 0x0;
this.data[0xbf] = 0x0;
this.data[0xc0] = 0x0;
this.data[0xc1] = 0x0;
this.data[0xc2] = 0x0;
this.data[0xc3] = 0x0;
this.data[0xc4] = 0x0;
this.data[0xc5] = 0x0;
this.data[0xc6] = 0x0;
this.data[0xc7] = 0x0;
this.data[0xc8] = 0x0;
this.data[0xc9] = 0x0;
this.data[0xca] = 0x0;
this.data[0xcb] = 0x0;
this.data[0xcc] = 0x0;
this.data[0xcd] = 0x0;
this.data[0xce] = 0x0;
this.data[0xcf] = 0x0;
this.data[0xd0] = 0x0;
this.data[0xd1] = 0x0;
this.data[0xd2] = 0x0;
this.data[0xd3] = 0x0;
this.data[0xd4] = 0x0;
this.data[0xd5] = 0x0;
this.data[0xd6] = 0x0;
this.data[0xd7] = 0x0;
this.data[0xd8] = 0x0;
this.data[0xd9] = 0x0;
this.data[0xda] = 0x0;
this.data[0xdb] = 0x0;
this.data[0xdc] = 0x0;
this.data[0xdd] = 0x0;
this.data[0xde] = 0x0;
this.data[0xdf] = 0x0;
this.data[0xe0] = 0x0;
this.data[0xe1] = 0x0;
this.data[0xe2] = 0x0;
this.data[0xe3] = 0x0;
this.data[0xe4] = 0x0;
this.data[0xe5] = 0x0;
this.data[0xe6] = 0x0;
this.data[0xe7] = 0x0;
this.data[0xe8] = 0x0;
this.data[0xe9] = 0x0;
this.data[0xea] = 0x0;
this.data[0xeb] = 0x0;
this.data[0xec] = 0x0;
this.data[0xed] = 0x0;
this.data[0xee] = 0x0;
this.data[0xef] = 0x0;
this.data[0xf0] = 0x0;
this.data[0xf1] = 0x0;
this.data[0xf2] = 0x0;
this.data[0xf3] = 0x0;
this.data[0xf4] = 0x0;
this.data[0xf5] = 0x0;
this.data[0xf6] = 0x0;
this.data[0xf7] = 0x0;
this.data[0xf8] = 0xe01133bd;
this.data[0xf9] = 0xc0ea362;
this.data[0xfa] = 0x9d48a555;
this.data[0xfb] = 0x947a820;
this.data[0xfc] = 0x0;
this.data[0xfd] = 0x0;
this.data[0xfe] = 0x0;
this.data[0xff] = 0x1000008;
this.lockAddress = 0;
}

File diff suppressed because it is too large Load diff

View file

@ -1,6 +1,6 @@
// Renode Platform file generated by svd2repl
// This file is automatically generated
cpu: CPU.VexRiscv @ sysbus
cpu: CPU.AesVexRiscv @ sysbus
cpuType: "rv32imac"
privilegeArchitecture: PrivilegeArchitecture.Priv1_10
PerformanceInMips: 120
@ -54,7 +54,8 @@ ticktimer: Timers.TickTimer @ sysbus 0xf0012000
spinor_soft_int: Miscellaneous.SpinorSoftInt @ sysbus 0xf0015000
IRQ -> cpu @ 1011
// Unrecognized peripheral: spinor @ 0xf0016000
spinor: SPI.BetrustedSpinor @ sysbus 0xf0016000
IRQ -> cpu @ 1012
keyboard: Input.BetrustedKbd @ sysbus 0xf0017000
IRQ -> cpu @ 1013
@ -116,6 +117,9 @@ audio: Memory.MappedMemory @ sysbus 0xe0000000
abracom_rtc: Sensors.ABRTCMC @ i2c 0x68
flash: SPI.MXIC_MX66UM1G45G @ spinor
underlyingMemory: spiflash
sysbus:
init:
ApplySVD @soc/renode.svd

View file

@ -11,6 +11,7 @@ using sysbus
i @peripherals/ABRTCMC.cs
i @peripherals/BetrustedEcI2C.cs
i @peripherals/BetrustedSocI2C.cs
i @peripherals/BetrustedSpinor.cs
i @peripherals/BetrustedWatchdog.cs
i @peripherals/BQ24157.cs
i @peripherals/BQ27421.cs
@ -23,6 +24,7 @@ i @peripherals/LiteX_Timer_32.cs
i @peripherals/LM3509.cs
i @peripherals/LSM6DS3.cs
i @peripherals/memlcd.cs
i @peripherals/MXIC_MX66UM1G45G.cs
i @peripherals/sha512.cs
i @peripherals/spinor_soft_int.cs
i @peripherals/ticktimer.cs
@ -31,6 +33,9 @@ i @peripherals/trng_server.cs
i @peripherals/TUSB320LAI.cs
i @peripherals/wfi.cs
EnsureTypeIsLoaded "Antmicro.Renode.Peripherals.CPU.VexRiscv"
i @peripherals/vexriscv-aes.cs
# Create the COM SPI bus
emulation CreateComConnector "com"
@ -57,11 +62,13 @@ sysbus Tag <0xB0000000, 0xB0006000> "Framebuffer"
# logLevel -1 i2c
# logLevel -1 i2c.abracom_rtc
# logLevel -1 sha512
# logLevel -1 sysbus.spinor.flash
# sysbus LogPeripheralAccess spinor true
# Silence GPIO
sysbus SilenceRange <0xf0003000, 0xF0003FFF>
# sysbus SilenceRange <0xF0021000, 0xF0021FFF>
# sysbus SilenceRange <0xF0023000, 0xF0023FFF>
# Silence POWER
sysbus SilenceRange <0xF0014000 100>
# Load the SPI flash into RAM
sysbus LoadBinary @precursors/soc_csr.bin 0x20000000
@ -84,7 +91,6 @@ emulation CreateServerSocketTerminal 9999 "kernel" False
connector Connect sysbus.uart kernel
runMacro $reset
sysbus.cpu InstallCustomInstructionHandlerFromFile "00ss0fdbbbbbaaaaa000ddddd0001011" @vexriscv-aes.py
mach clear

View file

@ -479,7 +479,7 @@ fn parse_vendor_extensions<T: BufRead>(
fn print_header<U: Write>(out: &mut U) -> std::io::Result<()> {
let s = r####"// Renode Platform file generated by svd2repl
// This file is automatically generated
cpu: CPU.VexRiscv @ sysbus
cpu: CPU.AesVexRiscv @ sysbus
cpuType: "rv32imac"
privilegeArchitecture: PrivilegeArchitecture.Priv1_10
PerformanceInMips: 120
@ -491,6 +491,9 @@ fn print_footer<U: Write>(out: &mut U) -> std::io::Result<()> {
let s = r####"
abracom_rtc: Sensors.ABRTCMC @ i2c 0x68
flash: SPI.MXIC_MX66UM1G45G @ spinor
underlyingMemory: spiflash
sysbus:
init:
ApplySVD @soc/renode.svd
@ -640,6 +643,7 @@ pub fn generate<T: Read, U: Write>(src: T, dest: &mut U) -> Result<(), ParseErro
cs_peripherals.insert("memlcd", "Video.BetrustedLCD");
cs_peripherals.insert("sha512", "Miscellaneous.Sha512");
cs_peripherals.insert("spinor_soft_int", "Miscellaneous.SpinorSoftInt");
cs_peripherals.insert("spinor", "SPI.BetrustedSpinor");
cs_peripherals.insert("timer0", "Timers.LiteX_Timer_32");
cs_peripherals.insert("trng_kernel", "Miscellaneous.BetrustedRNGKernel");
cs_peripherals.insert("trng_server", "Miscellaneous.BetrustedRNGServer");