summaryrefslogtreecommitdiff
path: root/arch/x86/boot/genimage.sh
blob: 75a9de1d3f72df2b3a5152108160f4cb7effbabc (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
#!/bin/sh
#
# This file is subject to the terms and conditions of the GNU General Public
# License.  See the file "COPYING" in the main directory of this archive
# for more details.
#
# Copyright (C) 2017 by Changbin Du <changbin.du@intel.com>
#
# Adapted from code in arch/x86/boot/Makefile by H. Peter Anvin and others
#
# "make fdimage/fdimage144/fdimage288/isoimage" script for x86 architecture
#
# Arguments:
#   $1 - fdimage format
#   $2 - target image file
#   $3 - kernel bzImage file
#   $4 - mtool configuration file
#   $5 - kernel cmdline
#   $6 - inird image file
#

verify () {
	if [ ! -f "$1" ]; then
		echo ""                                                   1>&2
		echo " *** Missing file: $1"                              1>&2
		echo ""                                                   1>&2
		exit 1
	fi
}


export MTOOLSRC=$4
FIMAGE=$2
FBZIMAGE=$3
KCMDLINE=$5
FDINITRD=$6

# Make sure the files actually exist
verify "$FBZIMAGE"
verify "$MTOOLSRC"

genbzdisk() {
	mformat a:
	syslinux $FIMAGE
	echo "$KCMDLINE" | mcopy - a:syslinux.cfg
	if [ -f "$FDINITRD" ] ; then
		mcopy "$FDINITRD" a:initrd.img
	fi
	mcopy $FBZIMAGE a:linux
}

genfdimage144() {
	dd if=/dev/zero of=$FIMAGE bs=1024 count=1440
	mformat v:
	syslinux $FIMAGE
	echo "$KCMDLINE" | mcopy - v:syslinux.cfg
	if [ -f "$FDINITRD" ] ; then
		mcopy "$FDINITRD" v:initrd.img
	fi
	mcopy $FBZIMAGE v:linux
}

genfdimage288() {
	dd if=/dev/zero of=$FIMAGE bs=1024 count=2880
	mformat w:
	syslinux $FIMAGE
	echo "$KCMDLINE" | mcopy - W:syslinux.cfg
	if [ -f "$FDINITRD" ] ; then
		mcopy "$FDINITRD" w:initrd.img
	fi
	mcopy $FBZIMAGE w:linux
}

genisoimage() {
	tmp_dir=`dirname $FIMAGE`/isoimage
	rm -rf $tmp_dir
	mkdir $tmp_dir
	for i in lib lib64 share end ; do
		if [ -f /usr/$i/syslinux/isolinux.bin ] ; then
			cp /usr/$i/syslinux/isolinux.bin $tmp_dir
			if [ -f /usr/$i/syslinux/ldlinux.c32 ]; then
				cp /usr/$i/syslinux/ldlinux.c32 $tmp_dir
			fi
			break
		fi
		if [ $i = end ] ; then exit 1 ; fi ;
	done
	cp $FBZIMAGE $tmp_dir/linux
	echo "$KCMDLINE" > $tmp_dir/isolinux.cfg
	if [ -f "$FDINITRD" ] ; then
		cp "$FDINITRD" $tmp_dir/initrd.img
	fi
	mkisofs -J -r -o $FIMAGE -b isolinux.bin -c boot.cat \
		-no-emul-boot -boot-load-size 4 -boot-info-table $tmp_dir
	isohybrid $FIMAGE 2>/dev/null || true
	rm -rf $tmp_dir
}

case $1 in
	bzdisk)     genbzdisk;;
	fdimage144) genfdimage144;;
	fdimage288) genfdimage288;;
	isoimage)   genisoimage;;
	*)          echo 'Unknown image format'; exit 1;
esac