summaryrefslogtreecommitdiff
path: root/src/Propellor/Property/Uboot.hs
blob: 098362e19119e3aed39d2085da1658175df20a6d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
module Propellor.Property.Uboot where

import Propellor.Base
import Propellor.Types.Info
import Propellor.Types.Bootloader
import Propellor.Types.Container
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 <$> hasContainerCapability FilesystemContained) 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]