1 /* $NetBSD: boot1.c,v 1.1 2006/09/01 21:26:19 uwe Exp $ */
4 * Copyright (c) 2003 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
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.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
32 #include <sys/cdefs.h>
33 __RCSID("$NetBSD: boot1.c,v 1.1 2006/09/01 21:26:19 uwe Exp $");
35 #include <lib/libsa/stand.h>
36 #include <lib/libkern/libkern.h>
38 #include <sys/param.h>
39 #include <sys/bootblock.h>
40 #include <sys/disklabel.h>
41 #include <dev/raidframe/raidframevar.h> /* For RF_PROTECTED_SECTORS */
43 #include "biosdisk_ll.h"
46 #define STR(x) XSTR(x)
48 static uint32_t bios_sector
;
50 const char *boot1(uint32_t *);
51 void putstr(const char *str
);
54 extern struct disklabel ptn_disklabel
;
57 boot1(uint32_t *sector
)
62 bios_sector
= *sector
;
64 putstr("\r\nNetBSD/" MACHINE
" " STR(FS
) " Primary Bootstrap\r\n");
68 * We default to the filesystem at the start of the
76 * Maybe the filesystem is enclosed in a raid set.
77 * add in size of raidframe header and try again.
78 * (Maybe this should only be done if the filesystem
79 * magic number is absent.)
81 bios_sector
+= RF_PROTECTED_SECTORS
;
87 * Nothing at the start of the MBR partition, fallback on
88 * partition 'a' from the disklabel in this MBR partition.
90 if (ptn_disklabel
.d_magic
!= DISKMAGIC
)
92 if (ptn_disklabel
.d_magic2
!= DISKMAGIC
)
94 if (ptn_disklabel
.d_partitions
[0].p_fstype
== FS_UNUSED
)
97 bios_sector
= ptn_disklabel
.d_partitions
[0].p_offset
;
98 *sector
= bios_sector
;
99 if (ptn_disklabel
.d_partitions
[0].p_fstype
== FS_RAID
)
100 bios_sector
+= RF_PROTECTED_SECTORS
;
101 fd
= open("boot", 0);
104 if (fd
== -1 || fstat(fd
, &sb
) == -1)
105 return "Can't open /boot.\r\n";
108 if (sb
.st_size
> SECONDARY_MAX_LOAD
)
109 return "/boot too large.\r\n";
112 if (read(fd
, (void *)SECONDARY_LOAD_ADDRESS
, sb
.st_size
) != sb
.st_size
)
113 return "/boot load failed.\r\n";
115 if (*(uint32_t *)(SECONDARY_LOAD_ADDRESS
+ 4) != LANDISK_BOOT_MAGIC_2
)
116 return "Invalid /boot file format.\r\n";
122 blkdevstrategy(void *devdata
, int flag
, daddr_t dblk
, size_t size
, void *buf
, size_t *rsize
)
128 if (size
& (BIOSDISK_SECSIZE
- 1))
134 if (size
!= 0 && readsects(0x40, bios_sector
+ dblk
, buf
,
135 size
/ BIOSDISK_SECSIZE
) != 0)