abstract the prom device open/close into a separate module, which
provides the correct functions for primary, secondary, and unified boot blocks. actually behave correctly (e.g. expect correct arguments, perform correct operations) depending on which you are. also some minor cleanup.
This commit is contained in:
parent
39ea91226c
commit
f0bdf50326
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: bootxx.c,v 1.11 1999/04/02 03:11:57 cgd Exp $ */
|
||||
/* $NetBSD: bootxx.c,v 1.12 1999/04/02 03:19:08 cgd Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (C) 1998 by Ross Harvey
|
||||
@ -74,31 +74,6 @@ errorstatus(const char *msg, u_int64_t val)
|
||||
}
|
||||
#endif
|
||||
|
||||
static int
|
||||
open_dev(fd)
|
||||
int *fd;
|
||||
{
|
||||
prom_return_t ret;
|
||||
char devname[64];
|
||||
int devlen;
|
||||
|
||||
/*
|
||||
* XXX
|
||||
* We don't know what device names look like yet,
|
||||
* so we can't change them.
|
||||
*/
|
||||
ret.bits = prom_getenv(PROM_E_BOOTED_DEV, devname, sizeof(devname));
|
||||
devlen = ret.u.retval;
|
||||
|
||||
ret.bits = prom_open(devname, devlen);
|
||||
|
||||
if (ret.u.status)
|
||||
return 0;
|
||||
*fd = ret.u.retval;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
load_file(fd, bbinfop, loadaddr)
|
||||
int fd;
|
||||
@ -189,7 +164,7 @@ main()
|
||||
bbinfop = (struct bbinfo *)&_end;
|
||||
loadaddr = (char *)SECONDARY_LOAD_ADDRESS;
|
||||
|
||||
if (!open_dev(&fd)) {
|
||||
if (!booted_dev_open()) {
|
||||
puts("Can't open boot device\n");
|
||||
return;
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: boot.c,v 1.16 1999/04/02 03:11:57 cgd Exp $ */
|
||||
/* $NetBSD: boot.c,v 1.17 1999/04/02 03:19:08 cgd Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1992, 1993
|
||||
@ -52,7 +52,10 @@
|
||||
#include <machine/pte.h>
|
||||
|
||||
#include "common.h"
|
||||
#include "stand/boot/disk.h"
|
||||
|
||||
#if !defined(UNIFIED_BOOTBLOCK) && !defined(SECONDARY_BOOTBLOCK)
|
||||
#error not UNIFIED_BOOTBLOCK and not SECONDARY_BOOTBLOCK
|
||||
#endif
|
||||
|
||||
int loadfile __P((char *, u_int64_t *));
|
||||
|
||||
@ -78,8 +81,11 @@ char *kernelnames[] = {
|
||||
};
|
||||
|
||||
void
|
||||
main(fd)
|
||||
int fd;
|
||||
#if defined(UNIFIED_BOOTBLOCK)
|
||||
main(void)
|
||||
#else /* defined(SECONDARY_BOOTBLOCK) */
|
||||
main(long fd)
|
||||
#endif
|
||||
{
|
||||
char *name, **namep;
|
||||
u_int64_t entry;
|
||||
@ -87,7 +93,15 @@ main(fd)
|
||||
|
||||
/* Init prom callback vector. */
|
||||
init_prom_calls();
|
||||
|
||||
#if defined(UNIFIED_BOOTBLOCK)
|
||||
if (!booted_dev_open()) {
|
||||
printf("Boot device (%s) open failed.\n",
|
||||
booted_dev_name[0] ? booted_dev_name : "unknown");
|
||||
goto fail;
|
||||
}
|
||||
#else /* defined(SECONDARY_BOOTBLOCK) */
|
||||
booted_dev_setfd(fd);
|
||||
#endif
|
||||
|
||||
/* print a banner */
|
||||
printf("\n");
|
||||
@ -95,8 +109,6 @@ main(fd)
|
||||
printf("(%s, %s)\n", bootprog_maker, bootprog_date);
|
||||
printf("\n");
|
||||
|
||||
booted_dev_fd = fd;
|
||||
|
||||
/* switch to OSF pal code. */
|
||||
OSFpal();
|
||||
|
||||
@ -121,31 +133,36 @@ main(fd)
|
||||
namep++)
|
||||
win = (loadfile(name = *namep, &entry) == 0);
|
||||
|
||||
close_primary_device(fd);
|
||||
booted_dev_close();
|
||||
printf("\n");
|
||||
if (win) {
|
||||
/*
|
||||
* Fill in the bootinfo for the kernel.
|
||||
*/
|
||||
bzero(&bootinfo_v1, sizeof(bootinfo_v1));
|
||||
bootinfo_v1.ssym = ssym;
|
||||
bootinfo_v1.esym = esym;
|
||||
bcopy(name, bootinfo_v1.booted_kernel,
|
||||
sizeof(bootinfo_v1.booted_kernel));
|
||||
bcopy(boot_flags, bootinfo_v1.boot_flags,
|
||||
sizeof(bootinfo_v1.boot_flags));
|
||||
bootinfo_v1.hwrpb = (void *)HWRPB_ADDR;
|
||||
bootinfo_v1.hwrpbsize = ((struct rpb *)HWRPB_ADDR)->rpb_size;
|
||||
bootinfo_v1.cngetc = NULL;
|
||||
bootinfo_v1.cnputc = NULL;
|
||||
bootinfo_v1.cnpollc = NULL;
|
||||
|
||||
(void)printf("Entering %s at 0x%lx...\n", name, entry);
|
||||
alpha_pal_imb();
|
||||
(*(void (*)())entry)(ffp_save, ptbr_save,
|
||||
BOOTINFO_MAGIC, &bootinfo_v1, 1, 0);
|
||||
if (!win) {
|
||||
goto fail;
|
||||
}
|
||||
|
||||
/*
|
||||
* Fill in the bootinfo for the kernel.
|
||||
*/
|
||||
bzero(&bootinfo_v1, sizeof(bootinfo_v1));
|
||||
bootinfo_v1.ssym = ssym;
|
||||
bootinfo_v1.esym = esym;
|
||||
bcopy(name, bootinfo_v1.booted_kernel,
|
||||
sizeof(bootinfo_v1.booted_kernel));
|
||||
bcopy(boot_flags, bootinfo_v1.boot_flags,
|
||||
sizeof(bootinfo_v1.boot_flags));
|
||||
bootinfo_v1.hwrpb = (void *)HWRPB_ADDR;
|
||||
bootinfo_v1.hwrpbsize = ((struct rpb *)HWRPB_ADDR)->rpb_size;
|
||||
bootinfo_v1.cngetc = NULL;
|
||||
bootinfo_v1.cnputc = NULL;
|
||||
bootinfo_v1.cnpollc = NULL;
|
||||
|
||||
(void)printf("Entering %s at 0x%lx...\n", name, entry);
|
||||
alpha_pal_imb();
|
||||
(*(void (*)())entry)(ffp_save, ptbr_save, BOOTINFO_MAGIC,
|
||||
&bootinfo_v1, 1, 0);
|
||||
|
||||
(void)printf("KERNEL RETURNED!\n");
|
||||
|
||||
fail:
|
||||
(void)printf("Boot failed! Halting...\n");
|
||||
halt();
|
||||
}
|
||||
|
68
sys/arch/alpha/stand/common/booted_dev.c
Normal file
68
sys/arch/alpha/stand/common/booted_dev.c
Normal file
@ -0,0 +1,68 @@
|
||||
/* $NetBSD: booted_dev.c,v 1.1 1999/04/02 03:19:08 cgd Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1999 Christopher G. Demetriou. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by Christopher G. Demetriou
|
||||
* for the NetBSD Project.
|
||||
* 4. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <lib/libsa/stand.h>
|
||||
#include <lib/libkern/libkern.h>
|
||||
|
||||
#include <machine/prom.h>
|
||||
#include "common.h"
|
||||
|
||||
long booted_dev_fd;
|
||||
#if defined(PRIMARY_BOOTBLOCK) || defined(UNIFIED_BOOTBLOCK)
|
||||
char booted_dev_name[BOOTED_DEV_MAXNAMELEN];
|
||||
#endif /* defined(PRIMARY_BOOTBLOCK) || defined(UNIFIED_BOOTBLOCK) */
|
||||
|
||||
#if defined(PRIMARY_BOOTBLOCK) || defined(UNIFIED_BOOTBLOCK)
|
||||
int
|
||||
booted_dev_open(void)
|
||||
{
|
||||
prom_return_t ret;
|
||||
int devlen;
|
||||
|
||||
/*
|
||||
* XXX
|
||||
* We don't know what device names look like yet,
|
||||
* so we can't change them.
|
||||
*/
|
||||
ret.bits = prom_getenv(PROM_E_BOOTED_DEV, booted_dev_name,
|
||||
sizeof(booted_dev_name));
|
||||
devlen = ret.u.retval;
|
||||
|
||||
ret.bits = prom_open(booted_dev_name, devlen);
|
||||
|
||||
if (ret.u.status)
|
||||
return 0;
|
||||
booted_dev_fd = ret.u.retval;
|
||||
|
||||
return 1;
|
||||
}
|
||||
#endif
|
@ -1,10 +1,60 @@
|
||||
/* $NetBSD: common.h,v 1.7 1999/04/02 03:11:57 cgd Exp $ */
|
||||
/* $NetBSD: common.h,v 1.8 1999/04/02 03:19:08 cgd Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1999 Christopher G. Demetriou. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by Christopher G. Demetriou
|
||||
* for the NetBSD Project.
|
||||
* 4. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#define alpha_pal_imb() __asm__("imb")
|
||||
|
||||
void init_prom_calls __P((void));
|
||||
void OSFpal __P((void));
|
||||
void halt __P((void));
|
||||
u_int64_t prom_dispatch __P((int, ...));
|
||||
void switch_palcode __P((void));
|
||||
void close_primary_device __P((int));
|
||||
void OSFpal __P((void));
|
||||
void init_prom_calls __P((void));
|
||||
void halt __P((void));
|
||||
u_int64_t prom_dispatch __P((int, ...));
|
||||
void putstr __P((const char *));
|
||||
void switch_palcode __P((void));
|
||||
|
||||
|
||||
/*
|
||||
* booted_dev.c
|
||||
*/
|
||||
|
||||
#define BOOTED_DEV_MAXNAMELEN 64
|
||||
|
||||
#if defined(PRIMARY_BOOTBLOCK) || defined(UNIFIED_BOOTBLOCK)
|
||||
int booted_dev_open(void);
|
||||
#endif
|
||||
#define booted_dev_close() ((void)prom_close(booted_dev_fd))
|
||||
#if defined(SECONDARY_BOOTBLOCK)
|
||||
#define booted_dev_setfd(fd) ((void)(booted_dev_fd = fd))
|
||||
#endif
|
||||
|
||||
extern long booted_dev_fd;
|
||||
#if defined(PRIMARY_BOOTBLOCK) || defined(UNIFIED_BOOTBLOCK)
|
||||
extern char booted_dev_name[BOOTED_DEV_MAXNAMELEN];
|
||||
#endif
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: if_prom.c,v 1.11 1999/03/27 09:01:28 ross Exp $ */
|
||||
/* $NetBSD: if_prom.c,v 1.12 1999/04/02 03:19:09 cgd Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1997 Christopher G. Demetriou. All rights reserved.
|
||||
@ -85,7 +85,7 @@ struct netif_driver prom_netif_driver = {
|
||||
NENTS(prom_ifs) /* netif_nifs */
|
||||
};
|
||||
|
||||
int netfd, broken_firmware;
|
||||
int broken_firmware;
|
||||
|
||||
int
|
||||
prom_match(nif, machdep_hint)
|
||||
@ -112,7 +112,7 @@ prom_put(desc, pkt, len)
|
||||
int len;
|
||||
{
|
||||
|
||||
prom_write(netfd, len, pkt, 0);
|
||||
prom_write(booted_dev_fd, len, pkt, 0);
|
||||
|
||||
return len;
|
||||
}
|
||||
@ -134,9 +134,9 @@ prom_get(desc, pkt, len, timeout)
|
||||
cc = 0;
|
||||
while (((getsecs() - t) < timeout) && !cc) {
|
||||
if (broken_firmware)
|
||||
ret.bits = prom_read(netfd, 0, hate, 0);
|
||||
ret.bits = prom_read(booted_dev_fd, 0, hate, 0);
|
||||
else
|
||||
ret.bits = prom_read(netfd, sizeof hate, hate, 0);
|
||||
ret.bits = prom_read(booted_dev_fd, sizeof hate, hate, 0);
|
||||
if (ret.u.status == 0)
|
||||
cc = ret.u.retval;
|
||||
}
|
||||
@ -156,10 +156,8 @@ prom_init(desc, machdep_hint)
|
||||
struct iodesc *desc;
|
||||
void *machdep_hint;
|
||||
{
|
||||
prom_return_t ret;
|
||||
char devname[64];
|
||||
int devlen, i, netbbinfovalid;
|
||||
char *enet_addr;
|
||||
int i, netbbinfovalid;
|
||||
const char *enet_addr;
|
||||
u_int64_t *qp, csum;
|
||||
|
||||
broken_firmware = 0;
|
||||
@ -181,11 +179,8 @@ prom_init(desc, machdep_hint)
|
||||
ether_sprintf(netbbinfo.ether_addr));
|
||||
#endif
|
||||
|
||||
ret.bits = prom_getenv(PROM_E_BOOTED_DEV, devname, sizeof(devname));
|
||||
devlen = ret.u.retval;
|
||||
|
||||
/* Ethernet address is the 9th component of the booted_dev string. */
|
||||
enet_addr = devname;
|
||||
enet_addr = booted_dev_name;
|
||||
for (i = 0; i < 8; i++) {
|
||||
enet_addr = strchr(enet_addr, ' ');
|
||||
if (enet_addr == NULL) {
|
||||
@ -223,13 +218,6 @@ prom_init(desc, machdep_hint)
|
||||
|
||||
gotit:
|
||||
printf("boot: ethernet address: %s\n", ether_sprintf(desc->myea));
|
||||
|
||||
ret.bits = prom_open(devname, devlen + 1);
|
||||
if (ret.u.status) {
|
||||
printf("prom_init: open failed: %d\n", ret.u.status);
|
||||
goto reallypunt;
|
||||
}
|
||||
netfd = ret.u.retval;
|
||||
return;
|
||||
|
||||
punt:
|
||||
@ -240,13 +228,14 @@ punt:
|
||||
goto gotit;
|
||||
}
|
||||
|
||||
reallypunt:
|
||||
printf("\n");
|
||||
printf("Boot device name was: \"%s\"\n", devname);
|
||||
printf("Boot device name was: \"%s\"\n", booted_dev_name);
|
||||
printf("\n");
|
||||
printf("Your firmware may be too old to network-boot NetBSD/Alpha,\n");
|
||||
printf("or you might have to hard-code an ethernet address into\n");
|
||||
printf("your network boot block with setnetbootinfo(8).\n");
|
||||
|
||||
booted_dev_close();
|
||||
halt();
|
||||
}
|
||||
|
||||
@ -255,12 +244,5 @@ prom_end(nif)
|
||||
struct netif *nif;
|
||||
{
|
||||
|
||||
prom_close(netfd);
|
||||
}
|
||||
|
||||
void
|
||||
close_primary_device(fd)
|
||||
int fd;
|
||||
{
|
||||
/* do nothing, there is no primary boot stage for us */
|
||||
/* nothing to do */
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user