|
|
|
@ -3,22 +3,52 @@
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
options.hardware.genode.usb = {
|
|
|
|
|
options.hardware.genode.usb = let
|
|
|
|
|
mkEnableOption' = text: default:
|
|
|
|
|
lib.mkEnableOption text // {
|
|
|
|
|
inherit default;
|
|
|
|
|
};
|
|
|
|
|
in {
|
|
|
|
|
|
|
|
|
|
enable = lib.mkEnableOption "USB driver";
|
|
|
|
|
storage.enable = lib.mkEnableOption "USB mass storage driver";
|
|
|
|
|
|
|
|
|
|
ehciSupport = lib.mkEnableOption "EHCI support" // { default = true; };
|
|
|
|
|
ohciSupport = lib.mkEnableOption "OHCI support" // { default = true; };
|
|
|
|
|
uhciSupport = lib.mkEnableOption "UHCI support" // { default = false; };
|
|
|
|
|
xhciSupport = lib.mkEnableOption "XHCI support" // { default = true; };
|
|
|
|
|
biosHandoff = mkEnableOption' "perform the BIOS handoff procedure" true;
|
|
|
|
|
|
|
|
|
|
ehciSupport = mkEnableOption' "EHCI support" true;
|
|
|
|
|
ohciSupport = mkEnableOption' "OHCI support" true;
|
|
|
|
|
uhciSupport = mkEnableOption' "UHCI support" false;
|
|
|
|
|
xhciSupport = mkEnableOption' "XHCI support" true;
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
config = let cfg = config.hardware.genode.usb;
|
|
|
|
|
config = let
|
|
|
|
|
cfg = config.hardware.genode.usb;
|
|
|
|
|
|
|
|
|
|
usbEris = lib.attrsets.mapAttrs (_: lib.getEris "bin") {
|
|
|
|
|
inherit (pkgs.genodePackages) part_block usb_block_drv usb_drv;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
managerConfig = pkgs.writeText "usb_device_manager.dhall" ''
|
|
|
|
|
let Manager = ${pkgs.genodePackages.usb_device_manager.dhall}/package.dhall
|
|
|
|
|
|
|
|
|
|
in Manager.toChildAttributes
|
|
|
|
|
Manager::{
|
|
|
|
|
, part_block.binary = "${usbEris.part_block.cap}"
|
|
|
|
|
, usb_block.binary = "${usbEris.usb_block_drv.cap}"
|
|
|
|
|
, usb_driver =
|
|
|
|
|
{ binary = "${usbEris.usb_drv.cap}"
|
|
|
|
|
, bios_handoff = True
|
|
|
|
|
, ehci = True
|
|
|
|
|
, ohci = False
|
|
|
|
|
, uhci = False
|
|
|
|
|
, xhci = False
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
'';
|
|
|
|
|
in {
|
|
|
|
|
|
|
|
|
|
hardware.genode.usb.enable = cfg.storage.enable;
|
|
|
|
|
hardware.genode.usb.enable = lib.mkDefault cfg.storage.enable;
|
|
|
|
|
|
|
|
|
|
hardware.genode.platform.policies = lib.optional cfg.enable
|
|
|
|
|
(builtins.toFile ("usb.platform-policy.dhall") ''
|
|
|
|
@ -26,7 +56,7 @@ with lib;
|
|
|
|
|
|
|
|
|
|
in Genode.Init.Config.Policy::{
|
|
|
|
|
, service = "Platform"
|
|
|
|
|
, label = Genode.Init.LabelSelector.prefix "usb_drv"
|
|
|
|
|
, label = Genode.Init.LabelSelector.prefix "drivers -> usb"
|
|
|
|
|
, content =
|
|
|
|
|
[ Genode.Prelude.XML.leaf
|
|
|
|
|
{ name = "pci", attributes = toMap { class = "USB" } }
|
|
|
|
@ -34,91 +64,10 @@ with lib;
|
|
|
|
|
}
|
|
|
|
|
'');
|
|
|
|
|
|
|
|
|
|
genode.init.children.usb_drv = lib.mkIf cfg.enable {
|
|
|
|
|
binary = "${pkgs.genodePackages.usb_drv}/bin/usb_drv";
|
|
|
|
|
configFile = let toYesNo = b: if b then "yes" else "no";
|
|
|
|
|
in builtins.toFile "usb_drv.dhall" ''
|
|
|
|
|
let Genode = env:DHALL_GENODE
|
|
|
|
|
|
|
|
|
|
let XML = Genode.Prelude.XML
|
|
|
|
|
|
|
|
|
|
let Init = Genode.Init
|
|
|
|
|
|
|
|
|
|
in λ(binary : Text) →
|
|
|
|
|
Init.Child.flat
|
|
|
|
|
Init.Child.Attributes::{
|
|
|
|
|
, binary
|
|
|
|
|
, resources = Init.Resources::{ caps = 256, ram = Genode.units.MiB 12 }
|
|
|
|
|
, romReports = let local = "devices" in [ { local, route = local } ]
|
|
|
|
|
, routes = [ Init.ServiceRoute.parent "IO_MEM" ]
|
|
|
|
|
, config =
|
|
|
|
|
let storagePolicy =
|
|
|
|
|
Init.Config.Policy::{
|
|
|
|
|
, service = "Usb"
|
|
|
|
|
, label = Init.LabelSelector.prefix "usb_block_drv"
|
|
|
|
|
, attributes = toMap { class = "8" }
|
|
|
|
|
, diag = Some True
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
in Init.Config::{
|
|
|
|
|
, attributes = toMap
|
|
|
|
|
{ ehci = "${toYesNo cfg.ehciSupport}"
|
|
|
|
|
, ohci = "${toYesNo cfg.ohciSupport}"
|
|
|
|
|
, uhci = "${toYesNo cfg.uhciSupport}"
|
|
|
|
|
, xhci = "${toYesNo cfg.xhciSupport}"
|
|
|
|
|
}
|
|
|
|
|
, content =
|
|
|
|
|
[ XML.element
|
|
|
|
|
{ name = "raw"
|
|
|
|
|
, attributes = XML.emptyAttributes
|
|
|
|
|
, content =
|
|
|
|
|
[ XML.leaf
|
|
|
|
|
{ name = "report"
|
|
|
|
|
, attributes = toMap { devices = "yes" }
|
|
|
|
|
}
|
|
|
|
|
, Init.Config.Policy.toXML storagePolicy
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
, policies = [ storagePolicy ]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
genode.core.children.usb_block_drv =
|
|
|
|
|
mkIf config.hardware.genode.usb.storage.enable {
|
|
|
|
|
binary = pkgs.genodePackages.usb_block_drv;
|
|
|
|
|
configFile = builtins.toFile "usb_block_drv.dhall" ''
|
|
|
|
|
let Genode = env:DHALL_GENODE
|
|
|
|
|
|
|
|
|
|
let Init = Genode.Init
|
|
|
|
|
|
|
|
|
|
in λ(binary : Text) →
|
|
|
|
|
Init.Child.flat
|
|
|
|
|
Init.Child.Attributes::{
|
|
|
|
|
, binary
|
|
|
|
|
, resources = Init.Resources::{ caps = 256, ram = Genode.units.MiB 4 }
|
|
|
|
|
, config = Init.Config::{
|
|
|
|
|
, attributes = toMap { writeable = "yes" }
|
|
|
|
|
, policies =
|
|
|
|
|
[ Init.Config.Policy::{
|
|
|
|
|
, service = "Block"
|
|
|
|
|
, label = Init.LabelSelector.prefix "part_block"
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
virtualisation.qemu.options = lib.optional cfg.enable
|
|
|
|
|
(lib.optional (pkgs.stdenv.isi686 || pkgs.stdenv.isx86_64) "-usb"
|
|
|
|
|
++ lib.optional (pkgs.stdenv.isAarch32 || pkgs.stdenv.isAarch64)
|
|
|
|
|
"-device usb-ehci,id=usb0") ++ lib.optional cfg.storage.enable [
|
|
|
|
|
"-drive id=usbdisk,file=${config.system.build.bootDriveImage},if=none,readonly"
|
|
|
|
|
"-device usb-storage,drive=usbdisk"
|
|
|
|
|
];
|
|
|
|
|
"-device usb-ehci,id=usb0");
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|