Heiko Schocher | c248536 | 2008-10-15 09:39:08 +0200 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2008 |
| 3 | * Heiko Schocher, DENX Software Engineering, hs@denx.de. |
| 4 | * |
Holger Brunck | 4f745bf | 2011-06-05 22:22:18 +0000 | [diff] [blame] | 5 | * (C) Copyright 2011 |
| 6 | * Holger Brunck, Keymile GmbH Hannover, holger.brunck@keymile.com |
| 7 | * |
Heiko Schocher | c248536 | 2008-10-15 09:39:08 +0200 | [diff] [blame] | 8 | * See file CREDITS for list of people who contributed to this |
| 9 | * project. |
| 10 | * |
| 11 | * This program is free software; you can redistribute it and/or |
| 12 | * modify it under the terms of the GNU General Public License as |
| 13 | * published by the Free Software Foundation; either version 2 of |
| 14 | * the License, or (at your option) any later version. |
| 15 | * |
| 16 | * This program is distributed in the hope that it will be useful, |
| 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 19 | * GNU General Public License for more details. |
| 20 | * |
| 21 | * You should have received a copy of the GNU General Public License |
| 22 | * along with this program; if not, write to the Free Software |
| 23 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 24 | * MA 02111-1307 USA |
| 25 | */ |
| 26 | |
| 27 | #include <common.h> |
Heiko Schocher | c248536 | 2008-10-15 09:39:08 +0200 | [diff] [blame] | 28 | #include <ioports.h> |
Holger Brunck | a9417ce | 2011-05-04 01:47:30 +0000 | [diff] [blame] | 29 | #include <command.h> |
Heiko Schocher | c248536 | 2008-10-15 09:39:08 +0200 | [diff] [blame] | 30 | #include <malloc.h> |
Heiko Schocher | 8f64da7 | 2008-10-15 09:41:00 +0200 | [diff] [blame] | 31 | #include <hush.h> |
Heiko Schocher | 210c8c0 | 2008-11-21 08:29:40 +0100 | [diff] [blame] | 32 | #include <net.h> |
Heiko Schocher | 62ddcf0 | 2010-02-18 08:08:25 +0100 | [diff] [blame] | 33 | #include <netdev.h> |
Heiko Schocher | 210c8c0 | 2008-11-21 08:29:40 +0100 | [diff] [blame] | 34 | #include <asm/io.h> |
Thomas Herzmann | 92c9108 | 2011-05-12 19:59:22 +0000 | [diff] [blame] | 35 | #include <linux/ctype.h> |
Heiko Schocher | c248536 | 2008-10-15 09:39:08 +0200 | [diff] [blame] | 36 | |
Thomas Herzmann | c1b3d84 | 2012-05-04 10:55:58 +0200 | [diff] [blame] | 37 | #if defined(CONFIG_POST) |
| 38 | #include "post.h" |
| 39 | #endif |
Holger Brunck | 4f745bf | 2011-06-05 22:22:18 +0000 | [diff] [blame] | 40 | #include "common.h" |
Heiko Schocher | c248536 | 2008-10-15 09:39:08 +0200 | [diff] [blame] | 41 | #if defined(CONFIG_HARD_I2C) || defined(CONFIG_SOFT_I2C) |
| 42 | #include <i2c.h> |
Holger Brunck | 1adfd9d | 2011-06-05 22:22:20 +0000 | [diff] [blame] | 43 | #endif |
Heiko Schocher | c248536 | 2008-10-15 09:39:08 +0200 | [diff] [blame] | 44 | |
Holger Brunck | e792aff | 2011-09-14 10:54:12 +0200 | [diff] [blame] | 45 | #if !defined(CONFIG_MPC83xx) |
Heiko Schocher | 6c11aea | 2011-03-08 10:51:15 +0100 | [diff] [blame] | 46 | static void i2c_write_start_seq(void); |
Holger Brunck | e792aff | 2011-09-14 10:54:12 +0200 | [diff] [blame] | 47 | #endif |
| 48 | |
Heiko Schocher | f1fef1d | 2010-04-26 13:07:28 +0200 | [diff] [blame] | 49 | DECLARE_GLOBAL_DATA_PTR; |
Heiko Schocher | 6c11aea | 2011-03-08 10:51:15 +0100 | [diff] [blame] | 50 | |
Heiko Schocher | f1fef1d | 2010-04-26 13:07:28 +0200 | [diff] [blame] | 51 | /* |
| 52 | * Set Keymile specific environment variables |
| 53 | * Currently only some memory layout variables are calculated here |
| 54 | * ... ------------------------------------------------ |
| 55 | * ... |@rootfsaddr |@pnvramaddr |@varaddr |@reserved |@END_OF_RAM |
| 56 | * ... |<------------------- pram ------------------->| |
| 57 | * ... ------------------------------------------------ |
| 58 | * @END_OF_RAM: denotes the RAM size |
| 59 | * @pnvramaddr: Startadress of pseudo non volatile RAM in hex |
| 60 | * @pram : preserved ram size in k |
| 61 | * @varaddr : startadress for /var mounted into RAM |
| 62 | */ |
| 63 | int set_km_env(void) |
| 64 | { |
| 65 | uchar buf[32]; |
| 66 | unsigned int pnvramaddr; |
| 67 | unsigned int pram; |
| 68 | unsigned int varaddr; |
Andreas Huber | 2a7714c | 2011-09-13 23:06:11 +0000 | [diff] [blame] | 69 | unsigned int kernelmem; |
| 70 | char *p; |
| 71 | unsigned long rootfssize = 0; |
Heiko Schocher | f1fef1d | 2010-04-26 13:07:28 +0200 | [diff] [blame] | 72 | |
| 73 | pnvramaddr = gd->ram_size - CONFIG_KM_RESERVED_PRAM - CONFIG_KM_PHRAM |
| 74 | - CONFIG_KM_PNVRAM; |
| 75 | sprintf((char *)buf, "0x%x", pnvramaddr); |
| 76 | setenv("pnvramaddr", (char *)buf); |
| 77 | |
Andreas Huber | 2a7714c | 2011-09-13 23:06:11 +0000 | [diff] [blame] | 78 | /* try to read rootfssize (ram image) from envrionment */ |
| 79 | p = getenv("rootfssize"); |
| 80 | if (p != NULL) |
| 81 | strict_strtoul(p, 16, &rootfssize); |
| 82 | pram = (rootfssize + CONFIG_KM_RESERVED_PRAM + CONFIG_KM_PHRAM + |
| 83 | CONFIG_KM_PNVRAM) / 0x400; |
Heiko Schocher | f1fef1d | 2010-04-26 13:07:28 +0200 | [diff] [blame] | 84 | sprintf((char *)buf, "0x%x", pram); |
| 85 | setenv("pram", (char *)buf); |
| 86 | |
| 87 | varaddr = gd->ram_size - CONFIG_KM_RESERVED_PRAM - CONFIG_KM_PHRAM; |
| 88 | sprintf((char *)buf, "0x%x", varaddr); |
| 89 | setenv("varaddr", (char *)buf); |
Andreas Huber | 2a7714c | 2011-09-13 23:06:11 +0000 | [diff] [blame] | 90 | |
| 91 | kernelmem = gd->ram_size - 0x400 * pram; |
| 92 | sprintf((char *)buf, "0x%x", kernelmem); |
| 93 | setenv("kernelmem", (char *)buf); |
| 94 | |
Heiko Schocher | f1fef1d | 2010-04-26 13:07:28 +0200 | [diff] [blame] | 95 | return 0; |
| 96 | } |
| 97 | |
Holger Brunck | e792aff | 2011-09-14 10:54:12 +0200 | [diff] [blame] | 98 | #if defined(CONFIG_SYS_I2C_INIT_BOARD) |
Heiko Schocher | 62ddcf0 | 2010-02-18 08:08:25 +0100 | [diff] [blame] | 99 | #if !defined(CONFIG_MPC83xx) |
Heiko Schocher | 6c11aea | 2011-03-08 10:51:15 +0100 | [diff] [blame] | 100 | static void i2c_write_start_seq(void) |
Heiko Schocher | c248536 | 2008-10-15 09:39:08 +0200 | [diff] [blame] | 101 | { |
Heiko Schocher | b11f53f | 2011-03-15 16:52:29 +0100 | [diff] [blame] | 102 | set_sda(1); |
| 103 | udelay(DELAY_HALF_PERIOD); |
| 104 | set_scl(1); |
| 105 | udelay(DELAY_HALF_PERIOD); |
| 106 | set_sda(0); |
| 107 | udelay(DELAY_HALF_PERIOD); |
| 108 | set_scl(0); |
| 109 | udelay(DELAY_HALF_PERIOD); |
Heiko Schocher | c248536 | 2008-10-15 09:39:08 +0200 | [diff] [blame] | 110 | } |
| 111 | |
Heiko Schocher | b11f53f | 2011-03-15 16:52:29 +0100 | [diff] [blame] | 112 | /* |
| 113 | * I2C is a synchronous protocol and resets of the processor in the middle |
| 114 | * of an access can block the I2C Bus until a powerdown of the full unit is |
| 115 | * done. This function toggles the SCL until the SCL and SCA line are |
| 116 | * released, but max. 16 times, after this a I2C start-sequence is sent. |
| 117 | * This I2C Deblocking mechanism was developed by Keymile in association |
| 118 | * with Anatech and Atmel in 1998. |
Heiko Schocher | c248536 | 2008-10-15 09:39:08 +0200 | [diff] [blame] | 119 | */ |
Holger Brunck | 4f745bf | 2011-06-05 22:22:18 +0000 | [diff] [blame] | 120 | int i2c_make_abort(void) |
Heiko Schocher | c248536 | 2008-10-15 09:39:08 +0200 | [diff] [blame] | 121 | { |
Heiko Schocher | 6c11aea | 2011-03-08 10:51:15 +0100 | [diff] [blame] | 122 | |
| 123 | #if defined(CONFIG_HARD_I2C) && !defined(MACH_TYPE_KM_KIRKWOOD) |
| 124 | immap_t *immap = (immap_t *)CONFIG_SYS_IMMR ; |
| 125 | i2c8260_t *i2c = (i2c8260_t *)&immap->im_i2c; |
| 126 | |
| 127 | /* |
| 128 | * disable I2C controller first, otherwhise it thinks we want to |
| 129 | * talk to the slave port... |
| 130 | */ |
| 131 | clrbits_8(&i2c->i2c_i2mod, 0x01); |
| 132 | |
| 133 | /* Set the PortPins to GPIO */ |
| 134 | setports(1); |
| 135 | #endif |
| 136 | |
Heiko Schocher | c248536 | 2008-10-15 09:39:08 +0200 | [diff] [blame] | 137 | int scl_state = 0; |
| 138 | int sda_state = 0; |
| 139 | int i = 0; |
| 140 | int ret = 0; |
| 141 | |
Heiko Schocher | b11f53f | 2011-03-15 16:52:29 +0100 | [diff] [blame] | 142 | if (!get_sda()) { |
Heiko Schocher | c248536 | 2008-10-15 09:39:08 +0200 | [diff] [blame] | 143 | ret = -1; |
| 144 | while (i < 16) { |
| 145 | i++; |
Heiko Schocher | b11f53f | 2011-03-15 16:52:29 +0100 | [diff] [blame] | 146 | set_scl(0); |
| 147 | udelay(DELAY_ABORT_SEQ); |
| 148 | set_scl(1); |
| 149 | udelay(DELAY_ABORT_SEQ); |
| 150 | scl_state = get_scl(); |
| 151 | sda_state = get_sda(); |
Heiko Schocher | c248536 | 2008-10-15 09:39:08 +0200 | [diff] [blame] | 152 | if (scl_state && sda_state) { |
| 153 | ret = 0; |
Stefan Bigler | c7506c2 | 2011-07-04 22:24:02 +0000 | [diff] [blame] | 154 | printf("[INFO] i2c abort after %d clocks\n", i); |
Heiko Schocher | c248536 | 2008-10-15 09:39:08 +0200 | [diff] [blame] | 155 | break; |
| 156 | } |
| 157 | } |
| 158 | } |
Heiko Schocher | b11f53f | 2011-03-15 16:52:29 +0100 | [diff] [blame] | 159 | if (ret == 0) |
| 160 | for (i = 0; i < 5; i++) |
Heiko Schocher | 6c11aea | 2011-03-08 10:51:15 +0100 | [diff] [blame] | 161 | i2c_write_start_seq(); |
Stefan Bigler | c7506c2 | 2011-07-04 22:24:02 +0000 | [diff] [blame] | 162 | else |
| 163 | printf("[ERROR] i2c abort failed\n"); |
Heiko Schocher | b11f53f | 2011-03-15 16:52:29 +0100 | [diff] [blame] | 164 | |
Heiko Schocher | 6c11aea | 2011-03-08 10:51:15 +0100 | [diff] [blame] | 165 | /* respect stop setup time */ |
| 166 | udelay(DELAY_ABORT_SEQ); |
| 167 | set_scl(1); |
| 168 | udelay(DELAY_ABORT_SEQ); |
| 169 | set_sda(1); |
Heiko Schocher | b11f53f | 2011-03-15 16:52:29 +0100 | [diff] [blame] | 170 | get_sda(); |
Heiko Schocher | c248536 | 2008-10-15 09:39:08 +0200 | [diff] [blame] | 171 | |
| 172 | #if defined(CONFIG_HARD_I2C) |
| 173 | /* Set the PortPins back to use for I2C */ |
Heiko Schocher | b11f53f | 2011-03-15 16:52:29 +0100 | [diff] [blame] | 174 | setports(0); |
Heiko Schocher | c248536 | 2008-10-15 09:39:08 +0200 | [diff] [blame] | 175 | #endif |
Heiko Schocher | 6c11aea | 2011-03-08 10:51:15 +0100 | [diff] [blame] | 176 | return ret; |
| 177 | } |
Heiko Schocher | 6c11aea | 2011-03-08 10:51:15 +0100 | [diff] [blame] | 178 | #endif |
| 179 | |
| 180 | /** |
| 181 | * i2c_init_board - reset i2c bus. When the board is powercycled during a |
| 182 | * bus transfer it might hang; for details see doc/I2C_Edge_Conditions. |
| 183 | */ |
| 184 | void i2c_init_board(void) |
| 185 | { |
| 186 | /* Now run the AbortSequence() */ |
| 187 | i2c_make_abort(); |
Heiko Schocher | c248536 | 2008-10-15 09:39:08 +0200 | [diff] [blame] | 188 | } |
Holger Brunck | e792aff | 2011-09-14 10:54:12 +0200 | [diff] [blame] | 189 | #endif |
| 190 | |
Heiko Schocher | 6250f0f | 2008-10-17 16:11:52 +0200 | [diff] [blame] | 191 | |
Holger Brunck | 802d996 | 2011-03-14 15:31:19 +0100 | [diff] [blame] | 192 | #if !defined(MACH_TYPE_KM_KIRKWOOD) |
Heiko Schocher | b11f53f | 2011-03-15 16:52:29 +0100 | [diff] [blame] | 193 | int ethernet_present(void) |
Heiko Schocher | 210c8c0 | 2008-11-21 08:29:40 +0100 | [diff] [blame] | 194 | { |
Heiko Schocher | 8ed7434 | 2011-03-08 10:47:39 +0100 | [diff] [blame] | 195 | struct km_bec_fpga *base = |
| 196 | (struct km_bec_fpga *)CONFIG_SYS_KMBEC_FPGA_BASE; |
Heiko Schocher | b11f53f | 2011-03-15 16:52:29 +0100 | [diff] [blame] | 197 | |
| 198 | return in_8(&base->bprth) & PIGGY_PRESENT; |
Heiko Schocher | 210c8c0 | 2008-11-21 08:29:40 +0100 | [diff] [blame] | 199 | } |
Heiko Schocher | 67fa8c2 | 2010-02-22 16:43:02 +0530 | [diff] [blame] | 200 | #endif |
Heiko Schocher | 210c8c0 | 2008-11-21 08:29:40 +0100 | [diff] [blame] | 201 | |
Heiko Schocher | b11f53f | 2011-03-15 16:52:29 +0100 | [diff] [blame] | 202 | int board_eth_init(bd_t *bis) |
Heiko Schocher | 210c8c0 | 2008-11-21 08:29:40 +0100 | [diff] [blame] | 203 | { |
Heiko Schocher | b11f53f | 2011-03-15 16:52:29 +0100 | [diff] [blame] | 204 | if (ethernet_present()) |
Heiko Schocher | 62ddcf0 | 2010-02-18 08:08:25 +0100 | [diff] [blame] | 205 | return cpu_eth_init(bis); |
| 206 | |
| 207 | return -1; |
Heiko Schocher | 210c8c0 | 2008-11-21 08:29:40 +0100 | [diff] [blame] | 208 | } |
Holger Brunck | a9417ce | 2011-05-04 01:47:30 +0000 | [diff] [blame] | 209 | |
| 210 | /* |
| 211 | * do_setboardid command |
| 212 | * read out the board id and the hw key from the intventory EEPROM and set |
| 213 | * this values as environment variables. |
| 214 | */ |
| 215 | static int do_setboardid(cmd_tbl_t *cmdtp, int flag, int argc, |
| 216 | char *const argv[]) |
| 217 | { |
| 218 | unsigned char buf[32]; |
| 219 | char *p; |
| 220 | |
| 221 | p = get_local_var("IVM_BoardId"); |
| 222 | if (p == NULL) { |
| 223 | printf("can't get the IVM_Boardid\n"); |
| 224 | return 1; |
| 225 | } |
| 226 | sprintf((char *)buf, "%s", p); |
| 227 | setenv("boardid", (char *)buf); |
Holger Brunck | 9485e77 | 2011-07-04 22:23:59 +0000 | [diff] [blame] | 228 | printf("set boardid=%s\n", buf); |
Holger Brunck | a9417ce | 2011-05-04 01:47:30 +0000 | [diff] [blame] | 229 | |
| 230 | p = get_local_var("IVM_HWKey"); |
| 231 | if (p == NULL) { |
| 232 | printf("can't get the IVM_HWKey\n"); |
| 233 | return 1; |
| 234 | } |
| 235 | sprintf((char *)buf, "%s", p); |
| 236 | setenv("hwkey", (char *)buf); |
Holger Brunck | 9485e77 | 2011-07-04 22:23:59 +0000 | [diff] [blame] | 237 | printf("set hwkey=%s\n", buf); |
| 238 | printf("Execute manually saveenv for persistent storage.\n"); |
Holger Brunck | a9417ce | 2011-05-04 01:47:30 +0000 | [diff] [blame] | 239 | |
| 240 | return 0; |
| 241 | } |
| 242 | |
| 243 | U_BOOT_CMD(km_setboardid, 1, 0, do_setboardid, "setboardid", "read out bid and " |
| 244 | "hwkey from IVM and set in environment"); |
Thomas Herzmann | 92c9108 | 2011-05-12 19:59:22 +0000 | [diff] [blame] | 245 | |
| 246 | /* |
| 247 | * command km_checkbidhwk |
| 248 | * if "boardid" and "hwkey" are not already set in the environment, do: |
| 249 | * if a "boardIdListHex" exists in the environment: |
| 250 | * - read ivm data for boardid and hwkey |
| 251 | * - compare each entry of the boardIdListHex with the |
| 252 | * IVM data: |
| 253 | * if match: |
| 254 | * set environment variables boardid, boardId, |
| 255 | * hwkey, hwKey to the found values |
| 256 | * both (boardid and boardId) are set because |
| 257 | * they might be used differently in the |
| 258 | * application and in the init scripts (?) |
| 259 | * return 0 in case of match, 1 if not match or error |
| 260 | */ |
| 261 | int do_checkboardidhwk(cmd_tbl_t *cmdtp, int flag, int argc, |
| 262 | char *const argv[]) |
| 263 | { |
| 264 | unsigned long ivmbid = 0, ivmhwkey = 0; |
| 265 | unsigned long envbid = 0, envhwkey = 0; |
| 266 | char *p; |
| 267 | int verbose = argc > 1 && *argv[1] == 'v'; |
| 268 | int rc = 0; |
| 269 | |
| 270 | /* |
| 271 | * first read out the real inventory values, these values are |
| 272 | * already stored in the local hush variables |
| 273 | */ |
| 274 | p = get_local_var("IVM_BoardId"); |
| 275 | if (p == NULL) { |
| 276 | printf("can't get the IVM_Boardid\n"); |
| 277 | return 1; |
| 278 | } |
| 279 | rc = strict_strtoul(p, 16, &ivmbid); |
| 280 | |
| 281 | p = get_local_var("IVM_HWKey"); |
| 282 | if (p == NULL) { |
| 283 | printf("can't get the IVM_HWKey\n"); |
| 284 | return 1; |
| 285 | } |
| 286 | rc = strict_strtoul(p, 16, &ivmhwkey); |
| 287 | |
| 288 | if (!ivmbid || !ivmhwkey) { |
| 289 | printf("Error: IVM_BoardId and/or IVM_HWKey not set!\n"); |
| 290 | return rc; |
| 291 | } |
| 292 | |
| 293 | /* now try to read values from environment if available */ |
| 294 | p = getenv("boardid"); |
| 295 | if (p != NULL) |
| 296 | rc = strict_strtoul(p, 16, &envbid); |
| 297 | p = getenv("hwkey"); |
| 298 | if (p != NULL) |
| 299 | rc = strict_strtoul(p, 16, &envhwkey); |
| 300 | |
| 301 | if (rc != 0) { |
| 302 | printf("strict_strtoul returns error: %d", rc); |
| 303 | return rc; |
| 304 | } |
| 305 | |
| 306 | if (!envbid || !envhwkey) { |
| 307 | /* |
| 308 | * BoardId/HWkey not available in the environment, so try the |
| 309 | * environment variable for BoardId/HWkey list |
| 310 | */ |
| 311 | char *bidhwklist = getenv("boardIdListHex"); |
| 312 | |
| 313 | if (bidhwklist) { |
| 314 | int found = 0; |
| 315 | char *rest = bidhwklist; |
| 316 | char *endp; |
| 317 | |
| 318 | if (verbose) { |
| 319 | printf("IVM_BoardId: %ld, IVM_HWKey=%ld\n", |
| 320 | ivmbid, ivmhwkey); |
| 321 | printf("boardIdHwKeyList: %s\n", |
| 322 | bidhwklist); |
| 323 | } |
| 324 | while (!found) { |
| 325 | /* loop over each bid/hwkey pair in the list */ |
| 326 | unsigned long bid = 0; |
| 327 | unsigned long hwkey = 0; |
| 328 | |
| 329 | while (*rest && !isxdigit(*rest)) |
| 330 | rest++; |
| 331 | /* |
| 332 | * use simple_strtoul because we need &end and |
| 333 | * we know we got non numeric char at the end |
| 334 | */ |
| 335 | bid = simple_strtoul(rest, &endp, 16); |
| 336 | /* BoardId and HWkey are separated with a "_" */ |
| 337 | if (*endp == '_') { |
| 338 | rest = endp + 1; |
| 339 | /* |
| 340 | * use simple_strtoul because we need |
| 341 | * &end |
| 342 | */ |
| 343 | hwkey = simple_strtoul(rest, &endp, 16); |
| 344 | rest = endp; |
| 345 | while (*rest && !isxdigit(*rest)) |
| 346 | rest++; |
| 347 | } |
| 348 | if ((!bid) || (!hwkey)) { |
| 349 | /* end of list */ |
| 350 | break; |
| 351 | } |
| 352 | if (verbose) { |
| 353 | printf("trying bid=0x%lX, hwkey=%ld\n", |
| 354 | bid, hwkey); |
| 355 | } |
| 356 | /* |
| 357 | * Compare the values of the found entry in the |
| 358 | * list with the valid values which are stored |
| 359 | * in the inventory eeprom. If they are equal |
Holger Brunck | ba8be32 | 2011-06-05 22:22:17 +0000 | [diff] [blame] | 360 | * set the values in environment variables. |
Thomas Herzmann | 92c9108 | 2011-05-12 19:59:22 +0000 | [diff] [blame] | 361 | */ |
| 362 | if ((bid == ivmbid) && (hwkey == ivmhwkey)) { |
| 363 | char buf[10]; |
| 364 | |
| 365 | found = 1; |
| 366 | envbid = bid; |
| 367 | envhwkey = hwkey; |
| 368 | sprintf(buf, "%lx", bid); |
| 369 | setenv("boardid", buf); |
| 370 | sprintf(buf, "%lx", hwkey); |
| 371 | setenv("hwkey", buf); |
Thomas Herzmann | 92c9108 | 2011-05-12 19:59:22 +0000 | [diff] [blame] | 372 | } |
| 373 | } /* end while( ! found ) */ |
| 374 | } |
| 375 | } |
| 376 | |
| 377 | /* compare now the values */ |
| 378 | if ((ivmbid == envbid) && (ivmhwkey == envhwkey)) { |
| 379 | printf("boardid=0x%3lX, hwkey=%ld\n", envbid, envhwkey); |
| 380 | rc = 0; /* match */ |
| 381 | } else { |
Holger Brunck | 9485e77 | 2011-07-04 22:23:59 +0000 | [diff] [blame] | 382 | printf("Error: env boardid=0x%3lX, hwkey=%ld\n", envbid, |
| 383 | envhwkey); |
Thomas Herzmann | 92c9108 | 2011-05-12 19:59:22 +0000 | [diff] [blame] | 384 | printf(" IVM bId=0x%3lX, hwKey=%ld\n", ivmbid, ivmhwkey); |
| 385 | rc = 1; /* don't match */ |
| 386 | } |
| 387 | return rc; |
| 388 | } |
| 389 | |
| 390 | U_BOOT_CMD(km_checkbidhwk, 2, 0, do_checkboardidhwk, |
| 391 | "check boardid and hwkey", |
| 392 | "[v]\n - check environment parameter "\ |
| 393 | "\"boardIdListHex\" against stored boardid and hwkey "\ |
| 394 | "from the IVM\n v: verbose output" |
| 395 | ); |
Thomas Herzmann | c1b3d84 | 2012-05-04 10:55:58 +0200 | [diff] [blame] | 396 | |
| 397 | /* |
| 398 | * command km_checktestboot |
| 399 | * if the testpin of the board is asserted, return 1 |
| 400 | * * else return 0 |
| 401 | */ |
| 402 | int do_checktestboot(cmd_tbl_t *cmdtp, int flag, int argc, |
| 403 | char *const argv[]) |
| 404 | { |
| 405 | int testpin = 0; |
| 406 | char *s = NULL; |
| 407 | int testboot = 0; |
| 408 | int verbose = argc > 1 && *argv[1] == 'v'; |
| 409 | |
| 410 | #if defined(CONFIG_POST) |
| 411 | testpin = post_hotkeys_pressed(); |
| 412 | s = getenv("test_bank"); |
| 413 | #endif |
| 414 | /* when test_bank is not set, act as if testpin is not asserted */ |
| 415 | testboot = (testpin != 0) && (s); |
| 416 | if (verbose) { |
| 417 | printf("testpin = %d\n", testpin); |
| 418 | printf("test_bank = %s\n", s ? s : "not set"); |
| 419 | printf("boot test app : %s\n", (testboot) ? "yes" : "no"); |
| 420 | } |
| 421 | /* return 0 means: testboot, therefore we need the inversion */ |
| 422 | return !testboot; |
| 423 | } |
| 424 | |
| 425 | U_BOOT_CMD(km_checktestboot, 2, 0, do_checktestboot, |
| 426 | "check if testpin is asserted", |
| 427 | "[v]\n v - verbose output" |
| 428 | ); |