1#!/bin/sh
2
3# This script generates the dummy HFS filesystem used for the PowerPC boot
4# blocks. It uses hfsutils (emulators/hfsutils) to generate a template
5# filesystem with the relevant interesting files. These are then found by
6# grep, and the offsets written to a Makefile snippet.
7#
8# Because of licensing concerns, and because it is overkill, we do not
9# distribute hfsutils as a build tool. If you need to regenerate the HFS
10# template (e.g. because the boot block or the CHRP script have grown),
11# you must install it from ports.
12
13HFS_SIZE=1600 			#Size in 512-byte blocks of the produced image
14
15CHRPBOOT_SIZE=2k
16BOOT1_SIZE=64k
17
18# Generate 800K HFS image
19OUTPUT_FILE=hfs.tmpl
20
21dd if=/dev/zero of=$OUTPUT_FILE bs=512 count=$HFS_SIZE
22hformat -l "FreeBSD Bootstrap" $OUTPUT_FILE
23hmount $OUTPUT_FILE
24
25# Create and bless a directory for the boot loader
26hmkdir ppc
27hattrib -b ppc
28hcd ppc
29
30# Make two dummy files for the CHRP boot script and boot1
31echo 'Bootinfo START' | dd of=bootinfo.txt.tmp cbs=$CHRPBOOT_SIZE count=1 conv=block
32echo 'Boot1 START' | dd of=boot1.elf.tmp cbs=$BOOT1_SIZE count=1 conv=block
33
34hcopy boot1.elf.tmp :boot1.elf
35hcopy bootinfo.txt.tmp :bootinfo.txt
36hattrib -c chrp -t tbxi bootinfo.txt
37humount
38
39rm bootinfo.txt.tmp
40rm boot1.elf.tmp
41
42# Locate the offsets of the two fake files
43BOOTINFO_OFFSET=$(hd $OUTPUT_FILE | grep 'Bootinfo START' | cut -f 1 -d ' ')
44BOOT1_OFFSET=$(hd $OUTPUT_FILE | grep 'Boot1 START' | cut -f 1 -d ' ')
45
46# Convert to numbers of blocks
47BOOTINFO_OFFSET=$(echo 0x$BOOTINFO_OFFSET | awk '{printf("%x\n",$1/512);}')
48BOOT1_OFFSET=$(echo 0x$BOOT1_OFFSET | awk '{printf("%x\n",$1/512);}')
49
50echo '# This file autogenerated by generate-hfs.sh - DO NOT EDIT' > Makefile.hfs
51echo "BOOTINFO_OFFSET=0x$BOOTINFO_OFFSET" >> Makefile.hfs
52echo "BOOT1_OFFSET=0x$BOOT1_OFFSET" >> Makefile.hfs
53
54bzip2 $OUTPUT_FILE
55echo 'HFS template boot filesystem created by generate-hfs.sh' > $OUTPUT_FILE.bz2.uu
56echo 'DO NOT EDIT' >> $OUTPUT_FILE.bz2.uu
57
58uuencode $OUTPUT_FILE.bz2 $OUTPUT_FILE.bz2 >> $OUTPUT_FILE.bz2.uu
59rm $OUTPUT_FILE.bz2
60
61