nixos: use usb_block_drv for USB storage
This commit is contained in:
parent
64d8f03cc1
commit
e899a3642e
|
@ -3,24 +3,27 @@
|
||||||
with lib;
|
with lib;
|
||||||
|
|
||||||
{
|
{
|
||||||
options = {
|
options.hardware.genode.usb = {
|
||||||
|
|
||||||
hardware.usb.genode.enable = lib.mkEnableOption "USB driver";
|
enable = lib.mkEnableOption "USB driver";
|
||||||
|
storage.enable = lib.mkEnableOption "USB mass storage driver";
|
||||||
|
|
||||||
hardware.usb.genode.storage.enable =
|
ehciSupport = lib.mkEnableOption "EHCI support" // { default = true; };
|
||||||
lib.mkEnableOption "USB mass storage driver";
|
ohciSupport = lib.mkEnableOption "OHCI support" // { default = true; };
|
||||||
|
uhciSupport = lib.mkEnableOption "UHCI support" // { default = false; };
|
||||||
|
xhciSupport = lib.mkEnableOption "XHCI support" // { default = true; };
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
config = {
|
config = let cfg = config.hardware.genode.usb;
|
||||||
|
in {
|
||||||
|
|
||||||
hardware.usb.genode.storage.enable = config.genode.boot.storeBackend
|
hardware.genode.usb.storage.enable = config.genode.boot.storeBackend
|
||||||
== "usb";
|
== "usb";
|
||||||
|
|
||||||
hardware.usb.genode.enable = config.hardware.usb.genode.storage.enable;
|
hardware.genode.usb.enable = cfg.storage.enable;
|
||||||
|
|
||||||
hardware.genode.platform.policies =
|
hardware.genode.platform.policies = lib.optional cfg.enable
|
||||||
lib.optional config.hardware.usb.genode.enable
|
|
||||||
(builtins.toFile ("usb.platform-policy.dhall") ''
|
(builtins.toFile ("usb.platform-policy.dhall") ''
|
||||||
let Genode = env:DHALL_GENODE
|
let Genode = env:DHALL_GENODE
|
||||||
|
|
||||||
|
@ -34,49 +37,84 @@ with lib;
|
||||||
}
|
}
|
||||||
'');
|
'');
|
||||||
|
|
||||||
genode.core.basePackages = lib.optional config.hardware.usb.genode.enable
|
genode.init.children.usb_drv = lib.mkIf cfg.enable {
|
||||||
pkgs.genodePackages.usb_drv;
|
inputs = [ pkgs.genodePackages.usb_drv ];
|
||||||
|
configFile = let toYesNo = b: if b then "yes" else "no";
|
||||||
genode.init.children.usb_drv = lib.mkIf config.hardware.usb.genode.enable {
|
in builtins.toFile "usb_drv.dhall" ''
|
||||||
coreROMs = [ "usb_drv" ];
|
|
||||||
configFile = builtins.toFile "usb_drv.dhall" ''
|
|
||||||
let Genode = env:DHALL_GENODE
|
let Genode = env:DHALL_GENODE
|
||||||
|
|
||||||
let XML = Genode.Prelude.XML
|
let XML = Genode.Prelude.XML
|
||||||
|
|
||||||
let Init = Genode.Init
|
let Init = Genode.Init
|
||||||
|
|
||||||
let storageEnable = ${
|
|
||||||
if config.hardware.usb.genode.storage.enable then "True" else "False"
|
|
||||||
}
|
|
||||||
|
|
||||||
in Init.Child.flat
|
in Init.Child.flat
|
||||||
Init.Child.Attributes::{
|
Init.Child.Attributes::{
|
||||||
, binary = "usb_drv"
|
, binary = "usb_drv"
|
||||||
, provides = [ "Block", "Usb" ]
|
|
||||||
, resources = Init.Resources::{ caps = 256, ram = Genode.units.MiB 12 }
|
, resources = Init.Resources::{ caps = 256, ram = Genode.units.MiB 12 }
|
||||||
|
, romReports = let local = "devices" in [ { local, route = local } ]
|
||||||
, routes = [ Init.ServiceRoute.parent "IO_MEM" ]
|
, routes = [ Init.ServiceRoute.parent "IO_MEM" ]
|
||||||
, config = Init.Config::{
|
, config =
|
||||||
, attributes = toMap { uhci = "yes", ehci = "yes", xhci = "yes" }
|
let storagePolicy =
|
||||||
, content =
|
Init.Config.Policy::{
|
||||||
if storageEnable
|
, service = "Usb"
|
||||||
then [ XML.leaf
|
, label = Init.LabelSelector.prefix "usb_block_drv"
|
||||||
{ name = "storage", attributes = XML.emptyAttributes }
|
, attributes = toMap { class = "8" }
|
||||||
]
|
, diag = Some True
|
||||||
else [] : List XML.Type
|
}
|
||||||
, policies =
|
|
||||||
if storageEnable
|
in Init.Config::{
|
||||||
then [ Init.Config.Policy::{
|
, attributes = toMap
|
||||||
, service = "Block"
|
{ ehci = "${toYesNo cfg.ehciSupport}"
|
||||||
, label = Init.LabelSelector.prefix "store_fs"
|
, 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
|
||||||
|
]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
else [] : List Init.Config.Policy.Type
|
, policies = [ storagePolicy ]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
|
genode.core.children.usb_block_drv =
|
||||||
|
mkIf config.hardware.genode.usb.storage.enable {
|
||||||
|
inputs = [ pkgs.genodePackages.usb_block_drv ];
|
||||||
|
configFile = builtins.toFile "usb_block_drv.dhall" ''
|
||||||
|
let Genode = env:DHALL_GENODE
|
||||||
|
|
||||||
|
let XML = Genode.Prelude.XML
|
||||||
|
|
||||||
|
let Init = Genode.Init
|
||||||
|
|
||||||
|
in Init.Child.flat
|
||||||
|
Init.Child.Attributes::{
|
||||||
|
, binary = "usb_block_drv"
|
||||||
|
, 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"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue