1 // SPDX-License-Identifier: GPL-2.0+
3 * (c) Copyright 2016 by VRT Technology
6 * Stuart Longland <stuartl@vrt.com.au>
8 * Based on FAT environment driver
9 * (c) Copyright 2011 by Tigris Elektronik GmbH
12 * Maximilian Schwerin <mvs@tigris.de>
14 * and EXT4 filesystem implementation
15 * (C) Copyright 2011 - 2012 Samsung Electronics
16 * EXT4 filesystem implementation in Uboot by
17 * Uma Shankar <uma.shankar@samsung.com>
18 * Manjunatha C Achar <a.manjunatha@samsung.com>
24 #include <environment.h>
25 #include <linux/stddef.h>
33 #ifdef CONFIG_CMD_SAVEENV
34 static int env_ext4_save(void)
37 struct blk_desc
*dev_desc
= NULL
;
38 disk_partition_t info
;
42 err
= env_export(&env_new
);
46 part
= blk_get_device_part_str(CONFIG_ENV_EXT4_INTERFACE
,
47 CONFIG_ENV_EXT4_DEVICE_AND_PART
,
52 dev
= dev_desc
->devnum
;
53 ext4fs_set_blk_dev(dev_desc
, &info
);
55 if (!ext4fs_mount(info
.size
)) {
56 printf("\n** Unable to use %s %s for saveenv **\n",
57 CONFIG_ENV_EXT4_INTERFACE
,
58 CONFIG_ENV_EXT4_DEVICE_AND_PART
);
62 err
= ext4fs_write(CONFIG_ENV_EXT4_FILE
, (void *)&env_new
,
67 printf("\n** Unable to write \"%s\" from %s%d:%d **\n",
68 CONFIG_ENV_EXT4_FILE
, CONFIG_ENV_EXT4_INTERFACE
, dev
,
76 #endif /* CONFIG_CMD_SAVEENV */
78 static int env_ext4_load(void)
80 ALLOC_CACHE_ALIGN_BUFFER(char, buf
, CONFIG_ENV_SIZE
);
81 struct blk_desc
*dev_desc
= NULL
;
82 disk_partition_t info
;
88 if (!strcmp(CONFIG_ENV_EXT4_INTERFACE
, "mmc"))
92 part
= blk_get_device_part_str(CONFIG_ENV_EXT4_INTERFACE
,
93 CONFIG_ENV_EXT4_DEVICE_AND_PART
,
96 goto err_env_relocate
;
98 dev
= dev_desc
->devnum
;
99 ext4fs_set_blk_dev(dev_desc
, &info
);
101 if (!ext4fs_mount(info
.size
)) {
102 printf("\n** Unable to use %s %s for loading the env **\n",
103 CONFIG_ENV_EXT4_INTERFACE
,
104 CONFIG_ENV_EXT4_DEVICE_AND_PART
);
105 goto err_env_relocate
;
108 err
= ext4_read_file(CONFIG_ENV_EXT4_FILE
, buf
, 0, CONFIG_ENV_SIZE
,
113 printf("\n** Unable to read \"%s\" from %s%d:%d **\n",
114 CONFIG_ENV_EXT4_FILE
, CONFIG_ENV_EXT4_INTERFACE
, dev
,
116 goto err_env_relocate
;
119 return env_import(buf
, 1);
122 set_default_env(NULL
, 0);
127 U_BOOT_ENV_LOCATION(ext4
) = {
128 .location
= ENVL_EXT4
,
130 .load
= env_ext4_load
,
131 .save
= env_save_ptr(env_ext4_save
),