xref: /freebsd/stand/common/metadata.c (revision 20b23ae7)
1d3e1307bSJustin Hibbits /*-
2d3e1307bSJustin Hibbits  * Copyright (c) 1998 Michael Smith <msmith@freebsd.org>
3d3e1307bSJustin Hibbits  * All rights reserved.
4d3e1307bSJustin Hibbits  *
5d3e1307bSJustin Hibbits  * Redistribution and use in source and binary forms, with or without
6d3e1307bSJustin Hibbits  * modification, are permitted provided that the following conditions
7d3e1307bSJustin Hibbits  * are met:
8d3e1307bSJustin Hibbits  * 1. Redistributions of source code must retain the above copyright
9d3e1307bSJustin Hibbits  *    notice, this list of conditions and the following disclaimer.
10d3e1307bSJustin Hibbits  * 2. Redistributions in binary form must reproduce the above copyright
11d3e1307bSJustin Hibbits  *    notice, this list of conditions and the following disclaimer in the
12d3e1307bSJustin Hibbits  *    documentation and/or other materials provided with the distribution.
13d3e1307bSJustin Hibbits  *
14d3e1307bSJustin Hibbits  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15d3e1307bSJustin Hibbits  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16d3e1307bSJustin Hibbits  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17d3e1307bSJustin Hibbits  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18d3e1307bSJustin Hibbits  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19d3e1307bSJustin Hibbits  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20d3e1307bSJustin Hibbits  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21d3e1307bSJustin Hibbits  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22d3e1307bSJustin Hibbits  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23d3e1307bSJustin Hibbits  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24d3e1307bSJustin Hibbits  * SUCH DAMAGE.
25d3e1307bSJustin Hibbits  *
26d3e1307bSJustin Hibbits  *	from: FreeBSD: src/sys/boot/sparc64/loader/metadata.c,v 1.6
27d3e1307bSJustin Hibbits  */
28d3e1307bSJustin Hibbits 
29d3e1307bSJustin Hibbits #include <sys/cdefs.h>
30d3e1307bSJustin Hibbits __FBSDID("$FreeBSD$");
31d3e1307bSJustin Hibbits 
32d3e1307bSJustin Hibbits #include <stand.h>
33d3e1307bSJustin Hibbits #include <sys/param.h>
34d3e1307bSJustin Hibbits #include <sys/linker.h>
354569e913SWarner Losh #include <sys/boot.h>
3628ee318dSKyle Evans #include <sys/reboot.h>
37d3e1307bSJustin Hibbits #if defined(LOADER_FDT_SUPPORT)
38d3e1307bSJustin Hibbits #include <fdt_platform.h>
39d3e1307bSJustin Hibbits #endif
40d3e1307bSJustin Hibbits 
414daa199dSKyle Evans #ifdef __arm__
424daa199dSKyle Evans #include <machine/elf.h>
434daa199dSKyle Evans #endif
44d3e1307bSJustin Hibbits #include <machine/metadata.h>
45d3e1307bSJustin Hibbits 
46d3e1307bSJustin Hibbits #include "bootstrap.h"
47d3e1307bSJustin Hibbits 
48c1418270SIan Lepore #ifdef LOADER_GELI_SUPPORT
49c1418270SIan Lepore #include "geliboot.h"
50c1418270SIan Lepore #endif
51c1418270SIan Lepore 
52dd5dbb31SMarius Strobl static int
53d3e1307bSJustin Hibbits md_getboothowto(char *kargs)
54d3e1307bSJustin Hibbits {
55d3e1307bSJustin Hibbits     int		howto;
56d3e1307bSJustin Hibbits 
57d3e1307bSJustin Hibbits     /* Parse kargs */
584569e913SWarner Losh     howto = boot_parse_cmdline(kargs);
59c96ac12eSWarner Losh     howto |= boot_env_to_howto();
60d3e1307bSJustin Hibbits     if (!strcmp(getenv("console"), "comconsole"))
61d3e1307bSJustin Hibbits 	howto |= RB_SERIAL;
62d3e1307bSJustin Hibbits     if (!strcmp(getenv("console"), "nullconsole"))
63d3e1307bSJustin Hibbits 	howto |= RB_MUTE;
64d3e1307bSJustin Hibbits     return(howto);
65d3e1307bSJustin Hibbits }
66d3e1307bSJustin Hibbits 
67d3e1307bSJustin Hibbits /*
68d3e1307bSJustin Hibbits  * Copy the environment into the load area starting at (addr).
69d3e1307bSJustin Hibbits  * Each variable is formatted as <name>=<value>, with a single nul
70d3e1307bSJustin Hibbits  * separating each variable, and a double nul terminating the environment.
71d3e1307bSJustin Hibbits  */
72d3e1307bSJustin Hibbits static vm_offset_t
73d3e1307bSJustin Hibbits md_copyenv(vm_offset_t addr)
74d3e1307bSJustin Hibbits {
75d3e1307bSJustin Hibbits     struct env_var	*ep;
76d3e1307bSJustin Hibbits 
77d3e1307bSJustin Hibbits     /* traverse the environment */
78d3e1307bSJustin Hibbits     for (ep = environ; ep != NULL; ep = ep->ev_next) {
79d3e1307bSJustin Hibbits 	archsw.arch_copyin(ep->ev_name, addr, strlen(ep->ev_name));
80d3e1307bSJustin Hibbits 	addr += strlen(ep->ev_name);
81d3e1307bSJustin Hibbits 	archsw.arch_copyin("=", addr, 1);
82d3e1307bSJustin Hibbits 	addr++;
83d3e1307bSJustin Hibbits 	if (ep->ev_value != NULL) {
84d3e1307bSJustin Hibbits 	    archsw.arch_copyin(ep->ev_value, addr, strlen(ep->ev_value));
85d3e1307bSJustin Hibbits 	    addr += strlen(ep->ev_value);
86d3e1307bSJustin Hibbits 	}
87d3e1307bSJustin Hibbits 	archsw.arch_copyin("", addr, 1);
88d3e1307bSJustin Hibbits 	addr++;
89d3e1307bSJustin Hibbits     }
90d3e1307bSJustin Hibbits     archsw.arch_copyin("", addr, 1);
91d3e1307bSJustin Hibbits     addr++;
92d3e1307bSJustin Hibbits     return(addr);
93d3e1307bSJustin Hibbits }
94d3e1307bSJustin Hibbits 
95d3e1307bSJustin Hibbits /*
96d3e1307bSJustin Hibbits  * Copy module-related data into the load area, where it can be
97d3e1307bSJustin Hibbits  * used as a directory for loaded modules.
98d3e1307bSJustin Hibbits  *
99d3e1307bSJustin Hibbits  * Module data is presented in a self-describing format.  Each datum
100d3e1307bSJustin Hibbits  * is preceded by a 32-bit identifier and a 32-bit size field.
101d3e1307bSJustin Hibbits  *
102d3e1307bSJustin Hibbits  * Currently, the following data are saved:
103d3e1307bSJustin Hibbits  *
104d3e1307bSJustin Hibbits  * MOD_NAME	(variable)		module name (string)
105d3e1307bSJustin Hibbits  * MOD_TYPE	(variable)		module type (string)
106d3e1307bSJustin Hibbits  * MOD_ARGS	(variable)		module parameters (string)
107d3e1307bSJustin Hibbits  * MOD_ADDR	sizeof(vm_offset_t)	module load address
108d3e1307bSJustin Hibbits  * MOD_SIZE	sizeof(size_t)		module size
109d3e1307bSJustin Hibbits  * MOD_METADATA	(variable)		type-specific metadata
110d3e1307bSJustin Hibbits  */
111d3e1307bSJustin Hibbits 
112d3e1307bSJustin Hibbits static int align;
113d3e1307bSJustin Hibbits 
114d3e1307bSJustin Hibbits #define COPY32(v, a, c) {			\
11556e53cb8SWarner Losh     uint32_t	x = (v);			\
116d3e1307bSJustin Hibbits     if (c)					\
117d3e1307bSJustin Hibbits         archsw.arch_copyin(&x, a, sizeof(x));	\
118d3e1307bSJustin Hibbits     a += sizeof(x);				\
119d3e1307bSJustin Hibbits }
120d3e1307bSJustin Hibbits 
121d3e1307bSJustin Hibbits #define MOD_STR(t, a, s, c) {			\
122d3e1307bSJustin Hibbits     COPY32(t, a, c);				\
123d3e1307bSJustin Hibbits     COPY32(strlen(s) + 1, a, c)			\
124d3e1307bSJustin Hibbits     if (c)					\
125d3e1307bSJustin Hibbits         archsw.arch_copyin(s, a, strlen(s) + 1);\
126d3e1307bSJustin Hibbits     a += roundup(strlen(s) + 1, align);		\
127d3e1307bSJustin Hibbits }
128d3e1307bSJustin Hibbits 
129d3e1307bSJustin Hibbits #define MOD_NAME(a, s, c)	MOD_STR(MODINFO_NAME, a, s, c)
130d3e1307bSJustin Hibbits #define MOD_TYPE(a, s, c)	MOD_STR(MODINFO_TYPE, a, s, c)
131d3e1307bSJustin Hibbits #define MOD_ARGS(a, s, c)	MOD_STR(MODINFO_ARGS, a, s, c)
132d3e1307bSJustin Hibbits 
133d3e1307bSJustin Hibbits #define MOD_VAR(t, a, s, c) {			\
134d3e1307bSJustin Hibbits     COPY32(t, a, c);				\
135d3e1307bSJustin Hibbits     COPY32(sizeof(s), a, c);			\
136d3e1307bSJustin Hibbits     if (c)					\
137d3e1307bSJustin Hibbits         archsw.arch_copyin(&s, a, sizeof(s));	\
138d3e1307bSJustin Hibbits     a += roundup(sizeof(s), align);		\
139d3e1307bSJustin Hibbits }
140d3e1307bSJustin Hibbits 
141d3e1307bSJustin Hibbits #define MOD_ADDR(a, s, c)	MOD_VAR(MODINFO_ADDR, a, s, c)
142d3e1307bSJustin Hibbits #define MOD_SIZE(a, s, c)	MOD_VAR(MODINFO_SIZE, a, s, c)
143d3e1307bSJustin Hibbits 
144d3e1307bSJustin Hibbits #define MOD_METADATA(a, mm, c) {		\
145d3e1307bSJustin Hibbits     COPY32(MODINFO_METADATA | mm->md_type, a, c);\
146d3e1307bSJustin Hibbits     COPY32(mm->md_size, a, c);			\
147d3e1307bSJustin Hibbits     if (c)					\
148d3e1307bSJustin Hibbits         archsw.arch_copyin(mm->md_data, a, mm->md_size);\
149d3e1307bSJustin Hibbits     a += roundup(mm->md_size, align);		\
150d3e1307bSJustin Hibbits }
151d3e1307bSJustin Hibbits 
152d3e1307bSJustin Hibbits #define MOD_END(a, c) {				\
153d3e1307bSJustin Hibbits     COPY32(MODINFO_END, a, c);			\
154d3e1307bSJustin Hibbits     COPY32(0, a, c);				\
155d3e1307bSJustin Hibbits }
156d3e1307bSJustin Hibbits 
157d3e1307bSJustin Hibbits static vm_offset_t
158d3e1307bSJustin Hibbits md_copymodules(vm_offset_t addr, int kern64)
159d3e1307bSJustin Hibbits {
160d3e1307bSJustin Hibbits     struct preloaded_file	*fp;
161d3e1307bSJustin Hibbits     struct file_metadata	*md;
162d3e1307bSJustin Hibbits     uint64_t			scratch64;
1637feea407SIan Lepore     uint32_t			scratch32;
164d3e1307bSJustin Hibbits     int				c;
165d3e1307bSJustin Hibbits 
166d3e1307bSJustin Hibbits     c = addr != 0;
167d3e1307bSJustin Hibbits     /* start with the first module on the list, should be the kernel */
168d3e1307bSJustin Hibbits     for (fp = file_findfile(NULL, NULL); fp != NULL; fp = fp->f_next) {
169d3e1307bSJustin Hibbits 
170d3e1307bSJustin Hibbits 	MOD_NAME(addr, fp->f_name, c);	/* this field must come first */
171d3e1307bSJustin Hibbits 	MOD_TYPE(addr, fp->f_type, c);
172d3e1307bSJustin Hibbits 	if (fp->f_args)
173d3e1307bSJustin Hibbits 	    MOD_ARGS(addr, fp->f_args, c);
174d3e1307bSJustin Hibbits 	if (kern64) {
175d3e1307bSJustin Hibbits 		scratch64 = fp->f_addr;
176d3e1307bSJustin Hibbits 		MOD_ADDR(addr, scratch64, c);
177d3e1307bSJustin Hibbits 		scratch64 = fp->f_size;
178d3e1307bSJustin Hibbits 		MOD_SIZE(addr, scratch64, c);
179d3e1307bSJustin Hibbits 	} else {
1807feea407SIan Lepore 		scratch32 = fp->f_addr;
1817feea407SIan Lepore #ifdef __arm__
1827feea407SIan Lepore 		scratch32 -= __elfN(relocation_offset);
1837feea407SIan Lepore #endif
1847feea407SIan Lepore 		MOD_ADDR(addr, scratch32, c);
185d3e1307bSJustin Hibbits 		MOD_SIZE(addr, fp->f_size, c);
186d3e1307bSJustin Hibbits 	}
187d3e1307bSJustin Hibbits 	for (md = fp->f_metadata; md != NULL; md = md->md_next) {
188d3e1307bSJustin Hibbits 	    if (!(md->md_type & MODINFOMD_NOCOPY)) {
189d3e1307bSJustin Hibbits 		MOD_METADATA(addr, md, c);
190d3e1307bSJustin Hibbits 	    }
191d3e1307bSJustin Hibbits 	}
192d3e1307bSJustin Hibbits     }
193d3e1307bSJustin Hibbits     MOD_END(addr, c);
194d3e1307bSJustin Hibbits     return(addr);
195d3e1307bSJustin Hibbits }
196d3e1307bSJustin Hibbits 
197d3e1307bSJustin Hibbits /*
198d3e1307bSJustin Hibbits  * Load the information expected by a kernel.
199d3e1307bSJustin Hibbits  *
200d3e1307bSJustin Hibbits  * - The 'boothowto' argument is constructed
201d3e1307bSJustin Hibbits  * - The 'bootdev' argument is constructed
202d3e1307bSJustin Hibbits  * - The kernel environment is copied into kernel space.
203d3e1307bSJustin Hibbits  * - Module metadata are formatted and placed in kernel space.
204d3e1307bSJustin Hibbits  */
205dd5dbb31SMarius Strobl static int
206d3e1307bSJustin Hibbits md_load_dual(char *args, vm_offset_t *modulep, vm_offset_t *dtb, int kern64)
207d3e1307bSJustin Hibbits {
208d3e1307bSJustin Hibbits     struct preloaded_file	*kfp;
209d3e1307bSJustin Hibbits     struct preloaded_file	*xp;
210d3e1307bSJustin Hibbits     struct file_metadata	*md;
211d3e1307bSJustin Hibbits     vm_offset_t			kernend;
212d3e1307bSJustin Hibbits     vm_offset_t			addr;
213d3e1307bSJustin Hibbits     vm_offset_t			envp;
214d3e1307bSJustin Hibbits #if defined(LOADER_FDT_SUPPORT)
215d3e1307bSJustin Hibbits     vm_offset_t			fdtp;
216d3e1307bSJustin Hibbits #endif
217d3e1307bSJustin Hibbits     vm_offset_t			size;
218d3e1307bSJustin Hibbits     uint64_t			scratch64;
219d3e1307bSJustin Hibbits     char			*rootdevname;
220d3e1307bSJustin Hibbits     int				howto;
2214daa199dSKyle Evans #ifdef __arm__
2224daa199dSKyle Evans     vm_offset_t			vaddr;
2234daa199dSKyle Evans     int				i;
2244daa199dSKyle Evans 
2254daa199dSKyle Evans 	/*
2264daa199dSKyle Evans 	 * These metadata addreses must be converted for kernel after
2274daa199dSKyle Evans 	 * relocation.
2284daa199dSKyle Evans 	 */
2294daa199dSKyle Evans     uint32_t			mdt[] = {
2304daa199dSKyle Evans 	    MODINFOMD_SSYM, MODINFOMD_ESYM, MODINFOMD_KERNEND,
2314daa199dSKyle Evans 	    MODINFOMD_ENVP,
2324daa199dSKyle Evans #if defined(LOADER_FDT_SUPPORT)
2334daa199dSKyle Evans 	    MODINFOMD_DTBP
2344daa199dSKyle Evans #endif
2354daa199dSKyle Evans     };
2364daa199dSKyle Evans #endif
237d3e1307bSJustin Hibbits 
238d3e1307bSJustin Hibbits     align = kern64 ? 8 : 4;
239d3e1307bSJustin Hibbits     howto = md_getboothowto(args);
240d3e1307bSJustin Hibbits 
241d3e1307bSJustin Hibbits     /*
242d3e1307bSJustin Hibbits      * Allow the environment variable 'rootdev' to override the supplied
243d3e1307bSJustin Hibbits      * device. This should perhaps go to MI code and/or have $rootdev
244d3e1307bSJustin Hibbits      * tested/set by MI code before launching the kernel.
245d3e1307bSJustin Hibbits      */
246d3e1307bSJustin Hibbits     rootdevname = getenv("rootdev");
247d3e1307bSJustin Hibbits     if (rootdevname == NULL)
248d3e1307bSJustin Hibbits 	rootdevname = getenv("currdev");
249d3e1307bSJustin Hibbits     /* Try reading the /etc/fstab file to select the root device */
250d3e1307bSJustin Hibbits     getrootmount(rootdevname);
251d3e1307bSJustin Hibbits 
252d3e1307bSJustin Hibbits     /* Find the last module in the chain */
253d3e1307bSJustin Hibbits     addr = 0;
254d3e1307bSJustin Hibbits     for (xp = file_findfile(NULL, NULL); xp != NULL; xp = xp->f_next) {
255d3e1307bSJustin Hibbits 	if (addr < (xp->f_addr + xp->f_size))
256d3e1307bSJustin Hibbits 	    addr = xp->f_addr + xp->f_size;
257d3e1307bSJustin Hibbits     }
258d3e1307bSJustin Hibbits     /* Pad to a page boundary */
259d3e1307bSJustin Hibbits     addr = roundup(addr, PAGE_SIZE);
260d3e1307bSJustin Hibbits 
261d3e1307bSJustin Hibbits     /* Copy our environment */
262d3e1307bSJustin Hibbits     envp = addr;
263d3e1307bSJustin Hibbits     addr = md_copyenv(addr);
264d3e1307bSJustin Hibbits 
265d3e1307bSJustin Hibbits     /* Pad to a page boundary */
266d3e1307bSJustin Hibbits     addr = roundup(addr, PAGE_SIZE);
267d3e1307bSJustin Hibbits 
268d3e1307bSJustin Hibbits #if defined(LOADER_FDT_SUPPORT)
269d3e1307bSJustin Hibbits     /* Copy out FDT */
270d3e1307bSJustin Hibbits     fdtp = 0;
271d3e1307bSJustin Hibbits #if defined(__powerpc__)
272d3e1307bSJustin Hibbits     if (getenv("usefdt") != NULL)
273d3e1307bSJustin Hibbits #endif
274d3e1307bSJustin Hibbits     {
275d3e1307bSJustin Hibbits 	size = fdt_copy(addr);
276d3e1307bSJustin Hibbits 	fdtp = addr;
277d3e1307bSJustin Hibbits 	addr = roundup(addr + size, PAGE_SIZE);
278d3e1307bSJustin Hibbits     }
279d3e1307bSJustin Hibbits #endif
280d3e1307bSJustin Hibbits 
281d3e1307bSJustin Hibbits     kernend = 0;
282d3e1307bSJustin Hibbits     kfp = file_findfile(NULL, kern64 ? "elf64 kernel" : "elf32 kernel");
283d3e1307bSJustin Hibbits     if (kfp == NULL)
284d3e1307bSJustin Hibbits 	kfp = file_findfile(NULL, "elf kernel");
285d3e1307bSJustin Hibbits     if (kfp == NULL)
286d3e1307bSJustin Hibbits 	panic("can't find kernel file");
287d3e1307bSJustin Hibbits     file_addmetadata(kfp, MODINFOMD_HOWTO, sizeof howto, &howto);
288d3e1307bSJustin Hibbits     if (kern64) {
289d3e1307bSJustin Hibbits 	scratch64 = envp;
290d3e1307bSJustin Hibbits 	file_addmetadata(kfp, MODINFOMD_ENVP, sizeof scratch64, &scratch64);
291d3e1307bSJustin Hibbits #if defined(LOADER_FDT_SUPPORT)
292d3e1307bSJustin Hibbits 	if (fdtp != 0) {
293d3e1307bSJustin Hibbits 	    scratch64 = fdtp;
294d3e1307bSJustin Hibbits 	    file_addmetadata(kfp, MODINFOMD_DTBP, sizeof scratch64, &scratch64);
295d3e1307bSJustin Hibbits 	}
296d3e1307bSJustin Hibbits #endif
297d3e1307bSJustin Hibbits 	scratch64 = kernend;
298d3e1307bSJustin Hibbits 	file_addmetadata(kfp, MODINFOMD_KERNEND,
299d3e1307bSJustin Hibbits 		sizeof scratch64, &scratch64);
300d3e1307bSJustin Hibbits     } else {
301d3e1307bSJustin Hibbits 	file_addmetadata(kfp, MODINFOMD_ENVP, sizeof envp, &envp);
302d3e1307bSJustin Hibbits #if defined(LOADER_FDT_SUPPORT)
303d3e1307bSJustin Hibbits 	if (fdtp != 0)
304d3e1307bSJustin Hibbits 	    file_addmetadata(kfp, MODINFOMD_DTBP, sizeof fdtp, &fdtp);
305d3e1307bSJustin Hibbits #endif
306d3e1307bSJustin Hibbits 	file_addmetadata(kfp, MODINFOMD_KERNEND, sizeof kernend, &kernend);
307d3e1307bSJustin Hibbits     }
308c1418270SIan Lepore #ifdef LOADER_GELI_SUPPORT
309c1418270SIan Lepore     geli_export_key_metadata(kfp);
310c1418270SIan Lepore #endif
311d3e1307bSJustin Hibbits 
312d3e1307bSJustin Hibbits     *modulep = addr;
313d3e1307bSJustin Hibbits     size = md_copymodules(0, kern64);
314d3e1307bSJustin Hibbits     kernend = roundup(addr + size, PAGE_SIZE);
315d3e1307bSJustin Hibbits 
316d3e1307bSJustin Hibbits     md = file_findmetadata(kfp, MODINFOMD_KERNEND);
317d3e1307bSJustin Hibbits     if (kern64) {
318d3e1307bSJustin Hibbits 	scratch64 = kernend;
319d3e1307bSJustin Hibbits 	bcopy(&scratch64, md->md_data, sizeof scratch64);
320d3e1307bSJustin Hibbits     } else {
321d3e1307bSJustin Hibbits 	bcopy(&kernend, md->md_data, sizeof kernend);
322d3e1307bSJustin Hibbits     }
323d3e1307bSJustin Hibbits 
3244daa199dSKyle Evans #ifdef __arm__
3254daa199dSKyle Evans     /* Convert addresses to the final VA */
3264daa199dSKyle Evans     *modulep -= __elfN(relocation_offset);
3274daa199dSKyle Evans 
3284daa199dSKyle Evans     /* Do relocation fixup on metadata of each module. */
3294daa199dSKyle Evans     for (xp = file_findfile(NULL, NULL); xp != NULL; xp = xp->f_next) {
3304daa199dSKyle Evans         for (i = 0; i < nitems(mdt); i++) {
3314daa199dSKyle Evans             md = file_findmetadata(xp, mdt[i]);
3324daa199dSKyle Evans                 if (md) {
3334daa199dSKyle Evans                     bcopy(md->md_data, &vaddr, sizeof vaddr);
3344daa199dSKyle Evans                     vaddr -= __elfN(relocation_offset);
3354daa199dSKyle Evans                     bcopy(&vaddr, md->md_data, sizeof vaddr);
3364daa199dSKyle Evans                 }
3374daa199dSKyle Evans             }
3384daa199dSKyle Evans     }
3394daa199dSKyle Evans #endif
3404daa199dSKyle Evans 
341d3e1307bSJustin Hibbits     (void)md_copymodules(addr, kern64);
342d3e1307bSJustin Hibbits #if defined(LOADER_FDT_SUPPORT)
343d3e1307bSJustin Hibbits     if (dtb != NULL)
344d3e1307bSJustin Hibbits 	*dtb = fdtp;
345d3e1307bSJustin Hibbits #endif
346d3e1307bSJustin Hibbits 
347d3e1307bSJustin Hibbits     return(0);
348d3e1307bSJustin Hibbits }
349d3e1307bSJustin Hibbits 
350d3e1307bSJustin Hibbits int
351d3e1307bSJustin Hibbits md_load(char *args, vm_offset_t *modulep, vm_offset_t *dtb)
352d3e1307bSJustin Hibbits {
353d3e1307bSJustin Hibbits     return (md_load_dual(args, modulep, dtb, 0));
354d3e1307bSJustin Hibbits }
355d3e1307bSJustin Hibbits 
35620b23ae7SWarner Losh #if defined(__powerpc__)
357d3e1307bSJustin Hibbits int
358d3e1307bSJustin Hibbits md_load64(char *args, vm_offset_t *modulep, vm_offset_t *dtb)
359d3e1307bSJustin Hibbits {
360d3e1307bSJustin Hibbits     return (md_load_dual(args, modulep, dtb, 1));
361d3e1307bSJustin Hibbits }
362d3e1307bSJustin Hibbits #endif
363