xref: /freebsd/stand/i386/common/bootargs.h (revision 7297dc4441b17d494c90055a4b9418ce5bca48e0)
1ca987d46SWarner Losh /*-
2ca987d46SWarner Losh  * Copyright (c) 2012 Andriy Gapon <avg@FreeBSD.org>
3ca987d46SWarner Losh  * All rights reserved.
4ca987d46SWarner Losh  *
5ca987d46SWarner Losh  * Redistribution and use in source and binary forms are freely
6ca987d46SWarner Losh  * permitted provided that the above copyright notice and this
7ca987d46SWarner Losh  * paragraph and the following disclaimer are duplicated in all
8ca987d46SWarner Losh  * such forms.
9ca987d46SWarner Losh  *
10ca987d46SWarner Losh  * This software is provided "AS IS" and without any express or
11ca987d46SWarner Losh  * implied warranties, including, without limitation, the implied
12ca987d46SWarner Losh  * warranties of merchantability and fitness for a particular
13ca987d46SWarner Losh  * purpose.
14ca987d46SWarner Losh  *
15ca987d46SWarner Losh  * $FreeBSD$
16ca987d46SWarner Losh  */
17ca987d46SWarner Losh 
18ca987d46SWarner Losh #ifndef _BOOT_I386_ARGS_H_
19ca987d46SWarner Losh #define	_BOOT_I386_ARGS_H_
20ca987d46SWarner Losh 
21*7297dc44SIan Lepore #define	KARGS_FLAGS_CD		0x0001	/* .bootdev is a bios CD dev */
22*7297dc44SIan Lepore #define	KARGS_FLAGS_PXE		0x0002	/* .pxeinfo is valid */
23*7297dc44SIan Lepore #define	KARGS_FLAGS_ZFS		0x0004	/* .zfspool is valid, EXTARG is zfs_boot_args */
24*7297dc44SIan Lepore #define	KARGS_FLAGS_EXTARG	0x0008	/* variably sized extended argument */
25*7297dc44SIan Lepore #define	KARGS_FLAGS_GELI	0x0010	/* EXTARG is geli_boot_args */
26ca987d46SWarner Losh 
27ca987d46SWarner Losh #define	BOOTARGS_SIZE	24	/* sizeof(struct bootargs) */
28ca987d46SWarner Losh #define	BA_BOOTFLAGS	8	/* offsetof(struct bootargs, bootflags) */
29ca987d46SWarner Losh #define	BA_BOOTINFO	20	/* offsetof(struct bootargs, bootinfo) */
30ca987d46SWarner Losh #define	BI_SIZE		48	/* offsetof(struct bootinfo, bi_size) */
31ca987d46SWarner Losh 
32ca987d46SWarner Losh /*
33ca987d46SWarner Losh  * We reserve some space above BTX allocated stack for the arguments
34ca987d46SWarner Losh  * and certain data that could hang off them.  Currently only struct bootinfo
35ca987d46SWarner Losh  * is supported in that category.  The bootinfo is placed at the top
36ca987d46SWarner Losh  * of the arguments area and the actual arguments are placed at ARGOFF offset
37ca987d46SWarner Losh  * from the top and grow towards the top.  Hopefully we have enough space
38ca987d46SWarner Losh  * for bootinfo and the arguments to not run into each other.
39ca987d46SWarner Losh  * Arguments area below ARGOFF is reserved for future use.
40ca987d46SWarner Losh  */
41ca987d46SWarner Losh #define	ARGSPACE	0x1000	/* total size of the BTX args area */
42ca987d46SWarner Losh #define	ARGOFF		0x800	/* actual args offset within the args area */
43ca987d46SWarner Losh #define	ARGADJ		(ARGSPACE - ARGOFF)
44ca987d46SWarner Losh 
45ca987d46SWarner Losh #ifndef __ASSEMBLER__
46ca987d46SWarner Losh 
47b92c2c90SIan Lepore /*
48b92c2c90SIan Lepore  * This struct describes the contents of the stack on entry to btxldr.S.  This
49b92c2c90SIan Lepore  * is the data that follows the return address, so it begins at 4(%esp).  On
50b92c2c90SIan Lepore  * the sending side, this data is passed as individual args to __exec().  On the
51b92c2c90SIan Lepore  * receiving side, code in btxldr.S copies the data from the entry stack to a
52b92c2c90SIan Lepore  * known fixed location in the new address space.  Then, btxcsu.S sets the
53b92c2c90SIan Lepore  * global variable __args to point to that known fixed location before calling
54b92c2c90SIan Lepore  * main(), which casts __args to a struct bootargs pointer to access the data.
55b92c2c90SIan Lepore  * The btxldr.S code is aware of KARGS_FLAGS_EXTARG, and if it's set, the extra
56b92c2c90SIan Lepore  * args data is copied along with the other bootargs from the entry stack to the
57b92c2c90SIan Lepore  * fixed location in the new address space.
58b92c2c90SIan Lepore  *
59b92c2c90SIan Lepore  * The bootinfo field is actually a pointer to a bootinfo struct that has been
60b92c2c90SIan Lepore  * converted to uint32_t using VTOP().  On the receiving side it must be
61b92c2c90SIan Lepore  * converted back to a pointer using PTOV().  Code in btxldr.S is aware of this
62b92c2c90SIan Lepore  * field and if it's non-NULL it copies the data it points to into another known
63b92c2c90SIan Lepore  * fixed location, and adjusts the bootinfo field to point to that new location.
64b92c2c90SIan Lepore  */
65ca987d46SWarner Losh struct bootargs
66ca987d46SWarner Losh {
67ca987d46SWarner Losh 	uint32_t			howto;
68ca987d46SWarner Losh 	uint32_t			bootdev;
69ca987d46SWarner Losh 	uint32_t			bootflags;
70ca987d46SWarner Losh 	union {
71ca987d46SWarner Losh 		struct {
72ca987d46SWarner Losh 			uint32_t	pxeinfo;
73ca987d46SWarner Losh 			uint32_t	reserved;
74ca987d46SWarner Losh 		};
75ca987d46SWarner Losh 		uint64_t		zfspool;
76ca987d46SWarner Losh 	};
77ca987d46SWarner Losh 	uint32_t			bootinfo;
78ca987d46SWarner Losh 
79ca987d46SWarner Losh 	/*
80ca987d46SWarner Losh 	 * If KARGS_FLAGS_EXTARG is set in bootflags, then the above fields
81ca987d46SWarner Losh 	 * are followed by a uint32_t field that specifies a size of the
82ca987d46SWarner Losh 	 * extended arguments (including the size field).
83ca987d46SWarner Losh 	 */
84ca987d46SWarner Losh };
85ca987d46SWarner Losh 
86ca987d46SWarner Losh #ifdef LOADER_GELI_SUPPORT
87ca987d46SWarner Losh #include <crypto/intake.h>
88df108aafSIan Lepore #include "geliboot.h"
89ca987d46SWarner Losh #endif
90ca987d46SWarner Losh 
91df108aafSIan Lepore /*
92df108aafSIan Lepore  * geli_boot_data is embedded in geli_boot_args (passed from gptboot to loader)
93df108aafSIan Lepore  * and in zfs_boot_args (passed from zfsboot and gptzfsboot to loader).
94df108aafSIan Lepore  */
95df108aafSIan Lepore struct geli_boot_data
96ca987d46SWarner Losh {
97ca987d46SWarner Losh     union {
98ca987d46SWarner Losh         char            gelipw[256];
99ca987d46SWarner Losh         struct {
100ca987d46SWarner Losh             char                notapw;	/*
101ca987d46SWarner Losh 					 * single null byte to stop keybuf
102ca987d46SWarner Losh 					 * being interpreted as a password
103ca987d46SWarner Losh 					 */
104ca987d46SWarner Losh             uint32_t            keybuf_sentinel;
105ca987d46SWarner Losh #ifdef LOADER_GELI_SUPPORT
106ca987d46SWarner Losh             struct keybuf       *keybuf;
107ca987d46SWarner Losh #else
108ca987d46SWarner Losh             void                *keybuf;
109ca987d46SWarner Losh #endif
110ca987d46SWarner Losh         };
111ca987d46SWarner Losh     };
112ca987d46SWarner Losh };
113ca987d46SWarner Losh 
114df108aafSIan Lepore #ifdef LOADER_GELI_SUPPORT
115df108aafSIan Lepore 
116df108aafSIan Lepore static inline void
117df108aafSIan Lepore export_geli_boot_data(struct geli_boot_data *gbdata)
118df108aafSIan Lepore {
119df108aafSIan Lepore 
120df108aafSIan Lepore 	gbdata->notapw = '\0';
121df108aafSIan Lepore 	gbdata->keybuf_sentinel = KEYBUF_SENTINEL;
122df108aafSIan Lepore 	gbdata->keybuf = malloc(sizeof(struct keybuf) +
123df108aafSIan Lepore 	    (GELI_MAX_KEYS * sizeof(struct keybuf_ent)));
124df108aafSIan Lepore 	geli_export_key_buffer(gbdata->keybuf);
125df108aafSIan Lepore }
126df108aafSIan Lepore 
127df108aafSIan Lepore static inline void
128df108aafSIan Lepore import_geli_boot_data(struct geli_boot_data *gbdata)
129df108aafSIan Lepore {
130df108aafSIan Lepore 
131df108aafSIan Lepore 	if (gbdata->gelipw[0] != '\0') {
132df108aafSIan Lepore 	    setenv("kern.geom.eli.passphrase", gbdata->gelipw, 1);
133df108aafSIan Lepore 	    explicit_bzero(gbdata->gelipw, sizeof(gbdata->gelipw));
134df108aafSIan Lepore 	} else if (gbdata->keybuf_sentinel == KEYBUF_SENTINEL) {
135df108aafSIan Lepore 	    geli_import_key_buffer(gbdata->keybuf);
136df108aafSIan Lepore 	}
137df108aafSIan Lepore }
138df108aafSIan Lepore #endif /* LOADER_GELI_SUPPORT */
139df108aafSIan Lepore 
140df108aafSIan Lepore struct geli_boot_args
141df108aafSIan Lepore {
142df108aafSIan Lepore 	uint32_t		size;
143df108aafSIan Lepore 	struct geli_boot_data	gelidata;
144df108aafSIan Lepore };
145df108aafSIan Lepore 
146df108aafSIan Lepore struct zfs_boot_args
147df108aafSIan Lepore {
148df108aafSIan Lepore 	uint32_t		size;
149df108aafSIan Lepore 	uint32_t		reserved;
150df108aafSIan Lepore 	uint64_t		pool;
151df108aafSIan Lepore 	uint64_t		root;
152df108aafSIan Lepore 	uint64_t		primary_pool;
153df108aafSIan Lepore 	uint64_t		primary_vdev;
154df108aafSIan Lepore 	struct geli_boot_data	gelidata;
155df108aafSIan Lepore };
156df108aafSIan Lepore 
157ca987d46SWarner Losh #endif /*__ASSEMBLER__*/
158ca987d46SWarner Losh 
159ca987d46SWarner Losh #endif	/* !_BOOT_I386_ARGS_H_ */
160