Commit 542ee066 authored by Kroese's avatar Kroese
Browse files

Implement serial emulator

parent 720d8ac7
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -20,13 +20,13 @@ COPY generate-dhcpd-conf /run/
COPY qemu-ifdown /run/
COPY qemu-ifup /run/
COPY run.sh /run/
COPY --from=builder /src/vdsm-serial/main /run/
COPY --from=builder /src/vdsm-serial/main /run/serial.bin

RUN ["chmod", "+x", "/run/generate-dhcpd-conf"]
RUN ["chmod", "+x", "/run/qemu-ifdown"]
RUN ["chmod", "+x", "/run/qemu-ifup"]
RUN ["chmod", "+x", "/run/run.sh"]
RUN ["chmod", "+x", "/run/main"]
RUN ["chmod", "+x", "/run/serial.bin"]

VOLUME /images

+16 −3
Original line number Diff line number Diff line
#!/usr/bin/env bash

echo "Booting Synology DSM for Docker..."

FILE="/images/boot.img"
if [ ! -f "$FILE" ]; then
    echo "ERROR: Synology DSM boot-image does not exist ($FILE)"
@@ -22,7 +24,6 @@ if [ ! -f "$FILE" ]; then
    exit 2
fi


# A bridge of this name will be created to host the TAP interface created for
# the VM
QEMU_BRIDGE='qemubr0'
@@ -70,16 +71,28 @@ touch /var/lib/misc/udhcpd.leases
# Finally, start our DHCPD server
udhcpd -I $DUMMY_DHCPD_IP -f $DHCPD_CONF_FILE &

echo "Launching Synology Serial Emulator..."

# Start the Synology Serial Emulator
./run/serial.bin -vmmversion "2.6.1-12139" -buildnumber 42962 -vmmts 1650802981032 -cpu 1 -cpu_arch string "QEMU, Virtual CPU, X86_64" -guestsn "0000000000000" -hostsn "0000000000000" -guestuuid "ba13a19a-c0c1-4fef-9346-915ed3b98341" &

echo "Booting OS..."

# And run the VM! A brief explaination of the options here:
# -enable-kvm: Use KVM for this VM (much faster for our case).
# -nographic: disable SDL graphics.
# -serial mon:stdio: use "monitored stdio" as our serial output.
exec qemu-system-x86_64 -enable-kvm -nographic -serial mon:stdio \
exec qemu-system-x86_64 -name Synology -enable-kvm -nographic -serial mon:stdio \
    "$@" \
    -device virtio-serial-pci,id=virtio-serial0,bus=pci.0,addr=0x3 -chardev pty,id=charserial0 \
    -device isa-serial,chardev=charserial0,id=serial0 -chardev socket,id=charchannel0,host=127.0.0.1,port=12345,reconnect=10 \
    -device virtserialport,bus=virtio-serial0.0,nr=1,chardev=charchannel0,id=channel0,name=vchannel \
    -device virtio-net,netdev=tap0 -netdev tap,id=tap0,ifname=Tap,script=$QEMU_IFUP,downscript=$QEMU_IFDOWN \
    -device virtio-scsi-pci,id=hw-synoboot,bus=pci.0,addr=0xa -drive file=/images/boot.img,if=none,id=drive-synoboot,format=raw,cache=none,aio=native,detect-zeroes=on \
    -device scsi-hd,bus=hw-synoboot.0,channel=0,scsi-id=0,lun=0,drive=drive-synoboot,id=synoboot0,bootindex=1 \
    -device virtio-scsi-pci,id=hw-synosys,bus=pci.0,addr=0xb -drive file=/images/system.img,if=none,id=drive-synosys,format=raw,cache=none,aio=native,detect-zeroes=on \
    -device scsi-hd,bus=hw-synosys.0,channel=0,scsi-id=0,lun=0,drive=drive-synosys,id=synosys0,bootindex=2 \
    -device virtio-scsi-pci,id=hw-userdata,bus=pci.0,addr=0xc -drive file=/images/data.img,if=none,id=drive-userdata,format=raw,cache=none,aio=native,detect-zeroes=on \
    -device scsi-hd,bus=hw-userdata.0,channel=0,scsi-id=0,lun=0,drive=drive-userdata,id=userdata0,bootindex=3
    -device scsi-hd,bus=hw-userdata.0,channel=0,scsi-id=0,lun=0,drive=drive-userdata,id=userdata0,bootindex=3 \
    -device piix3-usb-uhci,id=usb,bus=pci.0,addr=0x1.0x2
+1 −7
Original line number Diff line number Diff line
@@ -8,7 +8,6 @@ import (
	"log"
	"net"
	"strconv"
	"time"
)

type REQ struct {
@@ -44,13 +43,8 @@ var ListenAddr = flag.String("addr", "0.0.0.0:12345", "Listen address")
func main() {
	flag.Parse()
	log.Println("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!")
	log.Println("!!! Just for experimental, please delete it after 24 hour  !!!")
	log.Println("!!! See https://jxcn.org for update.                       !!!")
	log.Println("!!! This program will be unavailable after 2022-12-31      !!!")
	log.Println("!!!  Synology Serial Emulator created by https://jxcn.org  !!!")
	log.Println("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!")
	if time.Now().Year() >= 2023 {
		log.Panic("Expired")
	}
	listener, err := net.Listen("tcp", *ListenAddr)
	if err != nil {
		log.Println("Error listening", err.Error())