xref: /openbmc/linux/arch/x86/boot/genimage.sh (revision f7af616c)
1#!/bin/sh
2#
3# This file is subject to the terms and conditions of the GNU General Public
4# License.  See the file "COPYING" in the main directory of this archive
5# for more details.
6#
7# Copyright (C) 2017 by Changbin Du <changbin.du@intel.com>
8#
9# Adapted from code in arch/x86/boot/Makefile by H. Peter Anvin and others
10#
11# "make fdimage/fdimage144/fdimage288/isoimage" script for x86 architecture
12#
13# Arguments:
14#   $1 - fdimage format
15#   $2 - target image file
16#   $3 - kernel bzImage file
17#   $4 - mtool configuration file
18#   $5 - kernel cmdline
19#   $6 - inird image file
20#
21
22# Use "make V=1" to debug this script
23case "${KBUILD_VERBOSE}" in
24*1*)
25        set -x
26        ;;
27esac
28
29verify () {
30	if [ ! -f "$1" ]; then
31		echo ""                                                   1>&2
32		echo " *** Missing file: $1"                              1>&2
33		echo ""                                                   1>&2
34		exit 1
35	fi
36}
37
38
39export MTOOLSRC=$4
40FIMAGE=$2
41FBZIMAGE=$3
42KCMDLINE=$5
43FDINITRD=$6
44
45# Make sure the files actually exist
46verify "$FBZIMAGE"
47
48genbzdisk() {
49	verify "$MTOOLSRC"
50	mformat a:
51	syslinux $FIMAGE
52	echo "$KCMDLINE" | mcopy - a:syslinux.cfg
53	if [ -f "$FDINITRD" ] ; then
54		mcopy "$FDINITRD" a:initrd.img
55	fi
56	mcopy $FBZIMAGE a:linux
57}
58
59genfdimage144() {
60	verify "$MTOOLSRC"
61	dd if=/dev/zero of=$FIMAGE bs=1024 count=1440 2> /dev/null
62	mformat v:
63	syslinux $FIMAGE
64	echo "$KCMDLINE" | mcopy - v:syslinux.cfg
65	if [ -f "$FDINITRD" ] ; then
66		mcopy "$FDINITRD" v:initrd.img
67	fi
68	mcopy $FBZIMAGE v:linux
69}
70
71genfdimage288() {
72	verify "$MTOOLSRC"
73	dd if=/dev/zero of=$FIMAGE bs=1024 count=2880 2> /dev/null
74	mformat w:
75	syslinux $FIMAGE
76	echo "$KCMDLINE" | mcopy - W:syslinux.cfg
77	if [ -f "$FDINITRD" ] ; then
78		mcopy "$FDINITRD" w:initrd.img
79	fi
80	mcopy $FBZIMAGE w:linux
81}
82
83geniso() {
84	tmp_dir=`dirname $FIMAGE`/isoimage
85	rm -rf $tmp_dir
86	mkdir $tmp_dir
87	for i in lib lib64 share ; do
88		for j in syslinux ISOLINUX ; do
89			if [ -f /usr/$i/$j/isolinux.bin ] ; then
90				isolinux=/usr/$i/$j/isolinux.bin
91			fi
92		done
93		for j in syslinux syslinux/modules/bios ; do
94			if [ -f /usr/$i/$j/ldlinux.c32 ]; then
95				ldlinux=/usr/$i/$j/ldlinux.c32
96			fi
97		done
98		if [ -n "$isolinux" -a -n "$ldlinux" ] ; then
99			break
100		fi
101	done
102	if [ -z "$isolinux" ] ; then
103		echo 'Need an isolinux.bin file, please install syslinux/isolinux.'
104		exit 1
105	fi
106	if [ -z "$ldlinux" ] ; then
107		echo 'Need an ldlinux.c32 file, please install syslinux/isolinux.'
108		exit 1
109	fi
110	cp $isolinux $tmp_dir
111	cp $ldlinux $tmp_dir
112	cp $FBZIMAGE $tmp_dir/linux
113	echo "$KCMDLINE" > $tmp_dir/isolinux.cfg
114	if [ -f "$FDINITRD" ] ; then
115		cp "$FDINITRD" $tmp_dir/initrd.img
116	fi
117	genisoimage -J -r -input-charset=utf-8 -quiet -o $FIMAGE \
118		-b isolinux.bin -c boot.cat -no-emul-boot -boot-load-size 4 \
119		-boot-info-table $tmp_dir
120	isohybrid $FIMAGE 2>/dev/null || true
121	rm -rf $tmp_dir
122}
123
124case $1 in
125	bzdisk)     genbzdisk;;
126	fdimage144) genfdimage144;;
127	fdimage288) genfdimage288;;
128	isoimage)   geniso;;
129	*)          echo 'Unknown image format'; exit 1;
130esac
131