summaryrefslogtreecommitdiff
path: root/regress/usr.sbin/installboot/Makefile
blob: 83c477a7784e81ab79fcea9fc69a8cdb9b9f6ce1 (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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
#	$OpenBSD: Makefile,v 1.27 2022/09/12 13:10:04 kn Exp $

INSTALLBOOT ?=		/usr/sbin/installboot
DRY_RUN =		${INSTALLBOOT} -n
REAL_RUN =		${INSTALLBOOT}

# see distrib/${MACHINE}/ramdisk/install.md for FORMAT_DISK values
# default to root on softraid(4) on all architectures that have
# bootstrap + kernel + installboot(8) support for it
.if   ${MACHINE} == "amd64" ||	\
      ${MACHINE} == "i386"	# assume BIOS/MBR
FORMAT_DISK =		fdisk -iy
STAGENAMES =		biosboot boot
USE_SOFTRAID ?=		Yes
.elif ${MACHINE} == "arm64"
FORMAT_DISK =		fdisk -iy -b '32768@32768:C'
STAGENAMES =		BOOTAA64.EFI
USE_SOFTRAID ?=		Yes
.elif ${MACHINE} == "armv7"
FORMAT_DISK =		fdisk -iy -b '32768@32768:C'
STAGENAMES =		BOOTARM.EFI
USE_SOFTRAID ?=		No
.elif ${MACHINE} == "macppc"	# assume MBR
FORMAT_DISK =		fdisk -iy -b '2048@1:06'
STAGENAMES =		ofwboot
USE_SOFTRAID ?=		No
.elif ${MACHINE} == "octeon"
FORMAT_DISK =		fdisk -iy -b '65536@64:C'
STAGENAMES =		boot
USE_SOFTRAID ?=		No
.elif ${MACHINE} == "powerpc64"
FORMAT_DISK =		fdisk -iy -b '32768@32768:C'
STAGENAMES =		boot
USE_SOFTRAID ?=		No
.elif ${MACHINE} == "riscv64"
FORMAT_DISK =		fdisk -iy -b '32768@32768:C'
STAGENAMES =		BOOTRISCV64.EFI
USE_SOFTRAID ?=		No
.elif ${MACHINE} == "sparc64"
FORMAT_DISK =		true	# NOOP
STAGENAMES =		bootblk ofwboot
USE_SOFTRAID ?=		Yes
.endif
# missing: alpha, hppa, landisk, loongson, luna88k

STAGEDIR =		/usr/mdec
STAGEFILES =		${STAGENAMES:=${STAGEDIR}/%}

.if ${USE_SOFTRAID:L} == "yes"
# install on multi-chunk RAID 1C with keydisk so installboot(8) must
# - iterate over chunks
# - ignore the keydisk/not install to it
NDISKS ?=		1 2
KEYDISKFILE =		keydisk.img
KEYDEVFILE =		keydev.txt
.else
NDISKS =		1
.endif
DISKFILES =		${NDISKS:=disk%.img}
DISKDEVFILES =		${NDISKS:=diskdev%.txt}
ROOTDEVFILE =		rootdev.txt
MOUNTPOINT =		mnt


REGRESS_SETUP_ONCE =	copy-bootstrap-to-root

create-disks:
.for n in ${NDISKS}
	dd if=/dev/zero  of=disk${n}.img bs=1m count=0 seek=128 status=none
	${SUDO} vnconfig -- disk${n}.img 1>diskdev${n}.txt
.endfor
.if ${USE_SOFTRAID:L} == "yes"
	dd if=/dev/zero  of=${KEYDISKFILE} bs=1m count=0 seek=2 status=none
	${SUDO} vnconfig -- ${KEYDISKFILE} 1>${KEYDEVFILE}
.endif

format-disks: create-disks
.for devfile in ${DISKDEVFILES}
	${SUDO} ${FORMAT_DISK} -- "$$(<${devfile})" 1>/dev/null
.  if ${USE_SOFTRAID:L} == "yes"
	echo 'RAID 1M-* 100%' | \
		${SUDO} disklabel -wAT/dev/stdin -- "$$(<${devfile})" 1>/dev/null
.  endif
.endfor
.if ${USE_SOFTRAID:L} == "yes"
	echo 'RAID 1M' | \
		${SUDO} disklabel -wAT/dev/stdin -- "$$(<${KEYDEVFILE})" 1>/dev/null
.endif

create-root: format-disks
.if ${USE_SOFTRAID:L} == "yes"
	${SUDO} bioctl -l"$$(sed -- s/$$/a/ ${DISKDEVFILES} | paste -sd, -- -)" \
	    -c1C -k"$$(<${KEYDEVFILE})"a -- softraid0 | \
		awk -- '{ print $$NF }' 1>${ROOTDEVFILE}
.else
	ln -s -- ${DISKDEVFILES} ${ROOTDEVFILE}
.endif

format-root: create-root
.if ${USE_SOFTRAID:L} == "yes"
	${SUDO} ${FORMAT_DISK} -- "$$(<${ROOTDEVFILE})" 1>/dev/null
.endif
	${SUDO} disklabel -Aw -- "$$(<${ROOTDEVFILE})"
	${SUDO} newfs -q -- "$$(<${ROOTDEVFILE})"a 1>/dev/null

mount-root: format-root
	mkdir -- ${MOUNTPOINT}
	${SUDO} mount -- /dev/"$$(<${ROOTDEVFILE})"a ${MOUNTPOINT}

copy-bootstrap-to-root: mount-root
	${SUDO} mkdir -- ${MOUNTPOINT}/usr
	${SUDO} cp -r -- ${STAGEDIR} ${MOUNTPOINT}/usr/


# must be first as some targets expect a working filesystem
REGRESS_TARGETS = prepare

prepare:
	${SUDO} ${REAL_RUN} -p -- "$$(<${ROOTDEVFILE})"
.if ${USE_SOFTRAID:L} == "yes"
	# XXX -p is not yet softraid(4) aware, need to prepare chunks manually
.  for devfile in ${DISKDEVFILES}
	${SUDO} ${REAL_RUN} -p -- "$$(<${devfile})"
.  endfor
.endif

REGRESS_TARGETS +=	dry-prepare \
			dry-default \
			dry-root \
			root \
			root-stages

dry-prepare:
	${SUDO} ${DRY_RUN} -p -- "$$(<${ROOTDEVFILE})"
dry-default:
	${SUDO} ${DRY_RUN} -- "$$(<${ROOTDEVFILE})"
dry-root:
	${SUDO} ${DRY_RUN} -r/ -- "$$(<${ROOTDEVFILE})"

root:
	${SUDO} ${REAL_RUN} -r ${MOUNTPOINT} "$$(<${ROOTDEVFILE})"
root-stages:
	${SUDO} ${REAL_RUN} -- "$$(<${ROOTDEVFILE})" ${STAGEFILES}


REGRESS_EXPECTED_FAILURES =	dry-prepare-root \
				dry-prepare-stages \
				dry-nodisk-stages \
				dry-toofew \
				dry-toomany
REGRESS_TARGETS +=		${REGRESS_EXPECTED_FAILURES}

dry-prepare-root:
	${DRY_RUN} -p -r/ -- "$$(<${ROOTDEVFILE})" 2>/dev/null
dry-prepare-stages:
	${DRY_RUN} -p -- "$$(<${ROOTDEVFILE})" ${STAGEFILES} 2>/dev/null

dry-nodisk-stages:
	${SUDO} ${DRY_RUN} -- ${STAGEFILES} 2>/dev/null

dry-toofew:
	${DRY_RUN} -- 2>/dev/null
dry-toomany:
	${DRY_RUN} -- disk stage1 stage2 too many 2>/dev/null


CLEANFILES =		${DISKFILES} ${DISKDEVFILES} ${ROOTDEVFILE}
.if ${USE_SOFTRAID:L} == "yes"
CLEANFILES +=		${KEYDISKFILE} ${KEYDEVFILE}
.endif
REGRESS_CLEANUP =	cleanup

# allow failure to always cleanup as much as possible
.IGNORE: cleanup
cleanup:
	${SUDO} umount -- ${MOUNTPOINT} 2>/dev/null
	rmdir -- ${MOUNTPOINT} 2>/dev/null
.if ${USE_SOFTRAID:L} == "yes"
	${SUDO} bioctl -d -- "$$(<${ROOTDEVFILE})" 2>/dev/null
	${SUDO} vnconfig -u -- "$$(<${KEYDEVFILE})" 2>/dev/null
.endif
.for devfile in ${DISKDEVFILES}
	${SUDO} vnconfig -u -- "$$(<${devfile})" 2>/dev/null
.endfor

.include <bsd.regress.mk>