summaryrefslogtreecommitdiff
path: root/src/Propellor/Property/Uboot.hs
diff options
context:
space:
mode:
authorSean Whitton2017-11-19 12:04:26 -0700
committerSean Whitton2017-11-19 12:04:26 -0700
commit05e5308ee7cef99b24b4f9d9755e5488f8d92a39 (patch)
tree256b8f20bddf0f0701a3247228f9c2dd77be6e64 /src/Propellor/Property/Uboot.hs
parent38d039310e4db6ffaf5c8ca51c339421e6865eff (diff)
parent12beba0367d14f9c52adf72dd36e9cf5a8e35761 (diff)
Merge branch 'master' of https://git.joeyh.name/git/propellor into sbuild-overhaul
Diffstat (limited to 'src/Propellor/Property/Uboot.hs')
-rw-r--r--src/Propellor/Property/Uboot.hs36
1 files changed, 36 insertions, 0 deletions
diff --git a/src/Propellor/Property/Uboot.hs b/src/Propellor/Property/Uboot.hs
new file mode 100644
index 00000000..562d2441
--- /dev/null
+++ b/src/Propellor/Property/Uboot.hs
@@ -0,0 +1,36 @@
+module Propellor.Property.Uboot where
+
+import Propellor.Base
+import Propellor.Types.Info
+import Propellor.Types.Bootloader
+import Propellor.Property.Chroot
+import Propellor.Property.Mount
+import qualified Propellor.Property.Apt as Apt
+
+-- | Name of a board.
+type BoardName = String
+
+-- | Installs u-boot for Allwinner/sunxi platforms.
+--
+-- This includes writing it to the boot sector.
+sunxi :: BoardName -> Property (HasInfo + DebianLike)
+sunxi boardname = setInfoProperty (check (not <$> inChroot) go) info
+ `requires` Apt.installed ["u-boot", "u-boot-sunxi"]
+ where
+ go :: Property Linux
+ go = property' "u-boot installed" $ \w -> do
+ v <- liftIO $ getMountContaining "/boot"
+ case v of
+ Nothing -> error "unable to determine boot device"
+ Just dev -> ensureProperty w (dd dev "/")
+ dd :: FilePath -> FilePath -> Property Linux
+ dd dev prefix = tightenTargets $ cmdProperty "dd"
+ [ "conv=fsync,notrunc"
+ , "if=" ++ prefix ++ "/usr/lib/u-boot/"
+ ++ boardname ++ "/u-boot-sunxi-with-spl.bin"
+ , "of=" ++ dev
+ , "bs=1024"
+ , "seek=8"
+ ]
+ `assume` NoChange
+ info = toInfo [UbootInstalled dd]