Commit 2b74433f365fa677a60431a80e524b5d8d04e995
Committed by
Tom Rini
1 parent
a7eb1d66c7
Exists in
master
and in
53 other branches
env: Add support for UBI environment
UBI is a better place for the environment on NAND devices because it handles wear-leveling and bad blocks. Gluebi is needed in Linux to access the env as an MTD partition. Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Showing 6 changed files with 144 additions and 2 deletions Side-by-side Diff
README
... | ... | @@ -3548,6 +3548,27 @@ |
3548 | 3548 | environment. If redundant environment is used, it will be copied to |
3549 | 3549 | CONFIG_NAND_ENV_DST + CONFIG_ENV_SIZE. |
3550 | 3550 | |
3551 | +- CONFIG_ENV_IS_IN_UBI: | |
3552 | + | |
3553 | + Define this if you have an UBI volume that you want to use for the | |
3554 | + environment. This has the benefit of wear-leveling the environment | |
3555 | + accesses, which is important on NAND. | |
3556 | + | |
3557 | + - CONFIG_ENV_UBI_PART: | |
3558 | + | |
3559 | + Define this to a string that is the mtd partition containing the UBI. | |
3560 | + | |
3561 | + - CONFIG_ENV_UBI_VOLUME: | |
3562 | + | |
3563 | + Define this to the name of the volume that you want to store the | |
3564 | + environment in. | |
3565 | + | |
3566 | + - CONFIG_UBI_SILENCE_MSG | |
3567 | + - CONFIG_UBIFS_SILENCE_MSG | |
3568 | + | |
3569 | + You will probably want to define these to avoid a really noisy system | |
3570 | + when storing the env in UBI. | |
3571 | + | |
3551 | 3572 | - CONFIG_SYS_SPI_INIT_OFFSET |
3552 | 3573 | |
3553 | 3574 | Defines offset to the initial SPI buffer area in DPRAM. The |
common/Makefile
... | ... | @@ -66,6 +66,7 @@ |
66 | 66 | COBJS-$(CONFIG_ENV_IS_IN_ONENAND) += env_onenand.o |
67 | 67 | COBJS-$(CONFIG_ENV_IS_IN_SPI_FLASH) += env_sf.o |
68 | 68 | COBJS-$(CONFIG_ENV_IS_IN_REMOTE) += env_remote.o |
69 | +COBJS-$(CONFIG_ENV_IS_IN_UBI) += env_ubi.o | |
69 | 70 | COBJS-$(CONFIG_ENV_IS_NOWHERE) += env_nowhere.o |
70 | 71 | |
71 | 72 | # command |
common/cmd_nvedit.c
... | ... | @@ -62,9 +62,10 @@ |
62 | 62 | !defined(CONFIG_ENV_IS_IN_ONENAND) && \ |
63 | 63 | !defined(CONFIG_ENV_IS_IN_SPI_FLASH) && \ |
64 | 64 | !defined(CONFIG_ENV_IS_IN_REMOTE) && \ |
65 | + !defined(CONFIG_ENV_IS_IN_UBI) && \ | |
65 | 66 | !defined(CONFIG_ENV_IS_NOWHERE) |
66 | 67 | # error Define one of CONFIG_ENV_IS_IN_{EEPROM|FLASH|DATAFLASH|ONENAND|\ |
67 | -SPI_FLASH|NVRAM|MMC|FAT|REMOTE} or CONFIG_ENV_IS_NOWHERE | |
68 | +SPI_FLASH|NVRAM|MMC|FAT|REMOTE|UBI} or CONFIG_ENV_IS_NOWHERE | |
68 | 69 | #endif |
69 | 70 | |
70 | 71 | /* |
common/env_ubi.c
1 | +/* | |
2 | + * (c) Copyright 2012 by National Instruments, | |
3 | + * Joe Hershberger <joe.hershberger@ni.com> | |
4 | + * | |
5 | + * See file CREDITS for list of people who contributed to this | |
6 | + * project. | |
7 | + * | |
8 | + * This program is free software; you can redistribute it and/or | |
9 | + * modify it under the terms of the GNU General Public License as | |
10 | + * published by the Free Software Foundation; either version 2 of | |
11 | + * the License, or (at your option) any later version. | |
12 | + * | |
13 | + * This program is distributed in the hope that it will be useful, | |
14 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | + * GNU General Public License for more details. | |
17 | + * | |
18 | + * You should have received a copy of the GNU General Public License | |
19 | + * along with this program; if not, write to the Free Software | |
20 | + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, | |
21 | + * MA 02111-1307 USA | |
22 | + */ | |
23 | + | |
24 | +#include <common.h> | |
25 | + | |
26 | +#include <command.h> | |
27 | +#include <environment.h> | |
28 | +#include <errno.h> | |
29 | +#include <malloc.h> | |
30 | +#include <search.h> | |
31 | +#include <ubi_uboot.h> | |
32 | +#undef crc32 | |
33 | + | |
34 | +char *env_name_spec = "UBI"; | |
35 | + | |
36 | +env_t *env_ptr; | |
37 | + | |
38 | +DECLARE_GLOBAL_DATA_PTR; | |
39 | + | |
40 | +int env_init(void) | |
41 | +{ | |
42 | + /* use default */ | |
43 | + gd->env_addr = (ulong)&default_environment[0]; | |
44 | + gd->env_valid = 1; | |
45 | + | |
46 | + return 0; | |
47 | +} | |
48 | + | |
49 | +#ifdef CONFIG_CMD_SAVEENV | |
50 | +int saveenv(void) | |
51 | +{ | |
52 | + ALLOC_CACHE_ALIGN_BUFFER(env_t, env_new, 1); | |
53 | + ssize_t len; | |
54 | + char *res; | |
55 | + | |
56 | + res = (char *)&env_new->data; | |
57 | + len = hexport_r(&env_htab, '\0', 0, &res, ENV_SIZE, 0, NULL); | |
58 | + if (len < 0) { | |
59 | + error("Cannot export environment: errno = %d\n", errno); | |
60 | + return 1; | |
61 | + } | |
62 | + | |
63 | + if (ubi_part(CONFIG_ENV_UBI_PART, NULL)) { | |
64 | + printf("\n** Cannot find mtd partition \"%s\"\n", | |
65 | + CONFIG_ENV_UBI_PART); | |
66 | + return 1; | |
67 | + } | |
68 | + | |
69 | + env_new->crc = crc32(0, env_new->data, ENV_SIZE); | |
70 | + | |
71 | + if (ubi_volume_write(CONFIG_ENV_UBI_VOLUME, (void *)env_new, | |
72 | + CONFIG_ENV_SIZE)) { | |
73 | + printf("\n** Unable to write env to %s:%s **\n", | |
74 | + CONFIG_ENV_UBI_PART, CONFIG_ENV_UBI_VOLUME); | |
75 | + return 1; | |
76 | + } | |
77 | + | |
78 | + puts("done\n"); | |
79 | + return 0; | |
80 | +} | |
81 | +#endif /* CONFIG_CMD_SAVEENV */ | |
82 | + | |
83 | +void env_relocate_spec(void) | |
84 | +{ | |
85 | + ALLOC_CACHE_ALIGN_BUFFER(char, buf, CONFIG_ENV_SIZE); | |
86 | + | |
87 | + if (ubi_part(CONFIG_ENV_UBI_PART, NULL)) { | |
88 | + printf("\n** Cannot find mtd partition \"%s\"\n", | |
89 | + CONFIG_ENV_UBI_PART); | |
90 | + set_default_env(NULL); | |
91 | + return; | |
92 | + } | |
93 | + | |
94 | + if (ubi_volume_read(CONFIG_ENV_UBI_VOLUME, (void *)&buf, | |
95 | + CONFIG_ENV_SIZE)) { | |
96 | + printf("\n** Unable to read env from %s:%s **\n", | |
97 | + CONFIG_ENV_UBI_PART, CONFIG_ENV_UBI_VOLUME); | |
98 | + set_default_env(NULL); | |
99 | + return; | |
100 | + } | |
101 | + | |
102 | + env_import(buf, 1); | |
103 | +} |
include/environment.h
... | ... | @@ -96,6 +96,21 @@ |
96 | 96 | # endif |
97 | 97 | #endif /* CONFIG_ENV_IS_IN_NAND */ |
98 | 98 | |
99 | +#if defined(CONFIG_ENV_IS_IN_UBI) | |
100 | +# ifndef CONFIG_ENV_UBI_PART | |
101 | +# error "Need to define CONFIG_ENV_UBI_PART when using CONFIG_ENV_IS_IN_UBI" | |
102 | +# endif | |
103 | +# ifndef CONFIG_ENV_UBI_VOLUME | |
104 | +# error "Need to define CONFIG_ENV_UBI_VOLUME when using CONFIG_ENV_IS_IN_UBI" | |
105 | +# endif | |
106 | +# ifndef CONFIG_ENV_SIZE | |
107 | +# error "Need to define CONFIG_ENV_SIZE when using CONFIG_ENV_IS_IN_UBI" | |
108 | +# endif | |
109 | +# ifndef CONFIG_CMD_UBI | |
110 | +# error "Need to define CONFIG_CMD_UBI when using CONFIG_ENV_IS_IN_UBI" | |
111 | +# endif | |
112 | +#endif /* CONFIG_ENV_IS_IN_UBI */ | |
113 | + | |
99 | 114 | /* Embedded env is only supported for some flash types */ |
100 | 115 | #ifdef CONFIG_ENV_IS_EMBEDDED |
101 | 116 | # if !defined(CONFIG_ENV_IS_IN_FLASH) && \ |
tools/env/fw_env.c
... | ... | @@ -968,7 +968,8 @@ |
968 | 968 | } |
969 | 969 | if (mtdinfo.type != MTD_NORFLASH && |
970 | 970 | mtdinfo.type != MTD_NANDFLASH && |
971 | - mtdinfo.type != MTD_DATAFLASH) { | |
971 | + mtdinfo.type != MTD_DATAFLASH && | |
972 | + mtdinfo.type != MTD_UBIVOLUME) { | |
972 | 973 | fprintf (stderr, "Unsupported flash type %u on %s\n", |
973 | 974 | mtdinfo.type, DEVNAME(dev_current)); |
974 | 975 | return -1; |