Add support to pass boothowto and bootdev info from bootloader to kernel.

Kernel side changes:
- use %d7 (boothowto) and %d6 (bootdev) to pass info and also use
  old macro in <sys/reboot.h> as ancient 4.4BSD did for simplicity
- add <machine/bootinfo.h> to define values as API to pass these info
- save boothowto and bootdev in registers right after zero'ing bss
- add MD device_register(9) to check booted_device per passed bootdev info
- merge old bootarg checks in rootconf() and luna68k_init() with
  tweaks for backward compatibility
  (direct boot a.out kernel from ROM monitor without bootloader still works)
This commit is contained in:
tsutsui 2014-01-11 08:07:16 +00:00
parent f536e5d427
commit 1a578d633f
4 changed files with 158 additions and 39 deletions

View File

@ -0,0 +1,51 @@
/* $NetBSD: bootinfo.h,v 1.1 2014/01/11 08:07:16 tsutsui Exp $ */
/*-
* Copyright (c) 2014 Izumi Tsutsui. 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.
*
* 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.
*/
#ifndef __LUNA68K_BOOTINFO_H_
#define __LUNA68K_BOOTINFO_H_
/*
* see also MAKEBOOTDEV macro in <sys/reboot.h>
*
* ADAPTOR: SPC or LANCE
* CONTROLLER: SPC and LANCE unit number
* UNIT: SCSI ID of SPC devices (XXX: no LUN support)
* PARTITION: booted partition of the boot disk
* TYPE: unused
*/
#define LUNA68K_BOOTADPT_SPC 0
#define LUNA68K_BOOTADPT_LANCE 1
#define LUNA68K_BOOTADPT_SPC0_PA 0xe1000000
#define LUNA68K_BOOTADPT_SPC1_PA 0xe1000040
#define LUNA68K_BOOTADPT_LANCE0_PA 0xf1000000
#ifdef _KERNEL
extern uint32_t bootdev;
#endif
#endif /* __LUNA68K_BOOTINFO_H_ */

View File

@ -1,4 +1,4 @@
/* $NetBSD: autoconf.c,v 1.14 2012/10/13 06:16:19 tsutsui Exp $ */
/* $NetBSD: autoconf.c,v 1.15 2014/01/11 08:07:16 tsutsui Exp $ */
/*-
* Copyright (c) 2000 The NetBSD Foundation, Inc.
@ -31,7 +31,7 @@
#include <sys/cdefs.h> /* RCS ID & Copyright macro defns */
__KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.14 2012/10/13 06:16:19 tsutsui Exp $");
__KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.15 2014/01/11 08:07:16 tsutsui Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@ -40,19 +40,33 @@ __KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.14 2012/10/13 06:16:19 tsutsui Exp $"
#include <sys/reboot.h>
#include <sys/device.h>
#include <machine/autoconf.h>
#include <machine/bootinfo.h>
#include <machine/disklabel.h>
#include <machine/cpu.h>
#include <dev/scsipi/scsi_all.h>
#include <dev/scsipi/scsipi_all.h>
#include <dev/scsipi/scsiconf.h>
#include <luna68k/luna68k/isr.h>
static uint booted_adpt, booted_ctlr, booted_unit, booted_part;
/*
* Determine mass storage and memory configuration for a machine.
*/
void
cpu_configure(void)
{
booted_device = NULL; /* set by device drivers (if found) */
booted_adpt = B_ADAPTOR(bootdev);
booted_ctlr = B_CONTROLLER(bootdev);
booted_unit = B_UNIT(bootdev);
booted_part = B_PARTITION(bootdev);
(void)splhigh();
isrinit();
if (config_rootfound("mainbus", NULL) == NULL)
@ -61,29 +75,63 @@ cpu_configure(void)
spl0();
}
void
device_register(device_t dev, void *aux)
{
static device_t booted_controller;
static bool bootdev_found;
/*
* Check booted device.
*/
if (bootdev_found)
return;
if (booted_adpt == LUNA68K_BOOTADPT_LANCE &&
device_is_a(dev, "le")) {
struct mainbus_attach_args *ma = aux;
if (booted_ctlr == 0 &&
ma->ma_addr == LUNA68K_BOOTADPT_LANCE0_PA) {
booted_device = dev;
bootdev_found = true;
}
return;
}
if (booted_adpt == LUNA68K_BOOTADPT_SPC &&
device_is_a(dev, "spc")) {
struct mainbus_attach_args *ma = aux;
if ((booted_ctlr == 0 &&
(u_int)ma->ma_addr == LUNA68K_BOOTADPT_SPC0_PA) ||
(booted_ctlr == 1 &&
(u_int)ma->ma_addr == LUNA68K_BOOTADPT_SPC1_PA)) {
booted_controller = dev;
}
return;
}
if (booted_controller != NULL &&
(device_is_a(dev, "sd") || device_is_a(dev, "cd"))) {
struct scsipibus_attach_args *sa = aux;
device_t parent = device_parent(dev);
if (device_parent(parent) != booted_controller)
return;
if (booted_unit != sa->sa_periph->periph_target)
return;
booted_device = dev;
booted_partition = booted_part;
bootdev_found = true;
return;
}
}
void
cpu_rootconf(void)
{
#if 1 /* XXX to be reworked with helps of 2nd stage loaders XXX */
int i;
const char *devname;
char *cp;
extern char bootarg[64];
cp = bootarg;
devname = "sd0";
for (i = 0; i < sizeof(bootarg); i++) {
if (*cp == '\0')
break;
if (*cp == 'E' && memcmp("ENADDR=", cp, 7) == 0) {
devname = "le0";
break;
}
cp++;
}
booted_device = device_find_by_xname(devname);
#endif
printf("boot device: %s\n",
(booted_device) ? device_xname(booted_device) : "<unknown>");

View File

@ -1,4 +1,4 @@
/* $NetBSD: locore.s,v 1.53 2013/09/23 17:02:18 tsutsui Exp $ */
/* $NetBSD: locore.s,v 1.54 2014/01/11 08:07:16 tsutsui Exp $ */
/*
* Copyright (c) 1988 University of Utah.
@ -102,12 +102,6 @@ ASENTRY_NOPROFILE(start)
ASRELOC(tmpstk,%a0)
movl %a0,%sp | give ourselves a temporary stack
#if 0 /* not sure useful values, need a bootloader tailored for us */
RELOC(boothowto,%a0)
movl %d7,%a0@ | save boothowto
RELOC(bootdev,%a0)
movl %d6,%a0@ | save bootdev
#endif
RELOC(edata,%a0) | clear out BSS
movl #_C_LABEL(end)-4,%d0 | (must be <= 256 kB)
subl #_C_LABEL(edata),%d0
@ -115,6 +109,10 @@ ASENTRY_NOPROFILE(start)
1: clrl %a0@+
dbra %d0,1b
RELOC(boothowto,%a0)
movl %d7,%a0@ | save boothowto
RELOC(bootdev,%a0)
movl %d6,%a0@ | save bootdev
RELOC(lowram,%a0)
movl %a5,%a0@ | store start of physical memory

View File

@ -1,4 +1,4 @@
/* $NetBSD: machdep.c,v 1.95 2013/01/26 15:46:24 tsutsui Exp $ */
/* $NetBSD: machdep.c,v 1.96 2014/01/11 08:07:16 tsutsui Exp $ */
/*-
* Copyright (c) 2000 The NetBSD Foundation, Inc.
@ -31,7 +31,7 @@
#include <sys/cdefs.h> /* RCS ID & Copyright macro defns */
__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.95 2013/01/26 15:46:24 tsutsui Exp $");
__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.96 2014/01/11 08:07:16 tsutsui Exp $");
#include "opt_ddb.h"
#include "opt_kgdb.h"
@ -75,6 +75,7 @@ __KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.95 2013/01/26 15:46:24 tsutsui Exp $")
#include <sys/sysctl.h>
#include <machine/bootinfo.h>
#include <machine/cpu.h>
#include <machine/reg.h>
#include <machine/pcb.h>
@ -194,8 +195,25 @@ luna68k_init(void)
sw1 ^= 0xff;
sysconsole = !(sw1 & 0x2); /* console selection */
/*
* Check if boothowto and bootdev values are passed by our bootloader.
*/
if ((bootdev & B_MAGICMASK) == B_DEVMAGIC) {
/* Valid value is set; no need to parse bootarg. */
return;
}
/*
* No valid bootdev value is set.
* Assume we are booted by ROM monitor directly using a.out kernel
* and we have to parse bootarg passed from the monitor to set
* proper boothowto and check netboot.
*/
/* set default to "sd0a" with no howto flags */
bootdev = MAKEBOOTDEV(0, LUNA68K_BOOTADPT_SPC, 0, 0, 0);
boothowto = 0;
i = 0;
/*
* 'bootarg' on LUNA has:
* "<args of x command> ENADDR=<addr> HOST=<host> SERVER=<name>"
@ -207,15 +225,19 @@ luna68k_init(void)
*
* NetBSD/luna68k cares only the first argment; any of "sda".
*/
for (cp = bootarg; *cp != ' ' && *cp != 0; cp++) {
BOOT_FLAG(*cp, boothowto);
if (i++ >= sizeof(bootarg))
break;
bootarg[63] = '\0';
for (cp = bootarg; *cp != '\0'; cp++) {
if (*cp == '-') {
char c;
while ((c = *cp) != '\0' && c != ' ') {
BOOT_FLAG(c, boothowto);
cp++;
}
} else if (*cp == 'E' && memcmp("ENADDR=", cp, 7) == 0) {
bootdev =
MAKEBOOTDEV(0, LUNA68K_BOOTADPT_LANCE, 0, 0, 0);
}
}
#if 0 /* overload 1:sw1, which now means 'go ROM monitor' after poweron */
if (boothowto == 0)
boothowto = (sw1 & 0x1) ? RB_SINGLE : 0;
#endif
}
/*