Merge tag 'efi-2022-01-rc1' of https://source.denx.de/u-boot/custodians/u-boot-efi
[platform/kernel/u-boot.git] / env / nowhere.c
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * (C) Copyright 2000-2010
4  * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5  *
6  * (C) Copyright 2001 Sysgo Real-Time Solutions, GmbH <www.elinos.com>
7  * Andreas Heppel <aheppel@sysgo.de>
8  */
9
10 #include <common.h>
11 #include <command.h>
12 #include <env.h>
13 #include <env_internal.h>
14 #include <asm/global_data.h>
15 #include <linux/stddef.h>
16
17 DECLARE_GLOBAL_DATA_PTR;
18
19 /*
20  * Because we only ever have the default environment available we must mark
21  * it as invalid.
22  */
23 static int env_nowhere_init(void)
24 {
25         gd->env_addr    = (ulong)&default_environment[0];
26         gd->env_valid   = ENV_INVALID;
27
28         return 0;
29 }
30
31 static int env_nowhere_load(void)
32 {
33         /*
34          * For SPL, setting env_valid = ENV_INVALID is enough, as env_get()
35          * searches default_environment array in that case.
36          * For U-Boot proper, import the default environment to allow reload.
37          */
38         if (!IS_ENABLED(CONFIG_SPL_BUILD))
39                 env_set_default(NULL, 0);
40
41         gd->env_valid   = ENV_INVALID;
42
43         return 0;
44 }
45
46 U_BOOT_ENV_LOCATION(nowhere) = {
47         .location       = ENVL_NOWHERE,
48         .init           = env_nowhere_init,
49         .load           = env_nowhere_load,
50         ENV_NAME("nowhere")
51 };