Stefan Roese | 23d8d34 | 2007-06-06 11:42:13 +0200 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2007 |
| 3 | * Stefan Roese, DENX Software Engineering, sr@denx.de. |
| 4 | * |
Wolfgang Denk | d79de1d | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 5 | * SPDX-License-Identifier: GPL-2.0+ |
Stefan Roese | 23d8d34 | 2007-06-06 11:42:13 +0200 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #include <common.h> |
| 9 | #include <command.h> |
| 10 | #include <i2c.h> |
| 11 | |
| 12 | static u8 boot_267_nor[] = { |
| 13 | 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x8e, 0x00, |
| 14 | 0x14, 0xc0, 0x36, 0xcc, 0x00, 0x0c, 0x00, 0x00, |
| 15 | 0x00, 0x00, 0x00, 0x00 |
| 16 | }; |
| 17 | |
| 18 | static u8 boot_267_nand[] = { |
| 19 | 0xd0, 0x38, 0xc3, 0x50, 0x13, 0x88, 0x8e, 0x00, |
| 20 | 0x14, 0xc0, 0x36, 0xcc, 0x00, 0x0c, 0x00, 0x00, |
| 21 | 0x00, 0x00, 0x00, 0x00 |
| 22 | }; |
| 23 | |
Wolfgang Denk | 6262d021 | 2010-06-28 22:00:46 +0200 | [diff] [blame] | 24 | static int do_bootstrap(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
Stefan Roese | 23d8d34 | 2007-06-06 11:42:13 +0200 | [diff] [blame] | 25 | { |
| 26 | u8 chip; |
| 27 | u8 *buf; |
| 28 | int cpu_freq; |
| 29 | |
Wolfgang Denk | 3b68311 | 2010-07-17 01:06:04 +0200 | [diff] [blame] | 30 | if (argc < 3) |
| 31 | return cmd_usage(cmdtp); |
Stefan Roese | 23d8d34 | 2007-06-06 11:42:13 +0200 | [diff] [blame] | 32 | |
| 33 | cpu_freq = simple_strtol(argv[1], NULL, 10); |
| 34 | if (cpu_freq != 267) { |
| 35 | printf("Unsupported cpu-frequency - only 267 supported\n"); |
| 36 | return 1; |
| 37 | } |
| 38 | |
| 39 | /* use 0x50 as I2C EEPROM address for now */ |
| 40 | chip = 0x50; |
| 41 | |
| 42 | if ((strcmp(argv[2], "nor") != 0) && |
| 43 | (strcmp(argv[2], "nand") != 0)) { |
| 44 | printf("Unsupported boot-device - only nor|nand support\n"); |
| 45 | return 1; |
| 46 | } |
| 47 | |
| 48 | if (strcmp(argv[2], "nand") == 0) { |
| 49 | switch (cpu_freq) { |
| 50 | case 267: |
| 51 | buf = boot_267_nand; |
| 52 | break; |
| 53 | default: |
| 54 | break; |
| 55 | } |
| 56 | } else { |
| 57 | switch (cpu_freq) { |
| 58 | case 267: |
| 59 | buf = boot_267_nor; |
| 60 | break; |
| 61 | default: |
| 62 | break; |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | if (i2c_write(chip, 0, 1, buf, 16) != 0) |
| 67 | printf("Error writing to EEPROM at address 0x%x\n", chip); |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 68 | udelay(CONFIG_SYS_EEPROM_PAGE_WRITE_DELAY_MS * 1000); |
Stefan Roese | 23d8d34 | 2007-06-06 11:42:13 +0200 | [diff] [blame] | 69 | if (i2c_write(chip, 0x10, 1, buf+16, 4) != 0) |
| 70 | printf("Error2 writing to EEPROM at address 0x%x\n", chip); |
| 71 | |
| 72 | printf("Done\n"); |
| 73 | printf("Please power-cycle the board for the changes to take effect\n"); |
| 74 | |
| 75 | return 0; |
| 76 | } |
| 77 | |
| 78 | U_BOOT_CMD( |
| 79 | bootstrap, 3, 0, do_bootstrap, |
Peter Tyser | dfb72b8 | 2009-01-27 18:03:12 -0600 | [diff] [blame] | 80 | "program the I2C bootstrap EEPROM", |
Wolfgang Denk | c54781c | 2009-05-24 17:06:54 +0200 | [diff] [blame] | 81 | "<cpu-freq> <nor|nand> - program the I2C bootstrap EEPROM" |
| 82 | ); |