Blame view
common/env_fat.c
2.12 KB
57210c7cc
|
1 2 3 4 5 6 |
/* * (c) Copyright 2011 by Tigris Elektronik GmbH * * Author: * Maximilian Schwerin <mvs@tigris.de> * |
3765b3e7b
|
7 |
* SPDX-License-Identifier: GPL-2.0+ |
57210c7cc
|
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
*/ #include <common.h> #include <command.h> #include <environment.h> #include <linux/stddef.h> #include <malloc.h> #include <search.h> #include <errno.h> #include <fat.h> #include <mmc.h> char *env_name_spec = "FAT"; env_t *env_ptr; DECLARE_GLOBAL_DATA_PTR; |
57210c7cc
|
26 27 28 29 30 31 32 33 34 35 36 37 |
int env_init(void) { /* use default */ gd->env_addr = (ulong)&default_environment[0]; gd->env_valid = 1; return 0; } #ifdef CONFIG_CMD_SAVEENV int saveenv(void) { |
cd0f4fa1c
|
38 |
env_t env_new; |
57210c7cc
|
39 |
block_dev_desc_t *dev_desc = NULL; |
be354c1a2
|
40 41 |
disk_partition_t info; int dev, part; |
9aa90c1df
|
42 |
int err; |
1ad0b98a0
|
43 |
loff_t size; |
57210c7cc
|
44 |
|
7ce1526ed
|
45 46 47 |
err = env_export(&env_new); if (err) return err; |
57210c7cc
|
48 |
|
be354c1a2
|
49 50 51 52 |
part = get_device_and_partition(FAT_ENV_INTERFACE, FAT_ENV_DEVICE_AND_PART, &dev_desc, &info, 1); if (part < 0) |
57210c7cc
|
53 |
return 1; |
9aa90c1df
|
54 |
|
be354c1a2
|
55 56 57 58 59 60 |
dev = dev_desc->dev; if (fat_set_blk_dev(dev_desc, &info) != 0) { printf(" ** Unable to use %s %d:%d for saveenv ** ", FAT_ENV_INTERFACE, dev, part); |
57210c7cc
|
61 62 |
return 1; } |
1ad0b98a0
|
63 64 |
err = file_fat_write(FAT_ENV_FILE, (void *)&env_new, 0, sizeof(env_t), &size); |
9aa90c1df
|
65 |
if (err == -1) { |
57210c7cc
|
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
printf(" ** Unable to write \"%s\" from %s%d:%d ** ", FAT_ENV_FILE, FAT_ENV_INTERFACE, dev, part); return 1; } puts("done "); return 0; } #endif /* CONFIG_CMD_SAVEENV */ void env_relocate_spec(void) { |
6d1966e12
|
81 |
ALLOC_CACHE_ALIGN_BUFFER(char, buf, CONFIG_ENV_SIZE); |
57210c7cc
|
82 |
block_dev_desc_t *dev_desc = NULL; |
be354c1a2
|
83 84 |
disk_partition_t info; int dev, part; |
9aa90c1df
|
85 |
int err; |
57210c7cc
|
86 |
|
be354c1a2
|
87 88 89 90 91 92 93 94 95 96 97 98 99 |
part = get_device_and_partition(FAT_ENV_INTERFACE, FAT_ENV_DEVICE_AND_PART, &dev_desc, &info, 1); if (part < 0) goto err_env_relocate; dev = dev_desc->dev; if (fat_set_blk_dev(dev_desc, &info) != 0) { printf(" ** Unable to use %s %d:%d for loading the env ** ", FAT_ENV_INTERFACE, dev, part); goto err_env_relocate; |
57210c7cc
|
100 |
} |
6d1966e12
|
101 |
err = file_fat_read(FAT_ENV_FILE, buf, CONFIG_ENV_SIZE); |
9aa90c1df
|
102 |
if (err == -1) { |
57210c7cc
|
103 104 105 106 |
printf(" ** Unable to read \"%s\" from %s%d:%d ** ", FAT_ENV_FILE, FAT_ENV_INTERFACE, dev, part); |
be354c1a2
|
107 |
goto err_env_relocate; |
57210c7cc
|
108 109 110 |
} env_import(buf, 1); |
be354c1a2
|
111 112 113 114 |
return; err_env_relocate: set_default_env(NULL); |
57210c7cc
|
115 |
} |