3 * Stefan Roese, DENX Software Engineering, sr@denx.de.
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>
33 #include <asm/ppc4xx-gpio.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
[CONFIG_SYS_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);
48 static u32 start_time
;
50 int board_early_init_f(void)
52 mtdcr(UIC0SR
, 0xFFFFFFFF); /* clear all ints */
53 mtdcr(UIC0ER
, 0x00000000); /* disable all ints */
54 mtdcr(UIC0CR
, 0x00000000);
55 mtdcr(UIC0PR
, 0xFFFF7F00); /* set int polarities */
56 mtdcr(UIC0TR
, 0x00000000); /* set int trigger levels */
57 mtdcr(UIC0SR
, 0xFFFFFFFF); /* clear all ints */
58 mtdcr(UIC0VCR
, 0x00000001); /* set vect base=0,INT0 highest priority */
61 * Configure CPC0_PCI to enable PerWE as output
63 mtdcr(CPC0_PCI
, CPC0_PCI_SPE
);
75 post_magic
= in_be32((void *)CONFIG_SYS_POST_MAGIC
);
76 post_val
= in_be32((void *)CONFIG_SYS_POST_VAL
);
77 if ((post_magic
== REBOOT_MAGIC
) && (post_val
== REBOOT_DO_POST
)) {
79 * Set special bootline bootparameter to pass this POST boot
80 * mode to Linux to reset the username/password
82 setenv("addmisc", "setenv bootargs \\${bootargs} factory_reset=yes");
85 * Normally don't run POST tests, only when enabled
86 * via the sw-reset button. So disable further tests
87 * upon next bootup here.
89 out_be32((void *)CONFIG_SYS_POST_VAL
, REBOOT_NOP
);
92 * Only run POST when initiated via the sw-reset button mechanism
100 start_time
= get_timer(0);
106 /* Re-do sizing to get full correct info */
108 /* adjust flash start and offset */
110 switch (gd
->bd
->bi_flashsize
) {
136 pbcr
= (pbcr
& 0x0001ffff) | gd
->bd
->bi_flashstart
| (size_val
<< 17);
140 * Re-check to get correct base address
142 flash_get_size(gd
->bd
->bi_flashstart
, 0);
144 /* Monitor protection ON by default */
145 (void)flash_protect(FLAG_PROTECT_SET
,
146 -CONFIG_SYS_MONITOR_LEN
,
150 /* Env protection ON by default */
151 (void)flash_protect(FLAG_PROTECT_SET
,
152 CONFIG_ENV_ADDR_REDUND
,
153 CONFIG_ENV_ADDR_REDUND
+ 2*CONFIG_ENV_SECT_SIZE
- 1,
160 * Check Board Identity:
164 char *s
= getenv("serial#");
166 puts("Board: Zeus-");
168 if (in_be32((void *)GPIO0_IR
) & GPIO_VAL(CONFIG_SYS_GPIO_ZEUS_PE
))
173 puts(" of BulletEndPoint");
182 gpio_write_bit(CONFIG_SYS_GPIO_LED_RED
, 0);
183 gpio_write_bit(CONFIG_SYS_GPIO_LED_GREEN
, 0);
186 gpio_write_bit(CONFIG_SYS_GPIO_LED_RED
, 1);
187 gpio_write_bit(CONFIG_SYS_GPIO_LED_GREEN
, 1);
192 static int default_env_var(char *buf
, char *var
)
200 ptr
= strstr(buf
+ 4, var
);
202 printf("ERROR: %s not found!\n", var
);
205 ptr
+= strlen(var
) + 1;
208 * Now the ethaddr needs to be updated in the "normal"
209 * environment storage -> redundant flash.
213 printf("Updated %s from eeprom to %s!\n", var
, val
);
218 static int restore_default(void)
229 * Read board specific values from I2C EEPROM
230 * and set env variables accordingly
231 * -> ethaddr, eth1addr, serial#
233 buf
= buf_save
= malloc(FACTORY_RESET_ENV_SIZE
);
235 printf("ERROR: malloc() failed\n");
238 if (eeprom_read(FACTORY_RESET_I2C_EEPROM
, FACTORY_RESET_ENV_OFFS
,
239 (u8
*)buf
, FACTORY_RESET_ENV_SIZE
)) {
240 puts("\nError reading EEPROM!\n");
242 crc
= crc32(0, (u8
*)(buf
+ 4), FACTORY_RESET_ENV_SIZE
- 4);
243 if (crc
!= *(u32
*)buf
) {
244 printf("ERROR: crc mismatch %08x %08x\n", crc
, *(u32
*)buf
);
248 default_env_var(buf
, "ethaddr");
250 default_env_var(buf
, "eth1addr");
252 default_env_var(buf
, "serial#");
256 * Finally save updated env variables back to flash
265 int do_set_default(cmd_tbl_t
*cmdtp
, int flag
, int argc
, char * const argv
[])
278 buf
= buf_save
= malloc(FACTORY_RESET_ENV_SIZE
);
279 memset(buf
, 0, FACTORY_RESET_ENV_SIZE
);
281 strcpy(var
, "ethaddr");
282 printf("Setting %s to %s\n", var
, argv
[1]);
283 sprintf(str
, "%s=%s", var
, argv
[1]);
284 strcpy(buf
+ 4, str
);
285 buf
+= strlen(str
) + 1;
287 strcpy(var
, "eth1addr");
288 printf("Setting %s to %s\n", var
, argv
[2]);
289 sprintf(str
, "%s=%s", var
, argv
[2]);
290 strcpy(buf
+ 4, str
);
291 buf
+= strlen(str
) + 1;
293 strcpy(var
, "serial#");
294 printf("Setting %s to %s\n", var
, argv
[3]);
295 sprintf(str
, "%s=%s", var
, argv
[3]);
296 strcpy(buf
+ 4, str
);
298 crc
= crc32(0, (u8
*)(buf_save
+ 4), FACTORY_RESET_ENV_SIZE
- 4);
299 *(u32
*)buf_save
= crc
;
301 if (eeprom_write(FACTORY_RESET_I2C_EEPROM
, FACTORY_RESET_ENV_OFFS
,
302 (u8
*)buf_save
, FACTORY_RESET_ENV_SIZE
)) {
303 puts("\nError writing EEPROM!\n");
313 setdef
, 4, 1, do_set_default
,
314 "write board-specific values to EEPROM (ethaddr...)",
315 "ethaddr eth1addr serial#\n - write board-specific values to EEPROM"
318 static inline int sw_reset_pressed(void)
320 return !(in_be32((void *)GPIO0_IR
) & GPIO_VAL(CONFIG_SYS_GPIO_SW_RESET
));
323 int do_chkreset(cmd_tbl_t
* cmdtp
, int flag
, int argc
, char * const argv
[])
328 int factory_reset
= 0;
330 if (!sw_reset_pressed()) {
331 printf("SW-Reset already high (Button released)\n");
332 printf("-> No action taken!\n");
336 printf("Waiting for SW-Reset button to be released.");
339 delta
= get_timer(start_time
);
340 if (!sw_reset_pressed())
343 if ((delta
> CONFIG_SYS_TIME_POST
) && !post
) {
344 printf("\nWhen released now, POST tests will be started.");
345 gpio_write_bit(CONFIG_SYS_GPIO_LED_GREEN
, 0);
349 if ((delta
> CONFIG_SYS_TIME_FACTORY_RESET
) && !factory_reset
) {
350 printf("\nWhen released now, factory default values"
351 " will be restored.");
352 gpio_write_bit(CONFIG_SYS_GPIO_LED_RED
, 0);
357 if (!(count
++ % 1000))
362 printf("\nSW-Reset Button released after %d milli-seconds!\n", delta
);
364 if (delta
> CONFIG_SYS_TIME_FACTORY_RESET
) {
365 printf("Starting factory reset value restoration...\n");
368 * Restore default setting
373 * Reset the board for default to become valid
375 do_reset(NULL
, 0, 0, NULL
);
380 if (delta
> CONFIG_SYS_TIME_POST
) {
381 printf("Starting POST configuration...\n");
384 * Enable POST upon next bootup
386 out_be32((void *)CONFIG_SYS_POST_MAGIC
, REBOOT_MAGIC
);
387 out_be32((void *)CONFIG_SYS_POST_VAL
, REBOOT_DO_POST
);
388 post_bootmode_init();
391 * Reset the logbuffer for a clean start
395 do_reset(NULL
, 0, 0, NULL
);
404 chkreset
, 1, 1, do_chkreset
,
405 "Check for status of SW-reset button and act accordingly",
409 #if defined(CONFIG_POST)
411 * Returns 1 if keys pressed to start the power-on long-running tests
412 * Called from board_init_f().
414 int post_hotkeys_pressed(void)
419 post_magic
= in_be32((void *)CONFIG_SYS_POST_MAGIC
);
420 post_val
= in_be32((void *)CONFIG_SYS_POST_VAL
);
422 if ((post_magic
== REBOOT_MAGIC
) && (post_val
== REBOOT_DO_POST
))
427 #endif /* CONFIG_POST */