xref: /freebsd/stand/powerpc/boot1.chrp/generate-hfs.sh (revision 7ef62cebc2f965b0f640263e179276928885e33d)
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
13# $FreeBSD$
14
15HFS_SIZE=1600 			#Size in 512-byte blocks of the produced image
16
17CHRPBOOT_SIZE=2k
18BOOT1_SIZE=64k
19
20# Generate 800K HFS image
21OUTPUT_FILE=hfs.tmpl
22
23dd if=/dev/zero of=$OUTPUT_FILE bs=512 count=$HFS_SIZE
24hformat -l "FreeBSD Bootstrap" $OUTPUT_FILE
25hmount $OUTPUT_FILE
26
27# Create and bless a directory for the boot loader
28hmkdir ppc
29hattrib -b ppc
30hcd ppc
31
32# Make two dummy files for the CHRP boot script and boot1
33echo 'Bootinfo START' | dd of=bootinfo.txt.tmp cbs=$CHRPBOOT_SIZE count=1 conv=block
34echo 'Boot1 START' | dd of=boot1.elf.tmp cbs=$BOOT1_SIZE count=1 conv=block
35
36hcopy boot1.elf.tmp :boot1.elf
37hcopy bootinfo.txt.tmp :bootinfo.txt
38hattrib -c chrp -t tbxi bootinfo.txt
39humount
40
41rm bootinfo.txt.tmp
42rm boot1.elf.tmp
43
44# Locate the offsets of the two fake files
45BOOTINFO_OFFSET=$(hd $OUTPUT_FILE | grep 'Bootinfo START' | cut -f 1 -d ' ')
46BOOT1_OFFSET=$(hd $OUTPUT_FILE | grep 'Boot1 START' | cut -f 1 -d ' ')
47
48# Convert to numbers of blocks
49BOOTINFO_OFFSET=$(echo 0x$BOOTINFO_OFFSET | awk '{printf("%x\n",$1/512);}')
50BOOT1_OFFSET=$(echo 0x$BOOT1_OFFSET | awk '{printf("%x\n",$1/512);}')
51
52echo '# This file autogenerated by generate-hfs.sh - DO NOT EDIT' > Makefile.hfs
53echo '# $FreeBSD$' >> Makefile.hfs
54echo "BOOTINFO_OFFSET=0x$BOOTINFO_OFFSET" >> Makefile.hfs
55echo "BOOT1_OFFSET=0x$BOOT1_OFFSET" >> Makefile.hfs
56
57bzip2 $OUTPUT_FILE
58echo 'HFS template boot filesystem created by generate-hfs.sh' > $OUTPUT_FILE.bz2.uu
59echo 'DO NOT EDIT' >> $OUTPUT_FILE.bz2.uu
60echo '$FreeBSD$' >> $OUTPUT_FILE.bz2.uu
61
62uuencode $OUTPUT_FILE.bz2 $OUTPUT_FILE.bz2 >> $OUTPUT_FILE.bz2.uu
63rm $OUTPUT_FILE.bz2
64
65