No empty .Rs/.Re
[netbsd-mini2440.git] / sys / arch / landisk / stand / bootxx / boot1.c
blob842ba073fdfc0648a88e3bd4b7fff3fcd1c5e991
1 /* $NetBSD: boot1.c,v 1.1 2006/09/01 21:26:19 uwe Exp $ */
3 /*-
4 * Copyright (c) 2003 The NetBSD Foundation, Inc.
5 * All rights reserved.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by David Laight.
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.
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"
45 #define XSTR(x) #x
46 #define STR(x) XSTR(x)
48 static uint32_t bios_sector;
50 const char *boot1(uint32_t *);
51 void putstr(const char *str);
52 int raise(int sig);
54 extern struct disklabel ptn_disklabel;
56 const char *
57 boot1(uint32_t *sector)
59 struct stat sb;
60 int fd;
62 bios_sector = *sector;
64 putstr("\r\nNetBSD/" MACHINE " " STR(FS) " Primary Bootstrap\r\n");
66 do {
68 * We default to the filesystem at the start of the
69 * MBR partition
71 fd = open("boot", 0);
72 if (fd != -1)
73 break;
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;
82 fd = open("boot", 0);
83 if (fd != -1)
84 break;
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)
91 break;
92 if (ptn_disklabel.d_magic2 != DISKMAGIC)
93 break;
94 if (ptn_disklabel.d_partitions[0].p_fstype == FS_UNUSED)
95 break;
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);
102 } while (0);
104 if (fd == -1 || fstat(fd, &sb) == -1)
105 return "Can't open /boot.\r\n";
107 #if 0
108 if (sb.st_size > SECONDARY_MAX_LOAD)
109 return "/boot too large.\r\n";
110 #endif
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";
118 return 0;
122 blkdevstrategy(void *devdata, int flag, daddr_t dblk, size_t size, void *buf, size_t *rsize)
125 if (flag != F_READ)
126 return EROFS;
128 if (size & (BIOSDISK_SECSIZE - 1))
129 return EINVAL;
131 if (rsize)
132 *rsize = size;
134 if (size != 0 && readsects(0x40, bios_sector + dblk, buf,
135 size / BIOSDISK_SECSIZE) != 0)
136 return EIO;
138 return 0;
141 /*ARGUSED*/
143 raise(int sig)
146 return 0;