summaryrefslogtreecommitdiff
path: root/src/Propellor/Property/DiskImage.hs
diff options
context:
space:
mode:
authorJoey Hess2017-11-16 17:54:47 -0400
committerJoey Hess2017-11-16 17:54:47 -0400
commitcff178de9c0d229574ab884fcca08a41f434e119 (patch)
tree6208a18ba662ea907eb51db6196ff54c0577b543 /src/Propellor/Property/DiskImage.hs
parent19feb8451b75ae669b45add9e9d9851a542fd981 (diff)
Uboot: New module.
Installing u-boot to the boot sector is not needed by some boards (my CubieTruck boots without it), but may be by others. Tricky part was making u-boot be written to a disk image when building one. This commit was sponsored by Jake Vosloo on Patreon.
Diffstat (limited to 'src/Propellor/Property/DiskImage.hs')
-rw-r--r--src/Propellor/Property/DiskImage.hs33
1 files changed, 18 insertions, 15 deletions
diff --git a/src/Propellor/Property/DiskImage.hs b/src/Propellor/Property/DiskImage.hs
index 7493dd21..fe2e60ac 100644
--- a/src/Propellor/Property/DiskImage.hs
+++ b/src/Propellor/Property/DiskImage.hs
@@ -191,10 +191,14 @@ imageBuilt' rebuild img mkchroot tabletype partspec =
-- Pick boot loader finalization based on which bootloader is
-- installed.
final = case fromInfo (containerInfo chroot) of
- [GrubInstalled] -> grubBooted
- [FlashKernelInstalled] -> \_ _ -> doNothing
[] -> unbootable "no bootloader is installed"
- _ -> unbootable "multiple bootloaders are installed; don't know which to use"
+ l -> case filter ignorablefinal l of
+ [] -> \_ _ _ -> doNothing
+ [GrubInstalled] -> grubFinalized
+ [UbootInstalled p] -> ubootFinalized p
+ _ -> unbootable "multiple bootloaders are installed; don't know which to use"
+ ignorablefinal FlashKernelInstalled = True
+ ignorablefinal _ = False
-- | This property is automatically added to the chroot when building a
-- disk image. It cleans any caches of information that can be omitted;
@@ -229,7 +233,7 @@ imageBuiltFrom img chrootdir tabletype final partspec = mkimg <!> rmimg
mkimg' mnts mntopts parttable devs =
partitionsPopulated chrootdir mnts mntopts devs
`before`
- imageFinalized final mnts mntopts devs parttable
+ imageFinalized final dest mnts mntopts devs parttable
rmimg = undoRevertableProperty (buildDiskImage img)
`before` undoRevertableProperty (imageExists' dest dummyparttable)
dummyparttable = PartTable tabletype []
@@ -352,10 +356,10 @@ imageExists' dest@(RawDiskImage img) parttable = (setup <!> cleanup) `describe`
--
-- It's ok if the property leaves additional things mounted
-- in the partition tree.
-type Finalization = (FilePath -> [LoopDev] -> Property Linux)
+type Finalization = (RawDiskImage -> FilePath -> [LoopDev] -> Property Linux)
-imageFinalized :: Finalization -> [Maybe MountPoint] -> [MountOpts] -> [LoopDev] -> PartTable -> Property Linux
-imageFinalized final mnts mntopts devs (PartTable _ parts) =
+imageFinalized :: Finalization -> RawDiskImage -> [Maybe MountPoint] -> [MountOpts] -> [LoopDev] -> PartTable -> Property Linux
+imageFinalized final img mnts mntopts devs (PartTable _ parts) =
property' "disk image finalized" $ \w ->
withTmpDir "mnt" $ \top ->
go w top `finally` liftIO (unmountall top)
@@ -364,7 +368,7 @@ imageFinalized final mnts mntopts devs (PartTable _ parts) =
liftIO $ mountall top
liftIO $ writefstab top
liftIO $ allowservices top
- ensureProperty w $ final top devs
+ ensureProperty w $ final img top devs
-- Ordered lexographically by mount point, so / comes before /usr
-- comes before /usr/local
@@ -400,18 +404,14 @@ imageFinalized final mnts mntopts devs (PartTable _ parts) =
allowservices top = nukeFile (top ++ "/usr/sbin/policy-rc.d")
unbootable :: String -> Finalization
-unbootable msg = \_ _ -> property desc $ do
+unbootable msg = \_ _ _ -> property desc $ do
warningMessage (desc ++ ": " ++ msg)
return FailedChange
where
desc = "image is not bootable"
--- | Makes grub be the boot loader of the disk image.
---
--- This does not install the grub package. You will need to add
--- the `Grub.installed` property to the chroot.
-grubBooted :: Finalization
-grubBooted mnt loopdevs = Grub.bootsMounted mnt wholediskloopdev
+grubFinalized :: Finalization
+grubFinalized _img mnt loopdevs = Grub.bootsMounted mnt wholediskloopdev
`describe` "disk image boots using grub"
where
-- It doesn't matter which loopdev we use; all
@@ -421,6 +421,9 @@ grubBooted mnt loopdevs = Grub.bootsMounted mnt wholediskloopdev
(l:_) -> wholeDiskLoopDev l
[] -> error "No loop devs provided!"
+ubootFinalized :: (FilePath -> FilePath -> Property Linux) -> Finalization
+ubootFinalized p (RawDiskImage img) mnt _loopdevs = p img mnt
+
isChild :: FilePath -> Maybe MountPoint -> Bool
isChild mntpt (Just d)
| d `equalFilePath` mntpt = False