Skip to content

Commit

Permalink
tidying
Browse files Browse the repository at this point in the history
  • Loading branch information
abarisani committed Feb 5, 2025
1 parent 8cc7416 commit 0d88bc5
Show file tree
Hide file tree
Showing 9 changed files with 14 additions and 58 deletions.
42 changes: 0 additions & 42 deletions cmd/firecracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,12 @@
package cmd

import (
"bytes"
"errors"
"fmt"
"runtime"

"golang.org/x/term"

"github.com/usbarmory/tamago/board/firecracker/microvm"
"github.com/usbarmory/tamago/kvm/clock"
intel_uart "github.com/usbarmory/tamago/soc/intel/uart"
)

var boardName = "firecracker"
var NIC interface{}

type UART struct {
uart *intel_uart.UART
Expand Down Expand Up @@ -63,40 +55,6 @@ func uptime() (ns int64) {
return int64(float64(microvm.AMD64.TimerFn()) * microvm.AMD64.TimerMultiplier)
}

func mem(start uint, size int, w []byte) (b []byte) {
return memCopy(start, size, w)
}

func infoCmd(_ *Interface, _ *term.Terminal, _ []string) (string, error) {
var res bytes.Buffer

ramStart, ramEnd := runtime.MemRegion()

fmt.Fprintf(&res, "Runtime ......: %s %s/%s\n", runtime.Version(), runtime.GOOS, runtime.GOARCH)
fmt.Fprintf(&res, "RAM ..........: %#08x-%#08x (%d MiB)\n", ramStart, ramEnd, (ramEnd-ramStart)/(1024*1024))
fmt.Fprintf(&res, "Board ........: %s\n", boardName)
fmt.Fprintf(&res, "CPU ..........: %s\n", Target())

return res.String(), nil
}

func rebootCmd(_ *Interface, _ *term.Terminal, _ []string) (_ string, err error) {
return "", errors.New("unimplemented")
}

func (iface *Interface) cryptoTest() {
iface.spawn(btcdTest)
iface.spawn(kemTest)
}

func storageTest() {
return
}

func HasNetwork() (usb bool, eth bool) {
return false, true
}

func Target() (t string) {
return microvm.AMD64.Name()
}
2 changes: 1 addition & 1 deletion cmd/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ func (iface *Interface) Terminal(term *term.Terminal) {
}
}

func SerialConsole(iface *Interface) {
func StartTerminal(iface *Interface) {
term := term.NewTerminal(uart, "")
term.SetPrompt(string(term.Escape.Red) + "> " + string(term.Escape.Reset))

Expand Down
8 changes: 1 addition & 7 deletions cmd/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ import (
"golang.org/x/term"
)

var ()

func init() {
Add(Cmd{
Name: "test",
Expand Down Expand Up @@ -56,15 +54,11 @@ func testCmd(iface *Interface, _ *term.Terminal, _ []string) (_ string, _ error)
start := time.Now()

iface.spawn(timerTest)
iface.spawn(wakeTest)
iface.spawn(sleepTest)
iface.spawn(fsTest)
iface.spawn(rngTest)

if hasUSB, hasETH := HasNetwork(); !hasUSB && !hasETH {
// test incompatible with interrupt handling
iface.spawn(wakeTest)
}

// spawns on its own
iface.cryptoTest()

Expand Down
5 changes: 3 additions & 2 deletions network/firecracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,17 @@ import (
"github.com/usbarmory/virtio-net"
)

func Init(handler ConsoleHandler, hasUSB bool, hasEth bool) (dev *vnet.Net) {
func Init(handler ConsoleHandler, hasUSB bool, hasEth bool, nic **vnet.Net) {
if hasUSB {
log.Fatalf("unsupported")
}

dev = &vnet.Net{
dev := &vnet.Net{
Base: microvm.VIRTIO_NET0_BASE,
IRQ: microvm.VIRTIO_NET0_IRQ,
}

*nic = dev
startNet(handler, dev)

// This example illustrates IRQ handling, alternatively a poller can be
Expand Down
2 changes: 1 addition & 1 deletion network/imx-usbnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func startUSB(handler ConsoleHandler) (port *usb.USB) {

iface := usbnet.Interface{}

if err := iface.Init(IP, MAC, HostMAC); err != nil {
if err := iface.Init(IP, MAC, HostMAC); err != nil {
log.Fatalf("could not initialize USB networking, %v", err)
}

Expand Down
4 changes: 3 additions & 1 deletion network/imx.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,17 @@ func startInterruptHandler(usb *usb.USB, eth *enet.ENET) {
arm.ServiceInterrupts(isr)
}

func Init(console ConsoleHandler, hasUSB bool, hasEth bool) (eth *enet.ENET) {
func Init(console ConsoleHandler, hasUSB bool, hasEth bool, nic **enet.ENET) {
var usb *usb.USB
var eth *enet.ENET

if hasUSB {
usb = startUSB(console)
}

if hasEth {
eth = startEth(console)
*nic = eth
}

startInterruptHandler(usb, eth)
Expand Down
5 changes: 3 additions & 2 deletions network/microvm.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,18 @@ import (
"github.com/usbarmory/virtio-net"
)

func Init(handler ConsoleHandler, hasUSB bool, hasEth bool) (dev *vnet.Net) {
func Init(handler ConsoleHandler, hasUSB bool, hasEth bool, nic **vnet.Net) {
if hasUSB {
log.Fatalf("unsupported")
}

dev = &vnet.Net{
dev := &vnet.Net{
Base: microvm.VIRTIO_NET0_BASE,
IRQ: microvm.VIRTIO_NET0_IRQ,
HeaderLength: 10,
}

*nic = dev
startNet(handler, dev)

// This example illustrates IRQ handling, alternatively a poller can be
Expand Down
2 changes: 1 addition & 1 deletion network/stub.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ package network

import "log"

func Init(_ ConsoleHandler, _ bool, _ bool) (_ any) {
func Init(_ ConsoleHandler, _ bool, _ bool, _ interface{}) (_ any) {
log.Fatal("unsupported")
return
}
2 changes: 1 addition & 1 deletion network/virtio.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func startInterruptHandler(dev *vnet.Net, lapic *apic.LAPIC, ioapic *apic.IOAPIC
dev.RxHandler(buf)
}
lapic.ClearInterrupt()
case 6:
case 6:
// ignore this IRQ raised once at boot by Firecracker
default:
log.Printf("internal error, unexpected IRQ %d", irq)
Expand Down

0 comments on commit 0d88bc5

Please sign in to comment.