xref: /freebsd/sys/dev/cfe/cfe_env.c (revision 685dc743dc3b5645e34836464128e1c0558b404b)
1579c0614SWarner Losh /*-
2*4d846d26SWarner Losh  * SPDX-License-Identifier: BSD-2-Clause
3718cf2ccSPedro F. Giffuni  *
4579c0614SWarner Losh  * Copyright (c) 2009 Neelkanth Natu
5579c0614SWarner Losh  * All rights reserved.
6579c0614SWarner Losh  *
7579c0614SWarner Losh  * Redistribution and use in source and binary forms, with or without
8579c0614SWarner Losh  * modification, are permitted provided that the following conditions
9579c0614SWarner Losh  * are met:
10579c0614SWarner Losh  * 1. Redistributions of source code must retain the above copyright
11579c0614SWarner Losh  *    notice, this list of conditions and the following disclaimer.
12579c0614SWarner Losh  * 2. Redistributions in binary form must reproduce the above copyright
13579c0614SWarner Losh  *    notice, this list of conditions and the following disclaimer in the
14579c0614SWarner Losh  *    documentation and/or other materials provided with the distribution.
15579c0614SWarner Losh  *
16579c0614SWarner Losh  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17579c0614SWarner Losh  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18579c0614SWarner Losh  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19579c0614SWarner Losh  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20579c0614SWarner Losh  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21579c0614SWarner Losh  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22579c0614SWarner Losh  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23579c0614SWarner Losh  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24579c0614SWarner Losh  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25579c0614SWarner Losh  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26579c0614SWarner Losh  * SUCH DAMAGE.
27579c0614SWarner Losh  */
28579c0614SWarner Losh 
29579c0614SWarner Losh #include <sys/param.h>
305f7eb1ffSNeel Natu #include <sys/kenv.h>
31579c0614SWarner Losh 
32579c0614SWarner Losh #include <dev/cfe/cfe_api.h>
33579c0614SWarner Losh #ifndef	CFE_ENV_SIZE
34579c0614SWarner Losh #define	CFE_ENV_SIZE	PAGE_SIZE	/* default is one page */
35579c0614SWarner Losh #endif
36579c0614SWarner Losh 
37579c0614SWarner Losh extern void cfe_env_init(void);
38579c0614SWarner Losh 
39579c0614SWarner Losh static char cfe_env_buf[CFE_ENV_SIZE];
40579c0614SWarner Losh 
41579c0614SWarner Losh void
cfe_env_init(void)42579c0614SWarner Losh cfe_env_init(void)
43579c0614SWarner Losh {
445f7eb1ffSNeel Natu 	int idx;
455f7eb1ffSNeel Natu 	char name[KENV_MNAMELEN], val[KENV_MVALLEN];
46579c0614SWarner Losh 
475f7eb1ffSNeel Natu 	init_static_kenv(cfe_env_buf, CFE_ENV_SIZE);
48579c0614SWarner Losh 
49579c0614SWarner Losh 	idx = 0;
50579c0614SWarner Losh 	while (1) {
51579c0614SWarner Losh 		if (cfe_enumenv(idx, name, sizeof(name), val, sizeof(val)) != 0)
52579c0614SWarner Losh 			break;
53579c0614SWarner Losh 
54d9ca757cSDavide Italiano 		if (kern_setenv(name, val) != 0) {
55579c0614SWarner Losh 			printf("No space to store CFE env: \"%s=%s\"\n",
56579c0614SWarner Losh 				name, val);
575f7eb1ffSNeel Natu 		}
58579c0614SWarner Losh 		++idx;
59579c0614SWarner Losh 	}
60579c0614SWarner Losh }
61