1
1
mirror of https://github.com/NixOS/mobile-nixos.git synced 2024-12-16 11:43:21 +03:00
mobile-nixos/bin/boot-qemu
2018-06-23 17:11:07 -04:00

51 lines
1.4 KiB
Ruby
Executable File

#!/usr/bin/env nix-shell
#!nix-shell -p ruby -i ruby
# Boots a given `result` symlink on a remote system.
# This is mainly used to speed-up development where
# an aarch64 host is used to build the system, but the
# target device is plugged into another system
require_relative "../lib/rb/all.rb"
require "fileutils"
include FileUtils
# This assumes `result` is boot.img.
STORE_PATH = File.readlink("result")
# FIXME : read-only doesn't work...
$copy_readwrite = true;
begin
disk_image = Dir.glob(File.join(File.readlink("result"), "system", "sd-image", "*.img")).first
if $copy_readwrite then
DISK_IMAGE = "fs.img"
cp(disk_image, DISK_IMAGE)
chmod("u=rw", DISK_IMAGE)
else
DISK_IMAGE = disk_image
end
end
unless ARGV.count == 0 then
puts "Usage: bin/boot-eqmu"
exit 1
end
KERNEL_INITRD = "result/kernel-initrd"
args = []
args.push("qemu-system-x86_64")
args.push("-kernel", "#{KERNEL_INITRD}/kernel")
args.push("-initrd", "#{KERNEL_INITRD}/initrd")
args.push("-append", File.read("#{KERNEL_INITRD}/cmdline.txt"))
args.push("-m", "#{File.read("#{KERNEL_INITRD}/ram.txt")}M")
args.push("-serial", "stdio")
args.push("-drive", "file=#{DISK_IMAGE},format=raw#{if $copy_readwrite then "" else ",readonly" end}")
args.push("-device", "e1000,netdev=net0")
args.push("-netdev", "user,id=net0,hostfwd=tcp::2222-:22,hostfwd=tcp::2323-:23,net=172.16.42.0/24,dhcpstart=172.16.42.1")
run(*args, exec: true)
# vim: ft=ruby