2018-08-17 18:31:38 +02:00
|
|
|
#!/usr/bin/env node
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
const path = require("path");
|
|
|
|
|
|
|
|
// TODO:
|
|
|
|
// - Timeout
|
|
|
|
|
2018-10-15 18:54:01 +02:00
|
|
|
console.log("Don't forget to run `make all` before running this script");
|
2018-08-17 18:31:38 +02:00
|
|
|
|
|
|
|
var fs = require("fs");
|
2021-09-20 04:04:46 +02:00
|
|
|
var V86 = require("./../../../build/libv86.js").V86;
|
2018-08-17 18:31:38 +02:00
|
|
|
|
2021-09-20 04:04:46 +02:00
|
|
|
const V86_ROOT = path.join(__dirname, "../../..");
|
2018-08-17 18:31:38 +02:00
|
|
|
|
|
|
|
var OUTPUT_FILE = path.join(V86_ROOT, "images/debian-state-base.bin");
|
|
|
|
|
|
|
|
process.stdin.setRawMode(true);
|
|
|
|
process.stdin.resume();
|
|
|
|
process.stdin.setEncoding("utf8");
|
2018-11-04 22:32:17 +01:00
|
|
|
process.stdin.on("data", handle_key);
|
2018-08-17 18:31:38 +02:00
|
|
|
|
|
|
|
var emulator = new V86({
|
|
|
|
bios: { url: path.join(V86_ROOT, "/bios/seabios.bin") },
|
|
|
|
vga_bios: { url: path.join(V86_ROOT, "/bios/vgabios.bin") },
|
|
|
|
autostart: true,
|
|
|
|
memory_size: 512 * 1024 * 1024,
|
|
|
|
vga_memory_size: 8 * 1024 * 1024,
|
|
|
|
network_relay_url: "<UNUSED>",
|
2018-10-15 17:05:22 +02:00
|
|
|
bzimage_initrd_from_filesystem: true,
|
2018-10-05 22:17:57 +02:00
|
|
|
cmdline: "rw init=/bin/systemd root=host9p console=ttyS0 spectre_v2=off pti=off",
|
2018-08-17 18:31:38 +02:00
|
|
|
filesystem: {
|
|
|
|
basefs: {
|
|
|
|
url: path.join(V86_ROOT, "/images/debian-base-fs.json"),
|
|
|
|
},
|
|
|
|
baseurl: path.join(V86_ROOT, "/images/debian-9p-rootfs-flat/"),
|
|
|
|
},
|
|
|
|
screen_dummy: true,
|
|
|
|
});
|
|
|
|
|
|
|
|
console.log("Now booting, please stand by ...");
|
|
|
|
|
|
|
|
var boot_start = Date.now();
|
|
|
|
var serial_text = "";
|
2018-11-05 01:47:31 +01:00
|
|
|
let booted = false;
|
2018-08-17 18:31:38 +02:00
|
|
|
|
|
|
|
emulator.add_listener("serial0-output-char", function(c)
|
|
|
|
{
|
|
|
|
process.stdout.write(c);
|
|
|
|
|
|
|
|
serial_text += c;
|
|
|
|
|
2018-11-05 01:47:31 +01:00
|
|
|
if(!booted && serial_text.endsWith("root@localhost:~# "))
|
2018-08-17 18:31:38 +02:00
|
|
|
{
|
|
|
|
console.error("\nBooted in %d", (Date.now() - boot_start) / 1000);
|
2018-11-05 01:47:31 +01:00
|
|
|
booted = true;
|
2018-08-17 18:31:38 +02:00
|
|
|
|
2018-11-05 01:47:31 +01:00
|
|
|
// sync and drop caches: Makes it safer to change the filesystem as fewer files are rendered
|
|
|
|
emulator.serial0_send("sync;echo 3 >/proc/sys/vm/drop_caches\n");
|
2018-08-17 18:31:38 +02:00
|
|
|
|
2022-07-25 14:55:07 +02:00
|
|
|
setTimeout(async function ()
|
2018-08-17 18:31:38 +02:00
|
|
|
{
|
2022-07-25 14:55:07 +02:00
|
|
|
const s = await emulator.save_state();
|
|
|
|
|
|
|
|
fs.writeFile(OUTPUT_FILE, new Uint8Array(s), function(e)
|
2018-08-17 18:31:38 +02:00
|
|
|
{
|
2022-07-25 14:55:07 +02:00
|
|
|
if(e) throw e;
|
|
|
|
console.error("Saved as " + OUTPUT_FILE);
|
|
|
|
stop();
|
2018-08-17 18:31:38 +02:00
|
|
|
});
|
2018-11-05 01:47:31 +01:00
|
|
|
}, 10 * 1000);
|
2018-08-17 18:31:38 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2018-11-04 22:32:17 +01:00
|
|
|
function handle_key(c)
|
|
|
|
{
|
|
|
|
if(c === "\u0003")
|
|
|
|
{
|
|
|
|
// ctrl c
|
|
|
|
stop();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
emulator.serial0_send(c);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function stop()
|
|
|
|
{
|
|
|
|
emulator.stop();
|
|
|
|
process.stdin.pause();
|
|
|
|
}
|