5 * See file CREDITS for list of people who contributed to this
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.
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.
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,
27 #include <environment.h>
31 #include <asm/processor.h>
35 DECLARE_GLOBAL_DATA_PTR;
37 #define REBOOT_MAGIC 0x07081967
38 #define REBOOT_NOP 0x00000000
39 #define REBOOT_DO_POST 0x00000001
41 extern flash_info_t flash_info[CFG_MAX_FLASH_BANKS]; /* info for FLASH chips */
42 extern env_t *env_ptr;
43 extern uchar default_environment[];
45 ulong flash_get_size(ulong base, int banknum);
46 void env_crc_update(void);
47 int do_reset (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
49 static u32 start_time;
51 int board_early_init_f(void)
53 mtdcr(uicsr, 0xFFFFFFFF); /* clear all ints */
54 mtdcr(uicer, 0x00000000); /* disable all ints */
55 mtdcr(uiccr, 0x00000000);
56 mtdcr(uicpr, 0xFFFF7F00); /* set int polarities */
57 mtdcr(uictr, 0x00000000); /* set int trigger levels */
58 mtdcr(uicsr, 0xFFFFFFFF); /* clear all ints */
59 mtdcr(uicvcr, 0x00000001); /* set vect base=0,INT0 highest priority */
62 * Configure CPC0_PCI to enable PerWE as output
64 mtdcr(cpc0_pci, CPC0_PCI_SPE);
76 post_magic = in_be32((void *)CFG_POST_MAGIC);
77 post_val = in_be32((void *)CFG_POST_VAL);
78 if ((post_magic == REBOOT_MAGIC) && (post_val == REBOOT_DO_POST)) {
80 * Set special bootline bootparameter to pass this POST boot
81 * mode to Linux to reset the username/password
83 setenv("addmisc", "setenv bootargs \\${bootargs} factory_reset=yes");
86 * Normally don't run POST tests, only when enabled
87 * via the sw-reset button. So disable further tests
88 * upon next bootup here.
90 out_be32((void *)CFG_POST_VAL, REBOOT_NOP);
93 * Only run POST when initiated via the sw-reset button mechanism
101 start_time = get_timer(0);
107 /* Re-do sizing to get full correct info */
109 /* adjust flash start and offset */
111 switch (gd->bd->bi_flashsize) {
137 pbcr = (pbcr & 0x0001ffff) | gd->bd->bi_flashstart | (size_val << 17);
141 * Re-check to get correct base address
143 flash_get_size(gd->bd->bi_flashstart, 0);
145 /* Monitor protection ON by default */
146 (void)flash_protect(FLAG_PROTECT_SET,
151 /* Env protection ON by default */
152 (void)flash_protect(FLAG_PROTECT_SET,
154 CFG_ENV_ADDR_REDUND + 2*CFG_ENV_SECT_SIZE - 1,
161 * Check Board Identity:
165 char *s = getenv("serial#");
167 puts("Board: Zeus-");
169 if (in_be32((void *)GPIO0_IR) & GPIO_VAL(CFG_GPIO_ZEUS_PE))
174 puts(" of BulletEndPoint");
183 gpio_write_bit(CFG_GPIO_LED_RED, 0);
184 gpio_write_bit(CFG_GPIO_LED_GREEN, 0);
187 gpio_write_bit(CFG_GPIO_LED_RED, 1);
188 gpio_write_bit(CFG_GPIO_LED_GREEN, 1);
193 static u32 detect_sdram_size(void)
198 mfsdram(mem_mb0cf, val);
199 size = (4 << 20) << ((val & 0x000e0000) >> 17);
202 * Check if 2nd bank is enabled too
204 mfsdram(mem_mb1cf, val);
206 size += (4 << 20) << ((val & 0x000e0000) >> 17);
211 phys_size_t initdram (int board_type)
213 return detect_sdram_size();
216 static int default_env_var(char *buf, char *var)
224 ptr = strstr(buf + 4, var);
226 printf("ERROR: %s not found!\n", var);
229 ptr += strlen(var) + 1;
232 * Now the ethaddr needs to be updated in the "normal"
233 * environment storage -> redundant flash.
237 printf("Updated %s from eeprom to %s!\n", var, val);
242 static int restore_default(void)
249 * Unprotect and erase environment area
251 flash_protect(FLAG_PROTECT_CLEAR,
253 CFG_ENV_ADDR_REDUND + 2*CFG_ENV_SECT_SIZE - 1,
256 flash_sect_erase(CFG_ENV_ADDR_REDUND,
257 CFG_ENV_ADDR_REDUND + 2*CFG_ENV_SECT_SIZE - 1);
260 * Now restore default environment from U-Boot image
261 * -> ipaddr, serverip...
263 memset(env_ptr, 0, sizeof(env_t));
264 memcpy(env_ptr->data, default_environment, ENV_SIZE);
265 #ifdef CFG_REDUNDAND_ENVIRONMENT
266 env_ptr->flags = 0xFF;
272 * Read board specific values from I2C EEPROM
273 * and set env variables accordingly
274 * -> ethaddr, eth1addr, serial#
276 buf = buf_save = malloc(FACTORY_RESET_ENV_SIZE);
277 if (eeprom_read(FACTORY_RESET_I2C_EEPROM, FACTORY_RESET_ENV_OFFS,
278 (u8 *)buf, FACTORY_RESET_ENV_SIZE)) {
279 puts("\nError reading EEPROM!\n");
281 crc = crc32(0, (u8 *)(buf + 4), FACTORY_RESET_ENV_SIZE - 4);
282 if (crc != *(u32 *)buf) {
283 printf("ERROR: crc mismatch %08x %08x\n", crc, *(u32 *)buf);
287 default_env_var(buf, "ethaddr");
289 default_env_var(buf, "eth1addr");
291 default_env_var(buf, "serial#");
295 * Finally save updated env variables back to flash
304 int do_set_default(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
317 buf = buf_save = malloc(FACTORY_RESET_ENV_SIZE);
318 memset(buf, 0, FACTORY_RESET_ENV_SIZE);
320 strcpy(var, "ethaddr");
321 printf("Setting %s to %s\n", var, argv[1]);
322 sprintf(str, "%s=%s", var, argv[1]);
323 strcpy(buf + 4, str);
324 buf += strlen(str) + 1;
326 strcpy(var, "eth1addr");
327 printf("Setting %s to %s\n", var, argv[2]);
328 sprintf(str, "%s=%s", var, argv[2]);
329 strcpy(buf + 4, str);
330 buf += strlen(str) + 1;
332 strcpy(var, "serial#");
333 printf("Setting %s to %s\n", var, argv[3]);
334 sprintf(str, "%s=%s", var, argv[3]);
335 strcpy(buf + 4, str);
337 crc = crc32(0, (u8 *)(buf_save + 4), FACTORY_RESET_ENV_SIZE - 4);
338 *(u32 *)buf_save = crc;
340 if (eeprom_write(FACTORY_RESET_I2C_EEPROM, FACTORY_RESET_ENV_OFFS,
341 (u8 *)buf_save, FACTORY_RESET_ENV_SIZE)) {
342 puts("\nError writing EEPROM!\n");
352 setdef, 4, 1, do_set_default,
353 "setdef - write board-specific values to EEPROM (ethaddr...)\n",
354 "ethaddr eth1addr serial#\n - write board-specific values to EEPROM\n"
357 static inline int sw_reset_pressed(void)
359 return !(in_be32((void *)GPIO0_IR) & GPIO_VAL(CFG_GPIO_SW_RESET));
362 int do_chkreset(cmd_tbl_t* cmdtp, int flag, int argc, char* argv[])
367 int factory_reset = 0;
369 if (!sw_reset_pressed()) {
370 printf("SW-Reset already high (Button released)\n");
371 printf("-> No action taken!\n");
375 printf("Waiting for SW-Reset button to be released.");
378 delta = get_timer(start_time);
379 if (!sw_reset_pressed())
382 if ((delta > CFG_TIME_POST) && !post) {
383 printf("\nWhen released now, POST tests will be started.");
384 gpio_write_bit(CFG_GPIO_LED_GREEN, 0);
388 if ((delta > CFG_TIME_FACTORY_RESET) && !factory_reset) {
389 printf("\nWhen released now, factory default values"
390 " will be restored.");
391 gpio_write_bit(CFG_GPIO_LED_RED, 0);
396 if (!(count++ % 1000))
401 printf("\nSW-Reset Button released after %d milli-seconds!\n", delta);
403 if (delta > CFG_TIME_FACTORY_RESET) {
404 printf("Starting factory reset value restoration...\n");
407 * Restore default setting
412 * Reset the board for default to become valid
414 do_reset(NULL, 0, 0, NULL);
419 if (delta > CFG_TIME_POST) {
420 printf("Starting POST configuration...\n");
423 * Enable POST upon next bootup
425 out_be32((void *)CFG_POST_MAGIC, REBOOT_MAGIC);
426 out_be32((void *)CFG_POST_VAL, REBOOT_DO_POST);
427 post_bootmode_init();
430 * Reset the logbuffer for a clean start
434 do_reset(NULL, 0, 0, NULL);
443 chkreset, 1, 1, do_chkreset,
444 "chkreset- Check for status of SW-reset button and act accordingly\n",
448 #if defined(CONFIG_POST)
450 * Returns 1 if keys pressed to start the power-on long-running tests
451 * Called from board_init_f().
453 int post_hotkeys_pressed(void)
458 post_magic = in_be32((void *)CFG_POST_MAGIC);
459 post_val = in_be32((void *)CFG_POST_VAL);
461 if ((post_magic == REBOOT_MAGIC) && (post_val == REBOOT_DO_POST))
466 #endif /* CONFIG_POST */