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>
36 DECLARE_GLOBAL_DATA_PTR;
38 #ifdef CONFIG_CMD_SAVEENV
39 static int env_ext4_save(void)
42 struct blk_desc *dev_desc = NULL;
43 disk_partition_t info;
47 err = env_export(&env_new);
51 part = blk_get_device_part_str(EXT4_ENV_INTERFACE,
52 EXT4_ENV_DEVICE_AND_PART,
57 dev = dev_desc->devnum;
58 ext4fs_set_blk_dev(dev_desc, &info);
60 if (!ext4fs_mount(info.size)) {
61 printf("\n** Unable to use %s %s for saveenv **\n",
62 EXT4_ENV_INTERFACE, EXT4_ENV_DEVICE_AND_PART);
66 err = ext4fs_write(EXT4_ENV_FILE, (void *)&env_new, sizeof(env_t));
70 printf("\n** Unable to write \"%s\" from %s%d:%d **\n",
71 EXT4_ENV_FILE, EXT4_ENV_INTERFACE, dev, part);
78 #endif /* CONFIG_CMD_SAVEENV */
80 static void env_ext4_load(void)
82 ALLOC_CACHE_ALIGN_BUFFER(char, buf, CONFIG_ENV_SIZE);
83 struct blk_desc *dev_desc = NULL;
84 disk_partition_t info;
89 part = blk_get_device_part_str(EXT4_ENV_INTERFACE,
90 EXT4_ENV_DEVICE_AND_PART,
93 goto err_env_relocate;
95 dev = dev_desc->devnum;
96 ext4fs_set_blk_dev(dev_desc, &info);
98 if (!ext4fs_mount(info.size)) {
99 printf("\n** Unable to use %s %s for loading the env **\n",
100 EXT4_ENV_INTERFACE, EXT4_ENV_DEVICE_AND_PART);
101 goto err_env_relocate;
104 err = ext4_read_file(EXT4_ENV_FILE, buf, 0, CONFIG_ENV_SIZE, &off);
108 printf("\n** Unable to read \"%s\" from %s%d:%d **\n",
109 EXT4_ENV_FILE, EXT4_ENV_INTERFACE, dev, part);
110 goto err_env_relocate;
117 set_default_env(NULL);
120 U_BOOT_ENV_LOCATION(ext4) = {
121 .location = ENVL_EXT4,
123 .load = env_ext4_load,
124 .save = env_save_ptr(env_ext4_save),