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 705a1aceb0SJean-Christophe PLAGNIOL-VILLARD #endif /* CONFIG_ENV_IS_IN_FLASH */ 71c609719bSwdenk 7251bfee19SJean-Christophe PLAGNIOL-VILLARD #if defined(CONFIG_ENV_IS_IN_NAND) 730e8d1586SJean-Christophe PLAGNIOL-VILLARD # ifndef CONFIG_ENV_OFFSET 740e8d1586SJean-Christophe PLAGNIOL-VILLARD # error "Need to define CONFIG_ENV_OFFSET when using CONFIG_ENV_IS_IN_NAND" 75e443c944SMarkus Klotzbuecher # endif 760e8d1586SJean-Christophe PLAGNIOL-VILLARD # ifndef CONFIG_ENV_SIZE 770e8d1586SJean-Christophe PLAGNIOL-VILLARD # error "Need to define CONFIG_ENV_SIZE when using CONFIG_ENV_IS_IN_NAND" 78e443c944SMarkus Klotzbuecher # endif 790e8d1586SJean-Christophe PLAGNIOL-VILLARD # ifdef CONFIG_ENV_OFFSET_REDUND 806d0f6bcfSJean-Christophe PLAGNIOL-VILLARD # define CONFIG_SYS_REDUNDAND_ENVIRONMENT 81e443c944SMarkus Klotzbuecher # endif 820e8d1586SJean-Christophe PLAGNIOL-VILLARD # ifdef CONFIG_ENV_IS_EMBEDDED 83d12ae808SStefan Roese # define ENV_IS_EMBEDDED 1 84d12ae808SStefan Roese # endif 8551bfee19SJean-Christophe PLAGNIOL-VILLARD #endif /* CONFIG_ENV_IS_IN_NAND */ 86e443c944SMarkus Klotzbuecher 87*75eb82ecSunsik Kim #if defined(CONFIG_ENV_IS_IN_MG_DISK) 88*75eb82ecSunsik Kim # ifndef CONFIG_ENV_ADDR 89*75eb82ecSunsik Kim # error "Need to define CONFIG_ENV_ADDR when using CONFIG_ENV_IS_IN_MG_DISK" 90*75eb82ecSunsik Kim # endif 91*75eb82ecSunsik Kim # ifndef CONFIG_ENV_SIZE 92*75eb82ecSunsik Kim # error "Need to define CONFIG_ENV_SIZE when using CONFIG_ENV_IS_IN_MG_DISK" 93*75eb82ecSunsik Kim # endif 94*75eb82ecSunsik Kim # ifdef CONFIG_ENV_IS_EMBEDDED 95*75eb82ecSunsik Kim # error "CONFIG_ENV_IS_EMBEDDED not supported when using CONFIG_ENV_IS_IN_MG_DISK" 96*75eb82ecSunsik Kim # endif 97*75eb82ecSunsik Kim #endif /* CONFIG_ENV_IS_IN_MG_DISK */ 98*75eb82ecSunsik Kim 9989cdab78SMike Frysinger #ifdef USE_HOSTCC 10089cdab78SMike Frysinger # include <stdint.h> 10189cdab78SMike Frysinger #else 10289cdab78SMike Frysinger # include <linux/types.h> 10389cdab78SMike Frysinger #endif 104c609719bSwdenk 1056d0f6bcfSJean-Christophe PLAGNIOL-VILLARD #ifdef CONFIG_SYS_REDUNDAND_ENVIRONMENT 10689cdab78SMike Frysinger # define ENV_HEADER_SIZE (sizeof(uint32_t) + 1) 107c609719bSwdenk #else 10889cdab78SMike Frysinger # define ENV_HEADER_SIZE (sizeof(uint32_t)) 109c609719bSwdenk #endif 110c609719bSwdenk 111c609719bSwdenk 1120e8d1586SJean-Christophe PLAGNIOL-VILLARD #define ENV_SIZE (CONFIG_ENV_SIZE - ENV_HEADER_SIZE) 113c609719bSwdenk 114c609719bSwdenk typedef struct environment_s { 11589cdab78SMike Frysinger uint32_t crc; /* CRC32 over data bytes */ 1166d0f6bcfSJean-Christophe PLAGNIOL-VILLARD #ifdef CONFIG_SYS_REDUNDAND_ENVIRONMENT 117c609719bSwdenk unsigned char flags; /* active/obsolete flags */ 118c609719bSwdenk #endif 119c609719bSwdenk unsigned char data[ENV_SIZE]; /* Environment data */ 120c609719bSwdenk } env_t; 121c609719bSwdenk 122b502611bSJoakim Tjernlund /* Function that returns a character from the environment */ 123b502611bSJoakim Tjernlund unsigned char env_get_char (int); 124a8409f4fSWolfgang Denk 125a8409f4fSWolfgang Denk /* Function that returns a pointer to a value from the environment */ 126a8409f4fSWolfgang Denk unsigned char *env_get_addr(int); 127a8409f4fSWolfgang Denk unsigned char env_get_char_memory (int index); 128a8409f4fSWolfgang Denk 129a8409f4fSWolfgang Denk /* Function that updates CRC of the enironment */ 130a8409f4fSWolfgang Denk void env_crc_update (void); 131a8409f4fSWolfgang Denk 1325bb12dbdSHarald Welte /* [re]set to the default environment */ 1335bb12dbdSHarald Welte void set_default_env(void); 1345bb12dbdSHarald Welte 135c609719bSwdenk #endif /* _ENVIRONMENT_H_ */ 136