Merge branch 'org.openembedded.dev' of ssh+git://git@git.openembedded.net/openembedde...
[openembedded.git] / classes / bootimg.bbclass
1 # bootimg.oeclass
2 # Copyright (C) 2004, Advanced Micro Devices, Inc.  All Rights Reserved
3 # Released under the MIT license (see packages/COPYING)
4
5 # This creates a bootable image using syslinux, your kernel and an optional
6 # initrd
7
8 # External variables needed
9 # ${INITRD} - indicates a filesystem image to use as an initrd (optional)
10 # ${AUTO_SYSLINUXCFG} - set this to 1 to enable creating an automatic config
11 # ${LABELS} - a list of targets for the automatic config
12 # ${APPEND} - an override list of append strings for each label
13 # ${SYSLINUX_OPTS} - additional options to add to the syslinux file ';' delimited 
14
15 do_bootimg[depends] += "dosfstools-native:do_populate_staging \
16                         syslinux-native:do_populate_staging \
17                         mtools-native:do_populate_staging \
18                         cdrtools-native:do_populate_staging"
19
20 PACKAGES = " "
21
22 HDDDIR = "${S}/hdd/boot"
23 ISODIR = "${S}/cd/isolinux"
24
25 BOOTIMG_VOLUME_ID   ?= "oe"
26 BOOTIMG_EXTRA_SPACE ?= "64"
27
28 # Get the build_syslinux_cfg() function from the syslinux class
29
30 SYSLINUXCFG  = "${HDDDIR}/syslinux.cfg"
31 SYSLINUXMENU = "${HDDDIR}/menu"
32
33 inherit syslinux
34
35 IMAGE_POSTPROCESS_COMMAND ?= ""
36                 
37 build_boot_bin() {
38         install -d ${HDDDIR}
39         install -m 0644 ${STAGING_DIR}/${MACHINE}${HOST_VENDOR}-${HOST_OS}/kernel/bzImage \
40         ${HDDDIR}/vmlinuz
41
42         if [ -n "${INITRD}" ] && [ -s "${INITRD}" ]; then 
43                 install -m 0644 ${INITRD} ${HDDDIR}/initrd
44         fi
45
46         install -m 444 ${STAGING_DATADIR_NATIVE}/syslinux/ldlinux.sys \
47         ${HDDDIR}/ldlinux.sys
48
49         # Do a little math, bash style
50         #BLOCKS=`du -s ${HDDDIR} | cut -f 1`
51         BLOCKS=`du -bks ${HDDDIR} | cut -f 1`
52         SIZE=`expr $BLOCKS + ${BOOTIMG_EXTRA_SPACE}`    
53
54         install -d ${DEPLOY_DIR_IMAGE}
55
56         mkdosfs -F 12 -n ${BOOTIMG_VOLUME_ID} -d ${HDDDIR} \
57         -C ${DEPLOY_DIR_IMAGE}/${IMAGE_NAME}.hddimg $SIZE 
58
59         syslinux ${DEPLOY_DIR_IMAGE}/${IMAGE_NAME}.hddimg
60         chmod 644 ${DEPLOY_DIR_IMAGE}/${IMAGE_NAME}.hddimg
61
62         # Create an ISO if we have an INITRD
63         if [ -n "${INITRD}" ] && [ -s "${INITRD}" ] && [ "${NOISO}" != "1" ] ; then
64                 install -d ${ISODIR}
65
66                 # Install the kernel
67
68                 install -m 0644 ${STAGING_DIR}/${MACHINE}${HOST_VENDOR}-${HOST_OS}/kernel/bzImage \
69                         ${ISODIR}/vmlinuz
70
71                 # Install the configuration files
72
73                 cp ${HDDDIR}/syslinux.cfg ${ISODIR}/isolinux.cfg
74
75                 if [ -f ${SYSLINUXMENU} ]; then
76                         cp ${SYSLINUXMENU} ${ISODIR}
77                 fi
78
79                 install -m 0644 ${INITRD} ${ISODIR}/initrd
80
81                 # And install the syslinux stuff 
82                 cp ${STAGING_DATADIR_NATIVE}/syslinux/isolinux.bin \
83                 ${ISODIR}
84
85                 ${IMAGE_POSTPROCESS_COMMAND}
86
87                 mkisofs -V ${BOOTIMG_VOLUME_ID} \
88                 -o ${DEPLOY_DIR_IMAGE}/${IMAGE_NAME}.iso \
89                 -b isolinux/isolinux.bin -c isolinux/boot.cat -r \
90                 -no-emul-boot -boot-load-size 4 -boot-info-table \
91                 ${S}/cd/
92         fi
93
94
95 python do_bootimg() {
96         bb.build.exec_func('build_syslinux_cfg', d)
97         bb.build.exec_func('build_boot_bin', d)
98 }
99
100 # We need to run after bootsplash if it exists, so thats why this line
101 # is such.  Don't worry, if you don't do bootsplash, nobody will notice
102
103 addtask bootimg before do_build after do_bootsplash