2 * This file has been modified for the cdrkit suite.
4 * The behaviour and appearence of the program code below can differ to a major
5 * extent from the version distributed by the original author(s).
7 * For details, see Changelog file distributed with the cdrkit package. If you
8 * received this file from another source then ask the distributing person for
9 * a log of modifications.
14 * Program boot-hppa.c - Handle HPPA boot extensions to iso9660.
16 * Written by Steve McIntyre <steve@einval.com> June 2004.
18 * Heavily inspired by palo:
20 ****************************************************************************
21 * This file is subject to the terms and conditions of the GNU General Public
22 * License. See the file "COPYING" in the main directory of this archive
25 * Copyright (C) Hewlett-Packard (Paul Bame) paul_bame@hp.com
27 ****************************************************************************
28 * Copyright 2004 Steve McIntyre
30 * This program is free software; you can redistribute it and/or modify
31 * it under the terms of the GNU General Public License as published by
32 * the Free Software Foundation; either version 2, or (at your option)
35 * This program is distributed in the hope that it will be useful,
36 * but WITHOUT ANY WARRANTY; without even the implied warranty of
37 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
38 * GNU General Public License for more details.
40 * You should have received a copy of the GNU General Public License
41 * along with this program; if not, write to the Free Software
42 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
46 #include "genisoimage.h"
54 #include "endianconv.h"
56 extern long long alpha_hppa_boot_sector[256];
57 extern int boot_sector_initialized;
59 int add_boot_hppa_cmdline(char *cmdline);
60 int add_boot_hppa_kernel_32(char *filename);
61 int add_boot_hppa_kernel_64(char *filename);
62 int add_boot_hppa_bootloader(char *filename);
63 int add_boot_hppa_ramdisk(char *filename);
65 static int boot_hppa_write(FILE *outfile);
67 static char *hppa_cmdline = NULL;
68 static char *hppa_kernel_32 = NULL;
69 static char *hppa_kernel_64 = NULL;
70 static char *hppa_bootloader = NULL;
71 static char *hppa_ramdisk = NULL;
73 /* Simple function: store the filename to be used later when we need
74 to find the boot file */
75 extern int add_boot_hppa_cmdline(char *cmdline)
78 hppa_cmdline = strdup(cmdline);
89 /* Simple function: store the filename to be used later when we need
90 to find the boot file */
91 extern int add_boot_hppa_kernel_32(char *filename)
93 hppa_kernel_32 = filename;
97 /* Simple function: store the filename to be used later when we need
98 to find the boot file */
99 extern int add_boot_hppa_kernel_64(char *filename)
101 hppa_kernel_64 = filename;
105 /* Simple function: store the filename to be used later when we need
106 to find the boot file */
107 extern int add_boot_hppa_bootloader(char *filename)
109 hppa_bootloader = filename;
113 /* Simple function: store the filename to be used later when we need
114 to find the boot file */
115 extern int add_boot_hppa_ramdisk(char *filename)
117 hppa_ramdisk = filename;
121 static void exit_fatal(char *type, char *filename)
124 comerrno(EX_BAD, "Uh oh, I can't find the %s '%s'!\n",
127 fprintf(stderr, "Uh oh, I can't find the %s '%s'!\n",
133 static int boot_hppa_write(FILE *outfile)
135 struct directory_entry *boot_file; /* Boot file we need to search for */
136 unsigned long length = 0;
137 unsigned long extent = 0;
138 unsigned char *boot_sector = (unsigned char *) alpha_hppa_boot_sector;
141 if (!boot_sector_initialized) {
142 memset(alpha_hppa_boot_sector, 0, sizeof(alpha_hppa_boot_sector));
143 boot_sector_initialized = 1;
146 printf("Address is: %p\n",alpha_hppa_boot_sector);
148 boot_sector[0] = 0x80; /* magic */
149 boot_sector[1] = 0x00; /* magic */
150 boot_sector[2] = 'P';
151 boot_sector[3] = 'A';
152 boot_sector[4] = 'L';
153 boot_sector[5] = 'O';
154 boot_sector[6] = 0x00;
155 boot_sector[7] = 0x04; /* version */
157 /* Find the dir entry for the 32-bit kernel by walking our file list */
158 boot_file = search_tree_file(root, hppa_kernel_32);
160 exit_fatal("HPPA 32-bit kernel", hppa_kernel_32);
161 extent = 2048 * get_733(boot_file->isorec.extent);
162 length = get_733(boot_file->isorec.size);
163 fprintf(stderr, "Found hppa 32-bit kernel %s: using extent %lu (0x%lX), size %lu (0x%lX)\n",
164 hppa_kernel_32, extent, extent, length, length);
165 write_be32(extent, &boot_sector[8]);
166 write_be32(length, &boot_sector[12]);
168 /* Find the dir entry for the ramdisk by walking our file list */
169 boot_file = search_tree_file(root, hppa_ramdisk);
171 exit_fatal("HPPA ramdisk", hppa_ramdisk);
172 extent = 2048 * get_733(boot_file->isorec.extent);
173 length = get_733(boot_file->isorec.size);
174 fprintf(stderr, "Found hppa ramdisk %s: using extent %lu (0x%lX), size %lu (0x%lX)\n",
175 hppa_ramdisk, extent, extent, length, length);
176 write_be32(extent, &boot_sector[16]);
177 write_be32(length, &boot_sector[20]);
179 /* Now the commandline */
180 snprintf((char *)&boot_sector[24], 127, "%s", hppa_cmdline);
182 /* Find the dir entry for the 64-bit kernel by walking our file list */
183 boot_file = search_tree_file(root, hppa_kernel_64);
185 exit_fatal("HPPA 64-bit kernel", hppa_kernel_64);
186 extent = 2048 * get_733(boot_file->isorec.extent);
187 length = get_733(boot_file->isorec.size);
188 fprintf(stderr, "Found hppa 64-bit kernel %s: using extent %lu (0x%lX), size %lu (0x%lX)\n",
189 hppa_kernel_64, extent, extent, length, length);
190 write_be32(extent, &boot_sector[232]);
191 write_be32(length, &boot_sector[236]);
193 /* Find the dir entry for the IPL by walking our file list */
194 boot_file = search_tree_file(root, hppa_bootloader);
196 exit_fatal("HPPA bootloader", hppa_bootloader);
197 extent = 2048 * get_733(boot_file->isorec.extent);
198 length = get_733(boot_file->isorec.size);
199 fprintf(stderr, "Found hppa bootloader %s: using extent %lu (0x%lX), size %lu (0x%lX)\n",
200 hppa_bootloader, extent, extent, length, length);
201 write_be32(extent, &boot_sector[240]);
202 write_be32(length, &boot_sector[244]);
207 struct output_fragment hppaboot_desc = {NULL, NULL, NULL, boot_hppa_write, "hppa boot block"};