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