Blame view
env/onenand.c
2.44 KB
d7e8ce101 OneNAND support (... |
1 |
/* |
ea882baf9 New implementatio... |
2 3 4 |
* (C) Copyright 2010 DENX Software Engineering * Wolfgang Denk <wd@denx.de> * |
937076f84 MTD: OneNAND: Inc... |
5 |
* (C) Copyright 2005-2009 Samsung Electronics |
d7e8ce101 OneNAND support (... |
6 7 |
* Kyungmin Park <kyungmin.park@samsung.com> * |
1a4596601 Add GPL-2.0+ SPDX... |
8 |
* SPDX-License-Identifier: GPL-2.0+ |
d7e8ce101 OneNAND support (... |
9 10 11 |
*/ #include <common.h> |
d7e8ce101 OneNAND support (... |
12 13 14 15 |
#include <command.h> #include <environment.h> #include <linux/stddef.h> #include <malloc.h> |
ea882baf9 New implementatio... |
16 17 |
#include <search.h> #include <errno.h> |
b919ec25e env: clean env_on... |
18 |
#include <onenand_uboot.h> |
d7e8ce101 OneNAND support (... |
19 |
|
7b15e2bb9 linux/compat.h: r... |
20 |
#include <linux/compat.h> |
d7e8ce101 OneNAND support (... |
21 22 |
#include <linux/mtd/mtd.h> #include <linux/mtd/onenand.h> |
034afbcc1 env_onenand: set ... |
23 |
#define ONENAND_MAX_ENV_SIZE CONFIG_ENV_SIZE |
937076f84 MTD: OneNAND: Inc... |
24 |
#define ONENAND_ENV_SIZE(mtd) (ONENAND_MAX_ENV_SIZE - ENV_HEADER_SIZE) |
a9da2b410 Fix OneNAND erase... |
25 |
DECLARE_GLOBAL_DATA_PTR; |
c59519919 env: Adjust the l... |
26 |
static int env_onenand_load(void) |
d7e8ce101 OneNAND support (... |
27 |
{ |
937076f84 MTD: OneNAND: Inc... |
28 |
struct mtd_info *mtd = &onenand_mtd; |
b821cead7 onenand: Fix comp... |
29 |
#ifdef CONFIG_ENV_ADDR_FLEX |
c758e947a ENV Variable supp... |
30 |
struct onenand_chip *this = &onenand_chip; |
b821cead7 onenand: Fix comp... |
31 |
#endif |
ea882baf9 New implementatio... |
32 |
int rc; |
2ae64f513 Remove warnings r... |
33 |
size_t retlen; |
ea882baf9 New implementatio... |
34 |
#ifdef ENV_IS_EMBEDDED |
994bc671c env: move extern ... |
35 |
char *buf = (char *)&environment; |
ea882baf9 New implementatio... |
36 37 |
#else loff_t env_addr = CONFIG_ENV_ADDR; |
cd0f4fa1c Revert "env: fix ... |
38 39 |
char onenand_env[ONENAND_MAX_ENV_SIZE]; char *buf = (char *)&onenand_env[0]; |
ea882baf9 New implementatio... |
40 |
#endif /* ENV_IS_EMBEDDED */ |
d7e8ce101 OneNAND support (... |
41 |
|
ea882baf9 New implementatio... |
42 43 |
#ifndef ENV_IS_EMBEDDED # ifdef CONFIG_ENV_ADDR_FLEX |
c758e947a ENV Variable supp... |
44 45 |
if (FLEXONENAND(this)) env_addr = CONFIG_ENV_ADDR_FLEX; |
ea882baf9 New implementatio... |
46 |
# endif |
d7e8ce101 OneNAND support (... |
47 |
/* Check OneNAND exist */ |
937076f84 MTD: OneNAND: Inc... |
48 |
if (mtd->writesize) |
d7e8ce101 OneNAND support (... |
49 |
/* Ignore read fail */ |
dfe64e2c8 mtd: resync with ... |
50 |
mtd_read(mtd, env_addr, ONENAND_MAX_ENV_SIZE, |
b919ec25e env: clean env_on... |
51 |
&retlen, (u_char *)buf); |
d7e8ce101 OneNAND support (... |
52 |
else |
937076f84 MTD: OneNAND: Inc... |
53 |
mtd->writesize = MAX_ONENAND_PAGESIZE; |
ea882baf9 New implementatio... |
54 |
#endif /* !ENV_IS_EMBEDDED */ |
d7e8ce101 OneNAND support (... |
55 |
|
ea882baf9 New implementatio... |
56 |
rc = env_import(buf, 1); |
42a1820bb env: make env_imp... |
57 |
if (!rc) |
203e94f6c env: Add an enum ... |
58 |
gd->env_valid = ENV_VALID; |
c59519919 env: Adjust the l... |
59 |
|
42a1820bb env: make env_imp... |
60 |
return rc; |
d7e8ce101 OneNAND support (... |
61 |
} |
e5bce247b env: Switch over ... |
62 |
static int env_onenand_save(void) |
d7e8ce101 OneNAND support (... |
63 |
{ |
cd0f4fa1c Revert "env: fix ... |
64 |
env_t env_new; |
7ce1526ed env: Add env_expo... |
65 |
int ret; |
937076f84 MTD: OneNAND: Inc... |
66 |
struct mtd_info *mtd = &onenand_mtd; |
b821cead7 onenand: Fix comp... |
67 |
#ifdef CONFIG_ENV_ADDR_FLEX |
c758e947a ENV Variable supp... |
68 |
struct onenand_chip *this = &onenand_chip; |
b821cead7 onenand: Fix comp... |
69 |
#endif |
ea882baf9 New implementatio... |
70 71 |
loff_t env_addr = CONFIG_ENV_ADDR; size_t retlen; |
a9da2b410 Fix OneNAND erase... |
72 73 74 |
struct erase_info instr = { .callback = NULL, }; |
ea882baf9 New implementatio... |
75 |
|
7ce1526ed env: Add env_expo... |
76 77 78 |
ret = env_export(&env_new); if (ret) return ret; |
d7e8ce101 OneNAND support (... |
79 |
|
0e8d15866 rename CFG_ENV ma... |
80 |
instr.len = CONFIG_ENV_SIZE; |
b821cead7 onenand: Fix comp... |
81 |
#ifdef CONFIG_ENV_ADDR_FLEX |
c758e947a ENV Variable supp... |
82 83 84 85 86 87 |
if (FLEXONENAND(this)) { env_addr = CONFIG_ENV_ADDR_FLEX; instr.len = CONFIG_ENV_SIZE_FLEX; instr.len <<= onenand_mtd.eraseregions[0].numblocks == 1 ? 1 : 0; } |
b821cead7 onenand: Fix comp... |
88 |
#endif |
d7e8ce101 OneNAND support (... |
89 |
instr.addr = env_addr; |
937076f84 MTD: OneNAND: Inc... |
90 |
instr.mtd = mtd; |
dfe64e2c8 mtd: resync with ... |
91 |
if (mtd_erase(mtd, &instr)) { |
482877923 Fix compiler warn... |
92 93 |
printf("OneNAND: erase failed at 0x%08llx ", env_addr); |
d7e8ce101 OneNAND support (... |
94 95 |
return 1; } |
dfe64e2c8 mtd: resync with ... |
96 |
if (mtd_write(mtd, env_addr, ONENAND_MAX_ENV_SIZE, &retlen, |
cd0f4fa1c Revert "env: fix ... |
97 |
(u_char *)&env_new)) { |
8d2effea2 mtd: Update MTD i... |
98 99 |
printf("OneNAND: write failed at 0x%llx ", instr.addr); |
d7e8ce101 OneNAND support (... |
100 101 102 103 104 |
return 2; } return 0; } |
4415f1d1f env: Create a loc... |
105 106 |
U_BOOT_ENV_LOCATION(onenand) = { .location = ENVL_ONENAND, |
ac358beb8 env: Drop the env... |
107 |
ENV_NAME("OneNAND") |
e5bce247b env: Switch over ... |
108 109 |
.load = env_onenand_load, .save = env_save_ptr(env_onenand_save), |
4415f1d1f env: Create a loc... |
110 |
}; |