2 * (c) Copyright 2016 by VRT Technology
5 * Stuart Longland <stuartl@vrt.com.au>
7 * Based on FAT environment driver
8 * (c) Copyright 2011 by Tigris Elektronik GmbH
11 * Maximilian Schwerin <mvs@tigris.de>
13 * and EXT4 filesystem implementation
14 * (C) Copyright 2011 - 2012 Samsung Electronics
15 * EXT4 filesystem implementation in Uboot by
16 * Uma Shankar <uma.shankar@samsung.com>
17 * Manjunatha C Achar <a.manjunatha@samsung.com>
19 * SPDX-License-Identifier: GPL-2.0+
25 #include <environment.h>
26 #include <linux/stddef.h>
34 DECLARE_GLOBAL_DATA_PTR;
36 #ifdef CONFIG_CMD_SAVEENV
37 static int env_ext4_save(void)
40 struct blk_desc *dev_desc = NULL;
41 disk_partition_t info;
45 err = env_export(&env_new);
49 part = blk_get_device_part_str(CONFIG_ENV_EXT4_INTERFACE,
50 CONFIG_ENV_EXT4_DEVICE_AND_PART,
55 dev = dev_desc->devnum;
56 ext4fs_set_blk_dev(dev_desc, &info);
58 if (!ext4fs_mount(info.size)) {
59 printf("\n** Unable to use %s %s for saveenv **\n",
60 CONFIG_ENV_EXT4_INTERFACE,
61 CONFIG_ENV_EXT4_DEVICE_AND_PART);
65 err = ext4fs_write(CONFIG_ENV_EXT4_FILE, (void *)&env_new,
70 printf("\n** Unable to write \"%s\" from %s%d:%d **\n",
71 CONFIG_ENV_EXT4_FILE, CONFIG_ENV_EXT4_INTERFACE, dev,
79 #endif /* CONFIG_CMD_SAVEENV */
81 static int env_ext4_load(void)
83 ALLOC_CACHE_ALIGN_BUFFER(char, buf, CONFIG_ENV_SIZE);
84 struct blk_desc *dev_desc = NULL;
85 disk_partition_t info;
91 if (!strcmp(CONFIG_ENV_EXT4_INTERFACE, "mmc"))
95 part = blk_get_device_part_str(CONFIG_ENV_EXT4_INTERFACE,
96 CONFIG_ENV_EXT4_DEVICE_AND_PART,
99 goto err_env_relocate;
101 dev = dev_desc->devnum;
102 ext4fs_set_blk_dev(dev_desc, &info);
104 if (!ext4fs_mount(info.size)) {
105 printf("\n** Unable to use %s %s for loading the env **\n",
106 CONFIG_ENV_EXT4_INTERFACE,
107 CONFIG_ENV_EXT4_DEVICE_AND_PART);
108 goto err_env_relocate;
111 err = ext4_read_file(CONFIG_ENV_EXT4_FILE, buf, 0, CONFIG_ENV_SIZE,
116 printf("\n** Unable to read \"%s\" from %s%d:%d **\n",
117 CONFIG_ENV_EXT4_FILE, CONFIG_ENV_EXT4_INTERFACE, dev,
119 goto err_env_relocate;
122 return env_import(buf, 1);
125 set_default_env(NULL);
130 U_BOOT_ENV_LOCATION(ext4) = {
131 .location = ENVL_EXT4,
133 .load = env_ext4_load,
134 .save = env_save_ptr(env_ext4_save),