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