No empty .Rs/.Re
[netbsd-mini2440.git] / sys / dev / md_root.c
blob491a514e185f740fd823058091e3c5b82a5678c5
1 /* $NetBSD: md_root.c,v 1.16 2009/02/06 18:50:29 jym Exp $ */
3 /*-
4 * Copyright (c) 1996 The NetBSD Foundation, Inc.
5 * All rights reserved.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Gordon W. Ross.
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 __KERNEL_RCSID(0, "$NetBSD: md_root.c,v 1.16 2009/02/06 18:50:29 jym Exp $");
35 #include "opt_md.h"
37 #include <sys/param.h>
38 #include <sys/systm.h>
39 #include <sys/reboot.h>
41 #include <dev/md.h>
43 #ifdef MEMORY_DISK_DYNAMIC
44 #ifdef MEMORY_DISK_IMAGE
45 #error MEMORY_DISK_DYNAMIC is not compatible with MEMORY_DISK_IMAGE
46 #endif
47 size_t md_root_size;
48 char *md_root_image;
49 #else /* MEMORY_DISK_DYNAMIC */
51 #ifdef MEMORY_DISK_IMAGE
52 #ifdef MEMORY_DISK_ROOT_SIZE
53 #error MEMORY_DISK_ROOT_SIZE is not compatible with MEMORY_DISK_IMAGE
54 #endif
55 char md_root_image[] = {
56 #include "md_root_image.h"
58 uint32_t md_root_size = sizeof(md_root_image) & ~(DEV_BSIZE - 1);
60 #else /* MEMORY_DISK_IMAGE */
62 #ifndef MEMORY_DISK_ROOT_SIZE
63 #define MEMORY_DISK_ROOT_SIZE 512
64 #endif
65 #define ROOTBYTES (MEMORY_DISK_ROOT_SIZE << DEV_BSHIFT)
68 * This array will be patched to contain a file-system image.
69 * See the program mdsetimage(8) for details.
71 uint32_t md_root_size = ROOTBYTES;
72 char md_root_image[ROOTBYTES] = "|This is the root ramdisk!\n";
73 #endif /* MEMORY_DISK_IMAGE */
74 #endif /* MEMORY_DISK_DYNAMIC */
76 #ifndef MEMORY_DISK_RBFLAGS
77 #define MEMORY_DISK_RBFLAGS RB_AUTOBOOT /* default boot mode */
78 #endif
80 #ifdef MEMORY_DISK_DYNAMIC
81 void
82 md_root_setconf(char *addr, size_t size)
85 md_is_root = 1;
86 md_root_image = addr;
87 md_root_size = size;
89 #endif /* MEMORY_DISK_DYNAMIC */
92 * This is called during pseudo-device attachment.
94 #define PBUFLEN sizeof("99999 KB")
96 void
97 md_attach_hook(int unit, struct md_conf *md)
99 char pbuf[PBUFLEN];
101 if (unit == 0 && md_is_root) {
102 /* Setup root ramdisk */
103 md->md_addr = (void *)md_root_image;
104 md->md_size = (size_t)md_root_size;
105 md->md_type = MD_KMEM_FIXED;
106 format_bytes(pbuf, sizeof(pbuf), md->md_size);
107 aprint_verbose("md%d: internal %s image area\n", unit, pbuf);
112 * This is called during open (i.e. mountroot)
114 void
115 md_open_hook(int unit, struct md_conf *md)
118 if (unit == 0 && md_is_root) {
119 boothowto |= MEMORY_DISK_RBFLAGS;