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.bbclass191
1 files changed, 191 insertions, 0 deletions
diff --git a/meta/classes/boot-directdisk.bbclass b/meta/classes/boot-directdisk.bbclass
new file mode 100644
index 0000000000..09da032049
--- /dev/null
+++ b/meta/classes/boot-directdisk.bbclass
@@ -0,0 +1,191 @@
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 = "${@bb.utils.contains("MACHINE_FEATURES", "efi", "1", "0", d)}"
35EFI_PROVIDER ?= "grub-efi"
36EFI_CLASS = "${@bb.utils.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 = bb.utils.contains("MACHINE_FEATURES", "pcbios", "1", "0", d)
43 if pcbios == "0":
44 pcbios = bb.utils.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 = '${@bb.utils.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 # initrd is made of concatenation of multiple filesystem images
75 if [ -n "${INITRD}" ]; then
76 rm -f $dest/initrd
77 for fs in ${INITRD}
78 do
79 if [ -s "${fs}" ]; then
80 cat ${fs} >> $dest/initrd
81 else
82 bbfatal "${fs} is invalid. initrd image creation failed."
83 fi
84 done
85 chmod 0644 $dest/initrd
86 fi
87}
88
89build_boot_dd() {
90 HDDDIR="${S}/hdd/boot"
91 HDDIMG="${S}/hdd.image"
92 IMAGE=${DEPLOY_DIR_IMAGE}/${IMAGE_NAME}.hdddirect
93
94 boot_direct_populate $HDDDIR
95
96 if [ "${PCBIOS}" = "1" ]; then
97 syslinux_hddimg_populate $HDDDIR
98 fi
99 if [ "${EFI}" = "1" ]; then
100 efi_hddimg_populate $HDDDIR
101 fi
102
103 if [ "${IS_VMDK}" = "true" ]; then
104 if [ "x${AUTO_SYSLINUXMENU}" = "x1" ] ; then
105 install -m 0644 ${STAGING_DIR}/${MACHINE}/usr/share/syslinux/vesamenu.c32 $HDDDIR/${SYSLINUXDIR}/
106 if [ "x${SYSLINUX_SPLASH}" != "x" ] ; then
107 install -m 0644 ${SYSLINUX_SPLASH} $HDDDIR/${SYSLINUXDIR}/splash.lss
108 fi
109 fi
110 fi
111
112 BLOCKS=`du -bks $HDDDIR | cut -f 1`
113 BLOCKS=`expr $BLOCKS + ${BOOTDD_EXTRA_SPACE}`
114
115 # Ensure total sectors is an integral number of sectors per
116 # track or mcopy will complain. Sectors are 512 bytes, and we
117 # generate images with 32 sectors per track. This calculation is
118 # done in blocks, thus the mod by 16 instead of 32.
119 BLOCKS=$(expr $BLOCKS + $(expr 16 - $(expr $BLOCKS % 16)))
120
121 mkdosfs -n ${BOOTDD_VOLUME_ID} -S 512 -C $HDDIMG $BLOCKS
122 mcopy -i $HDDIMG -s $HDDDIR/* ::/
123
124 if [ "${PCBIOS}" = "1" ]; then
125 syslinux_hdddirect_install $HDDIMG
126 fi
127 chmod 644 $HDDIMG
128
129 ROOTFSBLOCKS=`du -Lbks ${ROOTFS} | cut -f 1`
130 TOTALSIZE=`expr $BLOCKS + $ROOTFSBLOCKS`
131 END1=`expr $BLOCKS \* 1024`
132 END2=`expr $END1 + 512`
133 END3=`expr \( $ROOTFSBLOCKS \* 1024 \) + $END1`
134
135 echo $ROOTFSBLOCKS $TOTALSIZE $END1 $END2 $END3
136 rm -rf $IMAGE
137 dd if=/dev/zero of=$IMAGE bs=1024 seek=$TOTALSIZE count=1
138
139 parted $IMAGE mklabel msdos
140 parted $IMAGE mkpart primary fat16 0 ${END1}B
141 parted $IMAGE unit B mkpart primary ext2 ${END2}B ${END3}B
142 parted $IMAGE set 1 boot on
143
144 parted $IMAGE print
145
146 awk "BEGIN { printf \"$(echo ${DISK_SIGNATURE} | fold -w 2 | tac | paste -sd '' | sed 's/\(..\)/\\x&/g')\" }" | \
147 dd of=$IMAGE bs=1 seek=440 conv=notrunc
148
149 OFFSET=`expr $END2 / 512`
150 if [ "${PCBIOS}" = "1" ]; then
151 dd if=${STAGING_DATADIR}/syslinux/mbr.bin of=$IMAGE conv=notrunc
152 fi
153
154 dd if=$HDDIMG of=$IMAGE conv=notrunc seek=1 bs=512
155 dd if=${ROOTFS} of=$IMAGE conv=notrunc seek=$OFFSET bs=512
156
157 cd ${DEPLOY_DIR_IMAGE}
158 rm -f ${DEPLOY_DIR_IMAGE}/${IMAGE_LINK_NAME}.hdddirect
159 ln -s ${IMAGE_NAME}.hdddirect ${DEPLOY_DIR_IMAGE}/${IMAGE_LINK_NAME}.hdddirect
160}
161
162python do_bootdirectdisk() {
163 validate_disk_signature(d)
164 if d.getVar("PCBIOS", True) == "1":
165 bb.build.exec_func('build_syslinux_cfg', d)
166 if d.getVar("EFI", True) == "1":
167 bb.build.exec_func('build_efi_cfg', d)
168 bb.build.exec_func('build_boot_dd', d)
169}
170
171def generate_disk_signature():
172 import uuid
173
174 signature = str(uuid.uuid4())[:8]
175
176 if signature != '00000000':
177 return signature
178 else:
179 return 'ffffffff'
180
181def validate_disk_signature(d):
182 import re
183
184 disk_signature = d.getVar("DISK_SIGNATURE", True)
185
186 if not re.match(r'^[0-9a-fA-F]{8}$', disk_signature):
187 bb.fatal("DISK_SIGNATURE '%s' must be an 8 digit hex string" % disk_signature)
188
189DISK_SIGNATURE_GENERATED := "${@generate_disk_signature()}"
190
191addtask bootdirectdisk before do_build