bootxx.c revision 1.3
1/* $NetBSD: bootxx.c,v 1.3 2002/04/24 01:40:25 lukem Exp $ */ 2 3/*- 4 * Copyright (c) 1998 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by Paul Kranenburg. 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 3. All advertising materials mentioning features or use of this software 19 * must display the following acknowledgement: 20 * This product includes software developed by the NetBSD 21 * Foundation, Inc. and its contributors. 22 * 4. Neither the name of The NetBSD Foundation nor the names of its 23 * contributors may be used to endorse or promote products derived 24 * from this software without specific prior written permission. 25 * 26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 36 * POSSIBILITY OF SUCH DAMAGE. 37 */ 38 39/* 40 * This is a generic "first-stage" boot program. 41 * 42 * Note that this program has absolutely no filesystem knowledge! 43 * 44 * Instead, this uses a table of disk block numbers that are 45 * filled in by the installboot program such that this program 46 * can load the "second-stage" boot program. 47 */ 48 49#include <sys/param.h> 50#include <machine/mon.h> 51 52#include <dev/sun/sun_boot.h> 53 54#include <stand.h> 55#include "libsa.h" 56 57/* 58 * This is the address where we load the second-stage boot loader. 59 */ 60#define LOADADDR 0x4000 61 62/* 63 * The contents of the sun68k_bbinfo below are set by installboot(8) 64 * to hold the filesystem data of the second-stage boot program 65 * (typically `/ufsboot'): filesystem block size, # of filesystem 66 * blocks and the block numbers themselves. 67 */ 68struct sun68k_bbinfo bbinfo = { 69 { SUN68K_BBINFO_MAGIC }, 70 0, 71 MAXBLOCKNUM, 72 { 0 } 73}; 74 75int 76main() 77{ 78 struct open_file f; 79 void *entry; 80 char *addr; 81 int n, error; 82 83#ifdef DEBUG 84 printf("bootxx: open...\n"); 85#endif 86 f.f_flags = F_RAW; 87 if (devopen(&f, 0, &addr)) { 88 printf("bootxx: devopen failed\n"); 89 return; 90 } 91 92 addr = (char*)LOADADDR; 93 error = copyboot(&f, addr); 94 f.f_dev->dv_close(&f); 95 if (!error) { 96#ifdef DEBUG 97 printf("bootxx: start 0x%x\n", (long)addr); 98#endif 99 entry = addr; 100 chain_to(entry); 101 } 102 /* copyboot had a problem... */ 103 return; 104} 105 106int 107copyboot(fp, addr) 108 struct open_file *fp; 109 char *addr; 110{ 111 int n, i, blknum; 112 char *buf; 113 114 /* Need to use a buffer that can be mapped into DVMA space. */ 115 buf = alloc(bbinfo.bbi_block_size); 116 if (!buf) 117 panic("bootxx: alloc failed"); 118 119 for (i = 0; i < bbinfo.bbi_block_count; i++) { 120 121 if ((blknum = bbinfo.bbi_block_table[i]) == 0) 122 break; 123 124#ifdef DEBUG 125 printf("bootxx: block # %d = %d\n", i, blknum); 126#endif 127 if ((fp->f_dev->dv_strategy)(fp->f_devdata, F_READ, blknum, 128 bbinfo.bbi_block_size, buf, &n)) 129 { 130 printf("bootxx: read failed\n"); 131 return -1; 132 } 133 if (n != bbinfo.bbi_block_size) { 134 printf("bootxx: short read\n"); 135 return -1; 136 } 137 bcopy(buf, addr, bbinfo.bbi_block_size); 138 addr += bbinfo.bbi_block_size; 139 } 140 141 return 0; 142} 143 144