summaryrefslogtreecommitdiffstats
path: root/meta/classes/boot-directdisk.bbclass
diff options
context:
space:
mode:
Diffstat (limited to 'meta/classes/boot-directdisk.bbclass')
-rw-r--r--meta/classes/boot-directdisk.bbclass182
1 files changed, 182 insertions, 0 deletions
diff --git a/meta/classes/boot-directdisk.bbclass b/meta/classes/boot-directdisk.bbclass
new file mode 100644
index 0000000..88e5c52
--- /dev/null
+++ b/meta/classes/boot-directdisk.bbclass
@@ -0,0 +1,182 @@
1# boot-directdisk.bbclass
2# (loosly based off bootimg.bbclass Copyright (C) 2004, Advanced Micro Devices, Inc.)
3#
4# Create an image which can be placed directly onto a harddisk using dd and then
5# booted.
6#
7# This uses syslinux. extlinux would have been nice but required the ext2/3
8# partition to be mounted. grub requires to run itself as part of the install
9# process.
10#
11# The end result is a 512 boot sector populated with an MBR and partition table
12# followed by an msdos fat16 partition containing syslinux and a linux kernel
13# completed by the ext2/3 rootfs.
14#
15# We have to push the msdos parition table size > 16MB so fat 16 is used as parted
16# won't touch fat12 partitions.
17
18# External variables needed
19
20# ${ROOTFS} - the rootfs image to incorporate
21
22do_bootdirectdisk[depends] += "dosfstools-native:do_populate_sysroot \
23 syslinux:do_populate_sysroot \
24 syslinux-native:do_populate_sysroot \
25 parted-native:do_populate_sysroot \
26 mtools-native:do_populate_sysroot "
27
28PACKAGES = " "
29EXCLUDE_FROM_WORLD = "1"
30
31BOOTDD_VOLUME_ID ?= "boot"
32BOOTDD_EXTRA_SPACE ?= "16384"
33
34EFI = "${@base_contains("MACHINE_FEATURES", "efi", "1", "0", d)}"
35EFI_PROVIDER ?= "grub-efi"
36EFI_CLASS = "${@base_contains("MACHINE_FEATURES", "efi", "${EFI_PROVIDER}", "", d)}"
37
38# Include legacy boot if MACHINE_FEATURES includes "pcbios" or if it does not
39# contain "efi". This way legacy is supported by default if neither is
40# specified, maintaining the original behavior.
41def pcbios(d):
42 pcbios = base_contains("MACHINE_FEATURES", "pcbios", "1", "0", d)
43 if pcbios == "0":
44 pcbios = base_contains("MACHINE_FEATURES", "efi", "0", "1", d)
45 return pcbios
46
47def pcbios_class(d):
48 if d.getVar("PCBIOS", True) == "1":
49 return "syslinux"
50 return ""
51
52PCBIOS = "${@pcbios(d)}"
53PCBIOS_CLASS = "${@pcbios_class(d)}"
54
55inherit ${PCBIOS_CLASS}
56inherit ${EFI_CLASS}
57
58# Get the build_syslinux_cfg() function from the syslinux class
59
60AUTO_SYSLINUXCFG = "1"
61DISK_SIGNATURE ?= "${DISK_SIGNATURE_GENERATED}"
62SYSLINUX_ROOT ?= "root=/dev/sda2"
63SYSLINUX_TIMEOUT ?= "10"
64
65IS_VMDK = '${@base_contains("IMAGE_FSTYPES", "vmdk", "true", "false", d)}'
66
67boot_direct_populate() {
68 dest=$1
69 install -d $dest
70
71 # Install bzImage, initrd, and rootfs.img in DEST for all loaders to use.
72 install -m 0644 ${STAGING_KERNEL_DIR}/bzImage $dest/vmlinuz
73
74 if [ -n "${INITRD}" ] && [ -s "${INITRD}" ]; then
75 install -m 0644 ${INITRD} $dest/initrd
76 fi
77
78}
79
80build_boot_dd() {
81 HDDDIR="${S}/hdd/boot"
82 HDDIMG="${S}/hdd.image"
83 IMAGE=${DEPLOY_DIR_IMAGE}/${IMAGE_NAME}.hdddirect
84
85 boot_direct_populate $HDDDIR
86
87 if [ "${PCBIOS}" = "1" ]; then
88 syslinux_hddimg_populate $HDDDIR
89 fi
90 if [ "${EFI}" = "1" ]; then
91 efi_hddimg_populate $HDDDIR
92 fi
93
94 if [ "${IS_VMDK}" = "true" ]; then
95 if [ "x${AUTO_SYSLINUXMENU}" = "x1" ] ; then
96 install -m 0644 ${STAGING_DIR}/${MACHINE}/usr/share/syslinux/vesamenu.c32 ${HDDDIR}${SYSLINUXDIR}/vesamenu.c32
97 if [ "x${SYSLINUX_SPLASH}" != "x" ] ; then
98 install -m 0644 ${SYSLINUX_SPLASH} ${HDDDIR}${SYSLINUXDIR}/splash.lss
99 fi
100 fi
101 fi
102
103 BLOCKS=`du -bks $HDDDIR | cut -f 1`
104 BLOCKS=`expr $BLOCKS + ${BOOTDD_EXTRA_SPACE}`
105
106 # Ensure total sectors is an integral number of sectors per
107 # track or mcopy will complain. Sectors are 512 bytes, and we
108 # generate images with 32 sectors per track. This calculation is
109 # done in blocks, thus the mod by 16 instead of 32.
110 BLOCKS=$(expr $BLOCKS + $(expr 16 - $(expr $BLOCKS % 16)))
111
112 mkdosfs -n ${BOOTDD_VOLUME_ID} -S 512 -C $HDDIMG $BLOCKS
113 mcopy -i $HDDIMG -s $HDDDIR/* ::/
114
115 if [ "${PCBIOS}" = "1" ]; then
116 syslinux_hdddirect_install $HDDIMG
117 fi
118 chmod 644 $HDDIMG
119
120 ROOTFSBLOCKS=`du -Lbks ${ROOTFS} | cut -f 1`
121 TOTALSIZE=`expr $BLOCKS + $ROOTFSBLOCKS`
122 END1=`expr $BLOCKS \* 1024`
123 END2=`expr $END1 + 512`
124 END3=`expr \( $ROOTFSBLOCKS \* 1024 \) + $END1`
125
126 echo $ROOTFSBLOCKS $TOTALSIZE $END1 $END2 $END3
127 rm -rf $IMAGE
128 dd if=/dev/zero of=$IMAGE bs=1024 seek=$TOTALSIZE count=1
129
130 parted $IMAGE mklabel msdos
131 parted $IMAGE mkpart primary fat16 0 ${END1}B
132 parted $IMAGE unit B mkpart primary ext2 ${END2}B ${END3}B
133 parted $IMAGE set 1 boot on
134
135 parted $IMAGE print
136
137 awk "BEGIN { printf \"$(echo ${DISK_SIGNATURE} | fold -w 2 | tac | paste -sd '' | sed 's/\(..\)/\\x&/g')\" }" | \
138 dd of=$IMAGE bs=1 seek=440 conv=notrunc
139
140 OFFSET=`expr $END2 / 512`
141 if [ "${PCBIOS}" = "1" ]; then
142 dd if=${STAGING_DATADIR}/syslinux/mbr.bin of=$IMAGE conv=notrunc
143 fi
144
145 dd if=$HDDIMG of=$IMAGE conv=notrunc seek=1 bs=512
146 dd if=${ROOTFS} of=$IMAGE conv=notrunc seek=$OFFSET bs=512
147
148 cd ${DEPLOY_DIR_IMAGE}
149 rm -f ${DEPLOY_DIR_IMAGE}/${IMAGE_LINK_NAME}.hdddirect
150 ln -s ${IMAGE_NAME}.hdddirect ${DEPLOY_DIR_IMAGE}/${IMAGE_LINK_NAME}.hdddirect
151}
152
153python do_bootdirectdisk() {
154 validate_disk_signature(d)
155 if d.getVar("PCBIOS", True) == "1":
156 bb.build.exec_func('build_syslinux_cfg', d)
157 if d.getVar("EFI", True) == "1":
158 bb.build.exec_func('build_efi_cfg', d)
159 bb.build.exec_func('build_boot_dd', d)
160}
161
162def generate_disk_signature():
163 import uuid
164
165 signature = str(uuid.uuid4())[:8]
166
167 if signature != '00000000':
168 return signature
169 else:
170 return 'ffffffff'
171
172def validate_disk_signature(d):
173 import re
174
175 disk_signature = d.getVar("DISK_SIGNATURE", True)
176
177 if not re.match(r'^[0-9a-fA-F]{8}$', disk_signature):
178 bb.fatal("DISK_SIGNATURE '%s' must be an 8 digit hex string" % disk_signature)
179
180DISK_SIGNATURE_GENERATED := "${@generate_disk_signature()}"
181
182addtask bootdirectdisk before do_build