1c609719bSwdenk /* 2c609719bSwdenk * (C) Copyright 2002 3c609719bSwdenk * Wolfgang Denk, DENX Software Engineering, wd@denx.de. 4c609719bSwdenk * 5c609719bSwdenk * See file CREDITS for list of people who contributed to this 6c609719bSwdenk * project. 7c609719bSwdenk * 8c609719bSwdenk * This program is free software; you can redistribute it and/or 9c609719bSwdenk * modify it under the terms of the GNU General Public License as 10c609719bSwdenk * published by the Free Software Foundation; either version 2 of 11c609719bSwdenk * the License, or (at your option) any later version. 12c609719bSwdenk * 13c609719bSwdenk * This program is distributed in the hope that it will be useful, 14c609719bSwdenk * but WITHOUT ANY WARRANTY; without even the implied warranty of 15c609719bSwdenk * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16c609719bSwdenk * GNU General Public License for more details. 17c609719bSwdenk * 18c609719bSwdenk * You should have received a copy of the GNU General Public License 19c609719bSwdenk * along with this program; if not, write to the Free Software 20c609719bSwdenk * Foundation, Inc., 59 Temple Place, Suite 330, Boston, 21c609719bSwdenk * MA 02111-1307 USA 22c609719bSwdenk */ 23c609719bSwdenk 24c609719bSwdenk #ifndef _ENVIRONMENT_H_ 25c609719bSwdenk #define _ENVIRONMENT_H_ 1 26c609719bSwdenk 27c609719bSwdenk /************************************************************************** 28c609719bSwdenk * 29c609719bSwdenk * The "environment" is stored as a list of '\0' terminated 30c609719bSwdenk * "name=value" strings. The end of the list is marked by a double 31c609719bSwdenk * '\0'. New entries are always added at the end. Deleting an entry 32c609719bSwdenk * shifts the remaining entries to the front. Replacing an entry is a 33c609719bSwdenk * combination of deleting the old value and adding the new one. 34c609719bSwdenk * 35c609719bSwdenk * The environment is preceeded by a 32 bit CRC over the data part. 36c609719bSwdenk * 37c609719bSwdenk ************************************************************************** 38c609719bSwdenk */ 39c609719bSwdenk 405a1aceb0SJean-Christophe PLAGNIOL-VILLARD #if defined(CONFIG_ENV_IS_IN_FLASH) 410e8d1586SJean-Christophe PLAGNIOL-VILLARD # ifndef CONFIG_ENV_ADDR 426d0f6bcfSJean-Christophe PLAGNIOL-VILLARD # define CONFIG_ENV_ADDR (CONFIG_SYS_FLASH_BASE + CONFIG_ENV_OFFSET) 43c609719bSwdenk # endif 440e8d1586SJean-Christophe PLAGNIOL-VILLARD # ifndef CONFIG_ENV_OFFSET 456d0f6bcfSJean-Christophe PLAGNIOL-VILLARD # define CONFIG_ENV_OFFSET (CONFIG_ENV_ADDR - CONFIG_SYS_FLASH_BASE) 46c609719bSwdenk # endif 470e8d1586SJean-Christophe PLAGNIOL-VILLARD # if !defined(CONFIG_ENV_ADDR_REDUND) && defined(CONFIG_ENV_OFFSET_REDUND) 486d0f6bcfSJean-Christophe PLAGNIOL-VILLARD # define CONFIG_ENV_ADDR_REDUND (CONFIG_SYS_FLASH_BASE + CONFIG_ENV_OFFSET_REDUND) 49c609719bSwdenk # endif 500e8d1586SJean-Christophe PLAGNIOL-VILLARD # if defined(CONFIG_ENV_SECT_SIZE) || defined(CONFIG_ENV_SIZE) 510e8d1586SJean-Christophe PLAGNIOL-VILLARD # ifndef CONFIG_ENV_SECT_SIZE 520e8d1586SJean-Christophe PLAGNIOL-VILLARD # define CONFIG_ENV_SECT_SIZE CONFIG_ENV_SIZE 53500545ccSwdenk # endif 540e8d1586SJean-Christophe PLAGNIOL-VILLARD # ifndef CONFIG_ENV_SIZE 550e8d1586SJean-Christophe PLAGNIOL-VILLARD # define CONFIG_ENV_SIZE CONFIG_ENV_SECT_SIZE 56c609719bSwdenk # endif 57500545ccSwdenk # else 580e8d1586SJean-Christophe PLAGNIOL-VILLARD # error "Both CONFIG_ENV_SECT_SIZE and CONFIG_ENV_SIZE undefined" 59500545ccSwdenk # endif 600e8d1586SJean-Christophe PLAGNIOL-VILLARD # if defined(CONFIG_ENV_ADDR_REDUND) && !defined(CONFIG_ENV_SIZE_REDUND) 610e8d1586SJean-Christophe PLAGNIOL-VILLARD # define CONFIG_ENV_SIZE_REDUND CONFIG_ENV_SIZE 62c609719bSwdenk # endif 636d0f6bcfSJean-Christophe PLAGNIOL-VILLARD # if (CONFIG_ENV_ADDR >= CONFIG_SYS_MONITOR_BASE) && \ 646d0f6bcfSJean-Christophe PLAGNIOL-VILLARD (CONFIG_ENV_ADDR+CONFIG_ENV_SIZE) <= (CONFIG_SYS_MONITOR_BASE + CONFIG_SYS_MONITOR_LEN) 65c609719bSwdenk # define ENV_IS_EMBEDDED 1 66c609719bSwdenk # endif 670e8d1586SJean-Christophe PLAGNIOL-VILLARD # if defined(CONFIG_ENV_ADDR_REDUND) || defined(CONFIG_ENV_OFFSET_REDUND) 686d0f6bcfSJean-Christophe PLAGNIOL-VILLARD # define CONFIG_SYS_REDUNDAND_ENVIRONMENT 1 69c609719bSwdenk # endif 70*0a9e4e77SMike Frysinger # ifdef CONFIG_ENV_IS_EMBEDDED 71*0a9e4e77SMike Frysinger # error "do not define CONFIG_ENV_IS_EMBEDDED in your board config" 72*0a9e4e77SMike Frysinger # error "it is calculated automatically for you" 73*0a9e4e77SMike Frysinger # endif 745a1aceb0SJean-Christophe PLAGNIOL-VILLARD #endif /* CONFIG_ENV_IS_IN_FLASH */ 75c609719bSwdenk 7651bfee19SJean-Christophe PLAGNIOL-VILLARD #if defined(CONFIG_ENV_IS_IN_NAND) 770e8d1586SJean-Christophe PLAGNIOL-VILLARD # ifndef CONFIG_ENV_OFFSET 780e8d1586SJean-Christophe PLAGNIOL-VILLARD # error "Need to define CONFIG_ENV_OFFSET when using CONFIG_ENV_IS_IN_NAND" 79e443c944SMarkus Klotzbuecher # endif 800e8d1586SJean-Christophe PLAGNIOL-VILLARD # ifndef CONFIG_ENV_SIZE 810e8d1586SJean-Christophe PLAGNIOL-VILLARD # error "Need to define CONFIG_ENV_SIZE when using CONFIG_ENV_IS_IN_NAND" 82e443c944SMarkus Klotzbuecher # endif 830e8d1586SJean-Christophe PLAGNIOL-VILLARD # ifdef CONFIG_ENV_OFFSET_REDUND 846d0f6bcfSJean-Christophe PLAGNIOL-VILLARD # define CONFIG_SYS_REDUNDAND_ENVIRONMENT 85e443c944SMarkus Klotzbuecher # endif 8651bfee19SJean-Christophe PLAGNIOL-VILLARD #endif /* CONFIG_ENV_IS_IN_NAND */ 87e443c944SMarkus Klotzbuecher 8875eb82ecSunsik Kim #if defined(CONFIG_ENV_IS_IN_MG_DISK) 8975eb82ecSunsik Kim # ifndef CONFIG_ENV_ADDR 9075eb82ecSunsik Kim # error "Need to define CONFIG_ENV_ADDR when using CONFIG_ENV_IS_IN_MG_DISK" 9175eb82ecSunsik Kim # endif 9275eb82ecSunsik Kim # ifndef CONFIG_ENV_SIZE 9375eb82ecSunsik Kim # error "Need to define CONFIG_ENV_SIZE when using CONFIG_ENV_IS_IN_MG_DISK" 9475eb82ecSunsik Kim # endif 9575eb82ecSunsik Kim #endif /* CONFIG_ENV_IS_IN_MG_DISK */ 9675eb82ecSunsik Kim 97*0a9e4e77SMike Frysinger /* Embedded env is only supported for some flash types */ 98*0a9e4e77SMike Frysinger #ifdef CONFIG_ENV_IS_EMBEDDED 99*0a9e4e77SMike Frysinger # if !defined(CONFIG_ENV_IS_IN_FLASH) && \ 100*0a9e4e77SMike Frysinger !defined(CONFIG_ENV_IS_IN_NAND) && \ 101*0a9e4e77SMike Frysinger !defined(CONFIG_ENV_IS_IN_ONENAND) 102*0a9e4e77SMike Frysinger # error "CONFIG_ENV_IS_EMBEDDED not supported for your flash type" 103*0a9e4e77SMike Frysinger # endif 104*0a9e4e77SMike Frysinger #endif 105*0a9e4e77SMike Frysinger 106*0a9e4e77SMike Frysinger /* 107*0a9e4e77SMike Frysinger * For the flash types where embedded env is supported, but it cannot be 108*0a9e4e77SMike Frysinger * calculated automatically (i.e. NAND), take the board opt-in. 109*0a9e4e77SMike Frysinger */ 110*0a9e4e77SMike Frysinger #if defined(CONFIG_ENV_IS_EMBEDDED) && !defined(ENV_IS_EMBEDDED) 111*0a9e4e77SMike Frysinger # define ENV_IS_EMBEDDED 1 112*0a9e4e77SMike Frysinger #endif 113*0a9e4e77SMike Frysinger 114*0a9e4e77SMike Frysinger /* The build system likes to know if the env is embedded */ 115*0a9e4e77SMike Frysinger #ifdef DO_DEPS_ONLY 116*0a9e4e77SMike Frysinger # ifdef ENV_IS_EMBEDDED 117*0a9e4e77SMike Frysinger # define CONFIG_ENV_IS_EMBEDDED 118*0a9e4e77SMike Frysinger # endif 119*0a9e4e77SMike Frysinger #endif 120*0a9e4e77SMike Frysinger 12137566090SMike Frysinger #include "compiler.h" 122c609719bSwdenk 1236d0f6bcfSJean-Christophe PLAGNIOL-VILLARD #ifdef CONFIG_SYS_REDUNDAND_ENVIRONMENT 12489cdab78SMike Frysinger # define ENV_HEADER_SIZE (sizeof(uint32_t) + 1) 125c609719bSwdenk #else 12689cdab78SMike Frysinger # define ENV_HEADER_SIZE (sizeof(uint32_t)) 127c609719bSwdenk #endif 128c609719bSwdenk 129c609719bSwdenk 1300e8d1586SJean-Christophe PLAGNIOL-VILLARD #define ENV_SIZE (CONFIG_ENV_SIZE - ENV_HEADER_SIZE) 131c609719bSwdenk 132c609719bSwdenk typedef struct environment_s { 13389cdab78SMike Frysinger uint32_t crc; /* CRC32 over data bytes */ 1346d0f6bcfSJean-Christophe PLAGNIOL-VILLARD #ifdef CONFIG_SYS_REDUNDAND_ENVIRONMENT 135c609719bSwdenk unsigned char flags; /* active/obsolete flags */ 136c609719bSwdenk #endif 137c609719bSwdenk unsigned char data[ENV_SIZE]; /* Environment data */ 138c609719bSwdenk } env_t; 139c609719bSwdenk 140b502611bSJoakim Tjernlund /* Function that returns a character from the environment */ 141b502611bSJoakim Tjernlund unsigned char env_get_char (int); 142a8409f4fSWolfgang Denk 143a8409f4fSWolfgang Denk /* Function that returns a pointer to a value from the environment */ 144a8409f4fSWolfgang Denk unsigned char *env_get_addr(int); 145a8409f4fSWolfgang Denk unsigned char env_get_char_memory (int index); 146a8409f4fSWolfgang Denk 147a8409f4fSWolfgang Denk /* Function that updates CRC of the enironment */ 148a8409f4fSWolfgang Denk void env_crc_update (void); 149a8409f4fSWolfgang Denk 1505bb12dbdSHarald Welte /* [re]set to the default environment */ 1515bb12dbdSHarald Welte void set_default_env(void); 1525bb12dbdSHarald Welte 153c609719bSwdenk #endif /* _ENVIRONMENT_H_ */ 154