| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: i386.c,v 1.37 2011/08/14 17:50:17 christos Exp $ */ | | 1 | /* $NetBSD: i386.c,v 1.38 2012/03/10 18:42:18 dsl Exp $ */ |
2 | | | 2 | |
3 | /*- | | 3 | /*- |
4 | * Copyright (c) 2003 The NetBSD Foundation, Inc. | | 4 | * Copyright (c) 2003 The NetBSD Foundation, Inc. |
5 | * All rights reserved. | | 5 | * All rights reserved. |
6 | * | | 6 | * |
7 | * This code is derived from software contributed to The NetBSD Foundation | | 7 | * This code is derived from software contributed to The NetBSD Foundation |
8 | * by David Laight. | | 8 | * by David Laight. |
9 | * | | 9 | * |
10 | * Redistribution and use in source and binary forms, with or without | | 10 | * Redistribution and use in source and binary forms, with or without |
11 | * modification, are permitted provided that the following conditions | | 11 | * modification, are permitted provided that the following conditions |
12 | * are met: | | 12 | * are met: |
13 | * 1. Redistributions of source code must retain the above copyright | | 13 | * 1. Redistributions of source code must retain the above copyright |
14 | * notice, this list of conditions and the following disclaimer. | | 14 | * notice, this list of conditions and the following disclaimer. |
| @@ -25,27 +25,27 @@ | | | @@ -25,27 +25,27 @@ |
25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | | 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 | | 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | | 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 | | 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
29 | * POSSIBILITY OF SUCH DAMAGE. | | 29 | * POSSIBILITY OF SUCH DAMAGE. |
30 | */ | | 30 | */ |
31 | | | 31 | |
32 | #if HAVE_NBTOOL_CONFIG_H | | 32 | #if HAVE_NBTOOL_CONFIG_H |
33 | #include "nbtool_config.h" | | 33 | #include "nbtool_config.h" |
34 | #endif | | 34 | #endif |
35 | | | 35 | |
36 | #include <sys/cdefs.h> | | 36 | #include <sys/cdefs.h> |
37 | #if !defined(__lint) | | 37 | #if !defined(__lint) |
38 | __RCSID("$NetBSD: i386.c,v 1.37 2011/08/14 17:50:17 christos Exp $"); | | 38 | __RCSID("$NetBSD: i386.c,v 1.38 2012/03/10 18:42:18 dsl Exp $"); |
39 | #endif /* !__lint */ | | 39 | #endif /* !__lint */ |
40 | | | 40 | |
41 | #include <sys/param.h> | | 41 | #include <sys/param.h> |
42 | #ifndef HAVE_NBTOOL_CONFIG_H | | 42 | #ifndef HAVE_NBTOOL_CONFIG_H |
43 | #include <sys/ioctl.h> | | 43 | #include <sys/ioctl.h> |
44 | #include <sys/dkio.h> | | 44 | #include <sys/dkio.h> |
45 | #endif | | 45 | #endif |
46 | | | 46 | |
47 | #include <assert.h> | | 47 | #include <assert.h> |
48 | #include <errno.h> | | 48 | #include <errno.h> |
49 | #include <err.h> | | 49 | #include <err.h> |
50 | #include <md5.h> | | 50 | #include <md5.h> |
51 | #include <stddef.h> | | 51 | #include <stddef.h> |
| @@ -69,33 +69,35 @@ static const struct console_name { | | | @@ -69,33 +69,35 @@ static const struct console_name { |
69 | { "com1kbd", 6 /* CONSDEV_COM1KBD */ }, | | 69 | { "com1kbd", 6 /* CONSDEV_COM1KBD */ }, |
70 | { "com2kbd", 7 /* CONSDEV_COM2KBD */ }, | | 70 | { "com2kbd", 7 /* CONSDEV_COM2KBD */ }, |
71 | { "com3kbd", 8 /* CONSDEV_COM3KBD */ }, | | 71 | { "com3kbd", 8 /* CONSDEV_COM3KBD */ }, |
72 | { "auto", -1 /* CONSDEV_AUTO */ }, | | 72 | { "auto", -1 /* CONSDEV_AUTO */ }, |
73 | }; | | 73 | }; |
74 | | | 74 | |
75 | static int i386_setboot(ib_params *); | | 75 | static int i386_setboot(ib_params *); |
76 | static int i386_editboot(ib_params *); | | 76 | static int i386_editboot(ib_params *); |
77 | | | 77 | |
78 | struct ib_mach ib_mach_i386 = | | 78 | struct ib_mach ib_mach_i386 = |
79 | { "i386", i386_setboot, no_clearboot, i386_editboot, | | 79 | { "i386", i386_setboot, no_clearboot, i386_editboot, |
80 | IB_RESETVIDEO | IB_CONSOLE | IB_CONSPEED | IB_CONSADDR | | | 80 | IB_RESETVIDEO | IB_CONSOLE | IB_CONSPEED | IB_CONSADDR | |
81 | IB_KEYMAP | IB_PASSWORD | IB_TIMEOUT | | | 81 | IB_KEYMAP | IB_PASSWORD | IB_TIMEOUT | |
82 | IB_MODULES | IB_BOOTCONF }; | | 82 | IB_MODULES | IB_BOOTCONF | |
| | | 83 | IB_STAGE1START }; |
83 | | | 84 | |
84 | struct ib_mach ib_mach_amd64 = | | 85 | struct ib_mach ib_mach_amd64 = |
85 | { "amd64", i386_setboot, no_clearboot, i386_editboot, | | 86 | { "amd64", i386_setboot, no_clearboot, i386_editboot, |
86 | IB_RESETVIDEO | IB_CONSOLE | IB_CONSPEED | IB_CONSADDR | | | 87 | IB_RESETVIDEO | IB_CONSOLE | IB_CONSPEED | IB_CONSADDR | |
87 | IB_KEYMAP | IB_PASSWORD | IB_TIMEOUT | | | 88 | IB_KEYMAP | IB_PASSWORD | IB_TIMEOUT | |
88 | IB_MODULES | IB_BOOTCONF }; | | 89 | IB_MODULES | IB_BOOTCONF | |
| | | 90 | IB_STAGE1START }; |
89 | | | 91 | |
90 | /* | | 92 | /* |
91 | * Attempting to write the 'labelsector' (or a sector near it - within 8k?) | | 93 | * Attempting to write the 'labelsector' (or a sector near it - within 8k?) |
92 | * using the non-raw disk device fails silently. This can be detected (today) | | 94 | * using the non-raw disk device fails silently. This can be detected (today) |
93 | * by doing a fsync() and a read back. | | 95 | * by doing a fsync() and a read back. |
94 | * This is very likely to affect installboot, indeed the code may need to | | 96 | * This is very likely to affect installboot, indeed the code may need to |
95 | * be written into the 'labelsector' itself - especially on non-512 byte media. | | 97 | * be written into the 'labelsector' itself - especially on non-512 byte media. |
96 | * We do all writes with a read verify. | | 98 | * We do all writes with a read verify. |
97 | * If EROFS is returned we also try to enable writes to the label sector. | | 99 | * If EROFS is returned we also try to enable writes to the label sector. |
98 | * (Maybe these functions should be in the generic part of installboot.) | | 100 | * (Maybe these functions should be in the generic part of installboot.) |
99 | */ | | 101 | */ |
100 | static int | | 102 | static int |
101 | pwrite_validate(int fd, const void *buf, size_t n_bytes, off_t offset) | | 103 | pwrite_validate(int fd, const void *buf, size_t n_bytes, off_t offset) |
| @@ -430,26 +432,29 @@ i386_setboot(ib_params *params) | | | @@ -430,26 +432,29 @@ i386_setboot(ib_params *params) |
430 | /* Check we have enough space for the old bpb */ | | 432 | /* Check we have enough space for the old bpb */ |
431 | if (disk_buf.b[1] > bootstrap.b[1]) { | | 433 | if (disk_buf.b[1] > bootstrap.b[1]) { |
432 | /* old BPB is larger, allow if extra zeros */ | | 434 | /* old BPB is larger, allow if extra zeros */ |
433 | if (!is_zero(disk_buf.b + 2 + bootstrap.b[1], | | 435 | if (!is_zero(disk_buf.b + 2 + bootstrap.b[1], |
434 | disk_buf.b[1] - bootstrap.b[1])) { | | 436 | disk_buf.b[1] - bootstrap.b[1])) { |
435 | warnx("Old BPB too big" USE_F); | | 437 | warnx("Old BPB too big" USE_F); |
436 | return 0; | | 438 | return 0; |
437 | } | | 439 | } |
438 | u = bootstrap.b[1]; | | 440 | u = bootstrap.b[1]; |
439 | } else { | | 441 | } else { |
440 | /* Old BPB is shorter, leave zero filled */ | | 442 | /* Old BPB is shorter, leave zero filled */ |
441 | u = disk_buf.b[1]; | | 443 | u = disk_buf.b[1]; |
442 | } | | 444 | } |
| | | 445 | if (params->s1start != 0) |
| | | 446 | /* Fixup physical offset of filesytem */ |
| | | 447 | bpb->bpbHiddenSecs = htole32(params->s1start); |
443 | memcpy(bootstrap.b + 2, disk_buf.b + 2, u); | | 448 | memcpy(bootstrap.b + 2, disk_buf.b + 2, u); |
444 | } | | 449 | } |
445 | #undef USE_F | | 450 | #undef USE_F |
446 | } | | 451 | } |
447 | | | 452 | |
448 | /* | | 453 | /* |
449 | * Fill in any user-specified options into the | | 454 | * Fill in any user-specified options into the |
450 | * struct x86_boot_params | | 455 | * struct x86_boot_params |
451 | * that follows the magic number. | | 456 | * that follows the magic number. |
452 | * See sys/arch/i386/stand/bootxx/bootxx.S for more information. | | 457 | * See sys/arch/i386/stand/bootxx/bootxx.S for more information. |
453 | */ | | 458 | */ |
454 | if (update_i386_boot_params(params, (void *)(magic + 1))) | | 459 | if (update_i386_boot_params(params, (void *)(magic + 1))) |
455 | return 0; | | 460 | return 0; |