Blame view
env/ext4.c
2.83 KB
fd1000b9c common: Add suppo... |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
/* * (c) Copyright 2016 by VRT Technology * * Author: * Stuart Longland <stuartl@vrt.com.au> * * Based on FAT environment driver * (c) Copyright 2011 by Tigris Elektronik GmbH * * Author: * Maximilian Schwerin <mvs@tigris.de> * * and EXT4 filesystem implementation * (C) Copyright 2011 - 2012 Samsung Electronics * EXT4 filesystem implementation in Uboot by * Uma Shankar <uma.shankar@samsung.com> * Manjunatha C Achar <a.manjunatha@samsung.com> * * SPDX-License-Identifier: GPL-2.0+ */ #include <common.h> #include <command.h> #include <environment.h> #include <linux/stddef.h> #include <malloc.h> |
bd62e2419 common: Fix suppo... |
28 |
#include <memalign.h> |
fd1000b9c common: Add suppo... |
29 30 31 32 |
#include <search.h> #include <errno.h> #include <ext4fs.h> #include <mmc.h> |
fd1000b9c common: Add suppo... |
33 |
DECLARE_GLOBAL_DATA_PTR; |
fd1000b9c common: Add suppo... |
34 |
#ifdef CONFIG_CMD_SAVEENV |
e5bce247b env: Switch over ... |
35 |
static int env_ext4_save(void) |
fd1000b9c common: Add suppo... |
36 37 |
{ env_t env_new; |
bd62e2419 common: Fix suppo... |
38 |
struct blk_desc *dev_desc = NULL; |
fd1000b9c common: Add suppo... |
39 40 41 42 43 44 45 |
disk_partition_t info; int dev, part; int err; err = env_export(&env_new); if (err) return err; |
1087a7942 env: enable acces... |
46 47 48 |
part = blk_get_device_part_str(CONFIG_ENV_EXT4_INTERFACE, CONFIG_ENV_EXT4_DEVICE_AND_PART, &dev_desc, &info, 1); |
fd1000b9c common: Add suppo... |
49 50 |
if (part < 0) return 1; |
bd62e2419 common: Fix suppo... |
51 |
dev = dev_desc->devnum; |
fd1000b9c common: Add suppo... |
52 53 54 55 56 57 |
ext4fs_set_blk_dev(dev_desc, &info); if (!ext4fs_mount(info.size)) { printf(" ** Unable to use %s %s for saveenv ** ", |
1087a7942 env: enable acces... |
58 59 |
CONFIG_ENV_EXT4_INTERFACE, CONFIG_ENV_EXT4_DEVICE_AND_PART); |
fd1000b9c common: Add suppo... |
60 61 |
return 1; } |
1087a7942 env: enable acces... |
62 63 |
err = ext4fs_write(CONFIG_ENV_EXT4_FILE, (void *)&env_new, sizeof(env_t)); |
fd1000b9c common: Add suppo... |
64 65 66 67 68 69 |
ext4fs_close(); if (err == -1) { printf(" ** Unable to write \"%s\" from %s%d:%d ** ", |
1087a7942 env: enable acces... |
70 71 |
CONFIG_ENV_EXT4_FILE, CONFIG_ENV_EXT4_INTERFACE, dev, part); |
fd1000b9c common: Add suppo... |
72 73 74 75 76 77 78 79 |
return 1; } puts("done "); return 0; } #endif /* CONFIG_CMD_SAVEENV */ |
c59519919 env: Adjust the l... |
80 |
static int env_ext4_load(void) |
fd1000b9c common: Add suppo... |
81 82 |
{ ALLOC_CACHE_ALIGN_BUFFER(char, buf, CONFIG_ENV_SIZE); |
bd62e2419 common: Fix suppo... |
83 |
struct blk_desc *dev_desc = NULL; |
fd1000b9c common: Add suppo... |
84 85 86 |
disk_partition_t info; int dev, part; int err; |
bd62e2419 common: Fix suppo... |
87 |
loff_t off; |
fd1000b9c common: Add suppo... |
88 |
|
26862b4a4 env: mmc/fat/ext4... |
89 90 |
if (!strcmp(CONFIG_ENV_EXT4_INTERFACE, "mmc")) mmc_initialize(NULL); |
1087a7942 env: enable acces... |
91 92 93 |
part = blk_get_device_part_str(CONFIG_ENV_EXT4_INTERFACE, CONFIG_ENV_EXT4_DEVICE_AND_PART, &dev_desc, &info, 1); |
fd1000b9c common: Add suppo... |
94 95 |
if (part < 0) goto err_env_relocate; |
bd62e2419 common: Fix suppo... |
96 |
dev = dev_desc->devnum; |
fd1000b9c common: Add suppo... |
97 98 99 100 101 102 |
ext4fs_set_blk_dev(dev_desc, &info); if (!ext4fs_mount(info.size)) { printf(" ** Unable to use %s %s for loading the env ** ", |
1087a7942 env: enable acces... |
103 104 |
CONFIG_ENV_EXT4_INTERFACE, CONFIG_ENV_EXT4_DEVICE_AND_PART); |
fd1000b9c common: Add suppo... |
105 106 |
goto err_env_relocate; } |
1087a7942 env: enable acces... |
107 108 |
err = ext4_read_file(CONFIG_ENV_EXT4_FILE, buf, 0, CONFIG_ENV_SIZE, &off); |
fd1000b9c common: Add suppo... |
109 110 111 112 113 114 |
ext4fs_close(); if (err == -1) { printf(" ** Unable to read \"%s\" from %s%d:%d ** ", |
1087a7942 env: enable acces... |
115 116 |
CONFIG_ENV_EXT4_FILE, CONFIG_ENV_EXT4_INTERFACE, dev, part); |
fd1000b9c common: Add suppo... |
117 118 |
goto err_env_relocate; } |
2166ebf78 env: make env dri... |
119 |
return env_import(buf, 1); |
fd1000b9c common: Add suppo... |
120 121 122 |
err_env_relocate: set_default_env(NULL); |
c59519919 env: Adjust the l... |
123 124 |
return -EIO; |
fd1000b9c common: Add suppo... |
125 |
} |
4415f1d1f env: Create a loc... |
126 127 128 |
U_BOOT_ENV_LOCATION(ext4) = { .location = ENVL_EXT4, |
ac358beb8 env: Drop the env... |
129 |
ENV_NAME("EXT4") |
e5bce247b env: Switch over ... |
130 131 |
.load = env_ext4_load, .save = env_save_ptr(env_ext4_save), |
4415f1d1f env: Create a loc... |
132 |
}; |