xref: /minix3/releasetools/x86_usbimage.sh (revision a7a79fa1f56459d4581874d33595a897559e1cda)
1*a7a79fa1SJean-Baptiste Boric#!/usr/bin/env bash
2*a7a79fa1SJean-Baptiste Boricset -e
3*a7a79fa1SJean-Baptiste Boric
4*a7a79fa1SJean-Baptiste Boric#
5*a7a79fa1SJean-Baptiste Boric# This script creates a bootable image and should at some point in the future
6*a7a79fa1SJean-Baptiste Boric# be replaced by the proper NetBSD infrastructure.
7*a7a79fa1SJean-Baptiste Boric#
8*a7a79fa1SJean-Baptiste Boric
9*a7a79fa1SJean-Baptiste Boric: ${ARCH=i386}
10*a7a79fa1SJean-Baptiste Boric: ${OBJ=../obj.${ARCH}}
11*a7a79fa1SJean-Baptiste Boric: ${TOOLCHAIN_TRIPLET=i586-elf32-minix-}
12*a7a79fa1SJean-Baptiste Boric: ${BUILDSH=build.sh}
13*a7a79fa1SJean-Baptiste Boric
14*a7a79fa1SJean-Baptiste Boric: ${SETS="minix-base"}
15*a7a79fa1SJean-Baptiste Boric: ${IMG=minix_x86_usb.img}
16*a7a79fa1SJean-Baptiste Boric
17*a7a79fa1SJean-Baptiste Boricif [ ! -f ${BUILDSH} ]
18*a7a79fa1SJean-Baptiste Boricthen
19*a7a79fa1SJean-Baptiste Boric	echo "Please invoke me from the root source dir, where ${BUILDSH} is."
20*a7a79fa1SJean-Baptiste Boric	exit 1
21*a7a79fa1SJean-Baptiste Boricfi
22*a7a79fa1SJean-Baptiste Boric
23*a7a79fa1SJean-Baptiste Boric#: ${RAMDISK_SIZE=$(( 200*(2**20) ))}
24*a7a79fa1SJean-Baptiste Boric: ${BOOTXX_SECS=32}
25*a7a79fa1SJean-Baptiste Boric
26*a7a79fa1SJean-Baptiste Boric# set up disk creation environment
27*a7a79fa1SJean-Baptiste Boric. releasetools/image.defaults
28*a7a79fa1SJean-Baptiste Boric. releasetools/image.functions
29*a7a79fa1SJean-Baptiste Boric
30*a7a79fa1SJean-Baptiste Boric# where the kernel & boot modules will be
31*a7a79fa1SJean-Baptiste BoricMODDIR=${DESTDIR}/boot/minix/.temp
32*a7a79fa1SJean-Baptiste Boric
33*a7a79fa1SJean-Baptiste Boricecho "Building work directory..."
34*a7a79fa1SJean-Baptiste Boricbuild_workdir "$SETS"
35*a7a79fa1SJean-Baptiste Boric
36*a7a79fa1SJean-Baptiste Boricecho "Adding extra files..."
37*a7a79fa1SJean-Baptiste Boricworkdir_add_ramdisk_files
38*a7a79fa1SJean-Baptiste Boric
39*a7a79fa1SJean-Baptiste Boric# set correct message of the day (log in and install tip)
40*a7a79fa1SJean-Baptiste Boriccp releasetools/release/ramdisk/etc/issue ${ROOT_DIR}/etc/issue
41*a7a79fa1SJean-Baptiste Boricadd_file_spec "etc/issue" extra.cdfiles
42*a7a79fa1SJean-Baptiste Boric
43*a7a79fa1SJean-Baptiste Boricecho "Bundling packages..."
44*a7a79fa1SJean-Baptiste Boricbundle_packages "$BUNDLE_PACKAGES"
45*a7a79fa1SJean-Baptiste Boric
46*a7a79fa1SJean-Baptiste Boricecho "Creating specification files..."
47*a7a79fa1SJean-Baptiste Boriccreate_input_spec
48*a7a79fa1SJean-Baptiste Boriccreate_protos
49*a7a79fa1SJean-Baptiste Boric
50*a7a79fa1SJean-Baptiste Boricecho "Writing ramdisk image..."
51*a7a79fa1SJean-Baptiste Boric# add the other modules for boot
52*a7a79fa1SJean-Baptiste Boriccp ${MODDIR}/* ${WORK_DIR}
53*a7a79fa1SJean-Baptiste Boriccreate_ramdisk_image ${RAMDISK_SIZE}
54*a7a79fa1SJean-Baptiste Boric
55*a7a79fa1SJean-Baptiste Boricecho "Writing USB image..."
56*a7a79fa1SJean-Baptiste Boric# clear ROOT_DIR
57*a7a79fa1SJean-Baptiste Boricrm -rf ${ROOT_DIR}/*
58*a7a79fa1SJean-Baptiste Boricecho ". type=dir uid=0 gid=0 mode=0755" > ${WORK_DIR}/extra.boot
59*a7a79fa1SJean-Baptiste Boric
60*a7a79fa1SJean-Baptiste Boric# move all modules back to ROOT_DIR
61*a7a79fa1SJean-Baptiste Boricmv ${WORK_DIR}/kernel ${WORK_DIR}/mod* ${ROOT_DIR}/
62*a7a79fa1SJean-Baptiste Boricadd_file_spec "kernel" extra.boot
63*a7a79fa1SJean-Baptiste Boricfor i in ${ROOT_DIR}/mod*; do
64*a7a79fa1SJean-Baptiste Boric	add_file_spec $(basename $i) extra.boot
65*a7a79fa1SJean-Baptiste Boricdone
66*a7a79fa1SJean-Baptiste Boric
67*a7a79fa1SJean-Baptiste Boric# add boot.cfg
68*a7a79fa1SJean-Baptiste Boriccat >${ROOT_DIR}/boot.cfg <<END_BOOT_CFG
69*a7a79fa1SJean-Baptiste Boricmenu=Start MINIX 3:load_mods /mod*; multiboot /kernel bootramdisk=1
70*a7a79fa1SJean-Baptiste Boricmenu=Edit menu option:edit
71*a7a79fa1SJean-Baptiste Boricmenu=Drop to boot prompt:prompt
72*a7a79fa1SJean-Baptiste Boricclear=1
73*a7a79fa1SJean-Baptiste Borictimeout=5
74*a7a79fa1SJean-Baptiste Boricdefault=1
75*a7a79fa1SJean-Baptiste BoricEND_BOOT_CFG
76*a7a79fa1SJean-Baptiste Boricadd_file_spec "boot.cfg" extra.boot
77*a7a79fa1SJean-Baptiste Boric
78*a7a79fa1SJean-Baptiste Boric# add boot monitor
79*a7a79fa1SJean-Baptiste Boriccp ${DESTDIR}/usr/mdec/boot_monitor ${ROOT_DIR}/boot_monitor
80*a7a79fa1SJean-Baptiste Boricadd_file_spec "boot_monitor" extra.boot
81*a7a79fa1SJean-Baptiste Boric
82*a7a79fa1SJean-Baptiste Boric# create proto file
83*a7a79fa1SJean-Baptiste Boriccat ${WORK_DIR}/extra.boot | ${CROSS_TOOLS}/nbtoproto -b ${ROOT_DIR} -o ${WORK_DIR}/proto.boot
84*a7a79fa1SJean-Baptiste Boric
85*a7a79fa1SJean-Baptiste BoricROOT_START=${BOOTXX_SECS}
86*a7a79fa1SJean-Baptiste Boric_ROOT_SIZE=$(${CROSS_TOOLS}/nbmkfs.mfs -I $((${ROOT_START} * 512)) ${IMG} ${WORK_DIR}/proto.boot)
87*a7a79fa1SJean-Baptiste Boric_ROOT_SIZE=$(($_ROOT_SIZE / 512))
88*a7a79fa1SJean-Baptiste Boric
89*a7a79fa1SJean-Baptiste Boric#
90*a7a79fa1SJean-Baptiste Boric# Write the partition table using the natively compiled
91*a7a79fa1SJean-Baptiste Boric# minix partition utility
92*a7a79fa1SJean-Baptiste Boric#
93*a7a79fa1SJean-Baptiste Boric${CROSS_TOOLS}/nbpartition -m ${IMG} ${BOOTXX_SECS} 81:${_ROOT_SIZE}
94*a7a79fa1SJean-Baptiste Boric${CROSS_TOOLS}/nbinstallboot -f -m ${ARCH} ${IMG} ${DESTDIR}/usr/mdec/bootxx_minixfs3
95*a7a79fa1SJean-Baptiste Boric
96*a7a79fa1SJean-Baptiste Boricecho ""
97*a7a79fa1SJean-Baptiste Boricecho "Universally Supported Boot disk image at `pwd`/${IMG}"
98*a7a79fa1SJean-Baptiste Boricecho ""
99*a7a79fa1SJean-Baptiste Boricecho "To boot this image on kvm using the bootloader:"
100*a7a79fa1SJean-Baptiste Boric# This is really, really slow.
101*a7a79fa1SJean-Baptiste Boric# echo "qemu-system-i386 --enable-kvm -m 1G -usbdevice disk:`pwd`/${IMG}"
102*a7a79fa1SJean-Baptiste Boricecho "qemu-system-i386 --enable-kvm -m 1G -hda `pwd`/${IMG}"
103*a7a79fa1SJean-Baptiste Boricecho ""
104*a7a79fa1SJean-Baptiste Boricecho "To boot this image on kvm:"
105*a7a79fa1SJean-Baptiste Boricecho "cd ${ROOT_DIR} && qemu-system-i386 --enable-kvm -m 1G -kernel kernel -append \"bootramdisk=1\" -initrd \"${mods}\""
106