Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Heiko Schocher | 5e51b48 | 2008-10-15 09:39:08 +0200 | [diff] [blame] | 2 | /* |
| 3 | * (C) Copyright 2008 |
| 4 | * Heiko Schocher, DENX Software Engineering, hs@denx.de. |
| 5 | * |
Holger Brunck | bf20a88 | 2011-06-05 22:22:18 +0000 | [diff] [blame] | 6 | * (C) Copyright 2011 |
| 7 | * Holger Brunck, Keymile GmbH Hannover, holger.brunck@keymile.com |
Heiko Schocher | 5e51b48 | 2008-10-15 09:39:08 +0200 | [diff] [blame] | 8 | */ |
| 9 | |
| 10 | #include <common.h> |
Heiko Schocher | 5e51b48 | 2008-10-15 09:39:08 +0200 | [diff] [blame] | 11 | #include <ioports.h> |
Holger Brunck | 3066492 | 2011-05-04 01:47:30 +0000 | [diff] [blame] | 12 | #include <command.h> |
Heiko Schocher | 5e51b48 | 2008-10-15 09:39:08 +0200 | [diff] [blame] | 13 | #include <malloc.h> |
Simon Glass | 299f0be | 2014-04-10 20:01:24 -0600 | [diff] [blame] | 14 | #include <cli_hush.h> |
Heiko Schocher | d19a6ec | 2008-11-21 08:29:40 +0100 | [diff] [blame] | 15 | #include <net.h> |
Heiko Schocher | 466924f | 2010-02-18 08:08:25 +0100 | [diff] [blame] | 16 | #include <netdev.h> |
Heiko Schocher | d19a6ec | 2008-11-21 08:29:40 +0100 | [diff] [blame] | 17 | #include <asm/io.h> |
Thomas Herzmann | 2c8a0c8 | 2011-05-12 19:59:22 +0000 | [diff] [blame] | 18 | #include <linux/ctype.h> |
Heiko Schocher | 5e51b48 | 2008-10-15 09:39:08 +0200 | [diff] [blame] | 19 | |
Thomas Herzmann | b2c3160 | 2012-05-04 10:55:58 +0200 | [diff] [blame] | 20 | #if defined(CONFIG_POST) |
| 21 | #include "post.h" |
| 22 | #endif |
Holger Brunck | bf20a88 | 2011-06-05 22:22:18 +0000 | [diff] [blame] | 23 | #include "common.h" |
Heiko Schocher | 5e51b48 | 2008-10-15 09:39:08 +0200 | [diff] [blame] | 24 | #include <i2c.h> |
Heiko Schocher | 5e51b48 | 2008-10-15 09:39:08 +0200 | [diff] [blame] | 25 | |
Heiko Schocher | cfc5804 | 2010-04-26 13:07:28 +0200 | [diff] [blame] | 26 | DECLARE_GLOBAL_DATA_PTR; |
Heiko Schocher | d9e1095 | 2011-03-08 10:51:15 +0100 | [diff] [blame] | 27 | |
Heiko Schocher | cfc5804 | 2010-04-26 13:07:28 +0200 | [diff] [blame] | 28 | /* |
| 29 | * Set Keymile specific environment variables |
| 30 | * Currently only some memory layout variables are calculated here |
| 31 | * ... ------------------------------------------------ |
| 32 | * ... |@rootfsaddr |@pnvramaddr |@varaddr |@reserved |@END_OF_RAM |
| 33 | * ... |<------------------- pram ------------------->| |
| 34 | * ... ------------------------------------------------ |
| 35 | * @END_OF_RAM: denotes the RAM size |
| 36 | * @pnvramaddr: Startadress of pseudo non volatile RAM in hex |
| 37 | * @pram : preserved ram size in k |
| 38 | * @varaddr : startadress for /var mounted into RAM |
| 39 | */ |
| 40 | int set_km_env(void) |
| 41 | { |
| 42 | uchar buf[32]; |
| 43 | unsigned int pnvramaddr; |
| 44 | unsigned int pram; |
| 45 | unsigned int varaddr; |
Andreas Huber | 28c63c7 | 2011-09-13 23:06:11 +0000 | [diff] [blame] | 46 | unsigned int kernelmem; |
| 47 | char *p; |
| 48 | unsigned long rootfssize = 0; |
Heiko Schocher | cfc5804 | 2010-04-26 13:07:28 +0200 | [diff] [blame] | 49 | |
| 50 | pnvramaddr = gd->ram_size - CONFIG_KM_RESERVED_PRAM - CONFIG_KM_PHRAM |
| 51 | - CONFIG_KM_PNVRAM; |
| 52 | sprintf((char *)buf, "0x%x", pnvramaddr); |
Simon Glass | 6a38e41 | 2017-08-03 12:22:09 -0600 | [diff] [blame] | 53 | env_set("pnvramaddr", (char *)buf); |
Heiko Schocher | cfc5804 | 2010-04-26 13:07:28 +0200 | [diff] [blame] | 54 | |
Robert P. J. Day | 8d56db9 | 2016-07-15 13:44:45 -0400 | [diff] [blame] | 55 | /* try to read rootfssize (ram image) from environment */ |
Simon Glass | 64b723f | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 56 | p = env_get("rootfssize"); |
Andreas Huber | 28c63c7 | 2011-09-13 23:06:11 +0000 | [diff] [blame] | 57 | if (p != NULL) |
| 58 | strict_strtoul(p, 16, &rootfssize); |
| 59 | pram = (rootfssize + CONFIG_KM_RESERVED_PRAM + CONFIG_KM_PHRAM + |
| 60 | CONFIG_KM_PNVRAM) / 0x400; |
Heiko Schocher | cfc5804 | 2010-04-26 13:07:28 +0200 | [diff] [blame] | 61 | sprintf((char *)buf, "0x%x", pram); |
Simon Glass | 6a38e41 | 2017-08-03 12:22:09 -0600 | [diff] [blame] | 62 | env_set("pram", (char *)buf); |
Heiko Schocher | cfc5804 | 2010-04-26 13:07:28 +0200 | [diff] [blame] | 63 | |
| 64 | varaddr = gd->ram_size - CONFIG_KM_RESERVED_PRAM - CONFIG_KM_PHRAM; |
| 65 | sprintf((char *)buf, "0x%x", varaddr); |
Simon Glass | 6a38e41 | 2017-08-03 12:22:09 -0600 | [diff] [blame] | 66 | env_set("varaddr", (char *)buf); |
Andreas Huber | 28c63c7 | 2011-09-13 23:06:11 +0000 | [diff] [blame] | 67 | |
| 68 | kernelmem = gd->ram_size - 0x400 * pram; |
| 69 | sprintf((char *)buf, "0x%x", kernelmem); |
Simon Glass | 6a38e41 | 2017-08-03 12:22:09 -0600 | [diff] [blame] | 70 | env_set("kernelmem", (char *)buf); |
Andreas Huber | 28c63c7 | 2011-09-13 23:06:11 +0000 | [diff] [blame] | 71 | |
Heiko Schocher | cfc5804 | 2010-04-26 13:07:28 +0200 | [diff] [blame] | 72 | return 0; |
| 73 | } |
| 74 | |
Holger Brunck | 015a60f | 2011-09-14 10:54:12 +0200 | [diff] [blame] | 75 | #if defined(CONFIG_SYS_I2C_INIT_BOARD) |
Heiko Schocher | d9e1095 | 2011-03-08 10:51:15 +0100 | [diff] [blame] | 76 | static void i2c_write_start_seq(void) |
Heiko Schocher | 5e51b48 | 2008-10-15 09:39:08 +0200 | [diff] [blame] | 77 | { |
Heiko Schocher | 8ce3dd5 | 2011-03-15 16:52:29 +0100 | [diff] [blame] | 78 | set_sda(1); |
| 79 | udelay(DELAY_HALF_PERIOD); |
| 80 | set_scl(1); |
| 81 | udelay(DELAY_HALF_PERIOD); |
| 82 | set_sda(0); |
| 83 | udelay(DELAY_HALF_PERIOD); |
| 84 | set_scl(0); |
| 85 | udelay(DELAY_HALF_PERIOD); |
Heiko Schocher | 5e51b48 | 2008-10-15 09:39:08 +0200 | [diff] [blame] | 86 | } |
| 87 | |
Heiko Schocher | 8ce3dd5 | 2011-03-15 16:52:29 +0100 | [diff] [blame] | 88 | /* |
| 89 | * I2C is a synchronous protocol and resets of the processor in the middle |
| 90 | * of an access can block the I2C Bus until a powerdown of the full unit is |
| 91 | * done. This function toggles the SCL until the SCL and SCA line are |
| 92 | * released, but max. 16 times, after this a I2C start-sequence is sent. |
| 93 | * This I2C Deblocking mechanism was developed by Keymile in association |
| 94 | * with Anatech and Atmel in 1998. |
Heiko Schocher | 5e51b48 | 2008-10-15 09:39:08 +0200 | [diff] [blame] | 95 | */ |
Holger Brunck | bf20a88 | 2011-06-05 22:22:18 +0000 | [diff] [blame] | 96 | int i2c_make_abort(void) |
Heiko Schocher | 5e51b48 | 2008-10-15 09:39:08 +0200 | [diff] [blame] | 97 | { |
| 98 | int scl_state = 0; |
| 99 | int sda_state = 0; |
| 100 | int i = 0; |
| 101 | int ret = 0; |
| 102 | |
Heiko Schocher | 8ce3dd5 | 2011-03-15 16:52:29 +0100 | [diff] [blame] | 103 | if (!get_sda()) { |
Heiko Schocher | 5e51b48 | 2008-10-15 09:39:08 +0200 | [diff] [blame] | 104 | ret = -1; |
| 105 | while (i < 16) { |
| 106 | i++; |
Heiko Schocher | 8ce3dd5 | 2011-03-15 16:52:29 +0100 | [diff] [blame] | 107 | set_scl(0); |
| 108 | udelay(DELAY_ABORT_SEQ); |
| 109 | set_scl(1); |
| 110 | udelay(DELAY_ABORT_SEQ); |
| 111 | scl_state = get_scl(); |
| 112 | sda_state = get_sda(); |
Heiko Schocher | 5e51b48 | 2008-10-15 09:39:08 +0200 | [diff] [blame] | 113 | if (scl_state && sda_state) { |
| 114 | ret = 0; |
| 115 | break; |
| 116 | } |
| 117 | } |
| 118 | } |
Heiko Schocher | 8ce3dd5 | 2011-03-15 16:52:29 +0100 | [diff] [blame] | 119 | if (ret == 0) |
| 120 | for (i = 0; i < 5; i++) |
Heiko Schocher | d9e1095 | 2011-03-08 10:51:15 +0100 | [diff] [blame] | 121 | i2c_write_start_seq(); |
Heiko Schocher | 8ce3dd5 | 2011-03-15 16:52:29 +0100 | [diff] [blame] | 122 | |
Heiko Schocher | d9e1095 | 2011-03-08 10:51:15 +0100 | [diff] [blame] | 123 | /* respect stop setup time */ |
| 124 | udelay(DELAY_ABORT_SEQ); |
| 125 | set_scl(1); |
| 126 | udelay(DELAY_ABORT_SEQ); |
| 127 | set_sda(1); |
Heiko Schocher | 8ce3dd5 | 2011-03-15 16:52:29 +0100 | [diff] [blame] | 128 | get_sda(); |
Heiko Schocher | d9e1095 | 2011-03-08 10:51:15 +0100 | [diff] [blame] | 129 | |
Heiko Schocher | 5e51b48 | 2008-10-15 09:39:08 +0200 | [diff] [blame] | 130 | return ret; |
| 131 | } |
Heiko Schocher | 5e51b48 | 2008-10-15 09:39:08 +0200 | [diff] [blame] | 132 | |
Heiko Schocher | d9e1095 | 2011-03-08 10:51:15 +0100 | [diff] [blame] | 133 | /** |
| 134 | * i2c_init_board - reset i2c bus. When the board is powercycled during a |
| 135 | * bus transfer it might hang; for details see doc/I2C_Edge_Conditions. |
| 136 | */ |
| 137 | void i2c_init_board(void) |
| 138 | { |
Heiko Schocher | 5e51b48 | 2008-10-15 09:39:08 +0200 | [diff] [blame] | 139 | /* Now run the AbortSequence() */ |
Heiko Schocher | 8ce3dd5 | 2011-03-15 16:52:29 +0100 | [diff] [blame] | 140 | i2c_make_abort(); |
Heiko Schocher | 5e51b48 | 2008-10-15 09:39:08 +0200 | [diff] [blame] | 141 | } |
Holger Brunck | 015a60f | 2011-09-14 10:54:12 +0200 | [diff] [blame] | 142 | #endif |
| 143 | |
Valentin Longchamp | 391cc9b | 2013-10-18 11:47:18 +0200 | [diff] [blame] | 144 | #if defined(CONFIG_KM_COMMON_ETH_INIT) |
Heiko Schocher | 8ce3dd5 | 2011-03-15 16:52:29 +0100 | [diff] [blame] | 145 | int board_eth_init(bd_t *bis) |
Heiko Schocher | d19a6ec | 2008-11-21 08:29:40 +0100 | [diff] [blame] | 146 | { |
Heiko Schocher | 8ce3dd5 | 2011-03-15 16:52:29 +0100 | [diff] [blame] | 147 | if (ethernet_present()) |
Heiko Schocher | 466924f | 2010-02-18 08:08:25 +0100 | [diff] [blame] | 148 | return cpu_eth_init(bis); |
| 149 | |
| 150 | return -1; |
Heiko Schocher | d19a6ec | 2008-11-21 08:29:40 +0100 | [diff] [blame] | 151 | } |
Valentin Longchamp | 391cc9b | 2013-10-18 11:47:18 +0200 | [diff] [blame] | 152 | #endif |
Holger Brunck | 3066492 | 2011-05-04 01:47:30 +0000 | [diff] [blame] | 153 | |
| 154 | /* |
| 155 | * do_setboardid command |
| 156 | * read out the board id and the hw key from the intventory EEPROM and set |
| 157 | * this values as environment variables. |
| 158 | */ |
| 159 | static int do_setboardid(cmd_tbl_t *cmdtp, int flag, int argc, |
| 160 | char *const argv[]) |
| 161 | { |
| 162 | unsigned char buf[32]; |
| 163 | char *p; |
| 164 | |
| 165 | p = get_local_var("IVM_BoardId"); |
| 166 | if (p == NULL) { |
| 167 | printf("can't get the IVM_Boardid\n"); |
| 168 | return 1; |
| 169 | } |
Ben Whitten | 34fd6c9 | 2015-12-30 13:05:58 +0000 | [diff] [blame] | 170 | strcpy((char *)buf, p); |
Simon Glass | 6a38e41 | 2017-08-03 12:22:09 -0600 | [diff] [blame] | 171 | env_set("boardid", (char *)buf); |
Holger Brunck | de79984 | 2011-07-04 22:23:59 +0000 | [diff] [blame] | 172 | printf("set boardid=%s\n", buf); |
Holger Brunck | 3066492 | 2011-05-04 01:47:30 +0000 | [diff] [blame] | 173 | |
| 174 | p = get_local_var("IVM_HWKey"); |
| 175 | if (p == NULL) { |
| 176 | printf("can't get the IVM_HWKey\n"); |
| 177 | return 1; |
| 178 | } |
Ben Whitten | 34fd6c9 | 2015-12-30 13:05:58 +0000 | [diff] [blame] | 179 | strcpy((char *)buf, p); |
Simon Glass | 6a38e41 | 2017-08-03 12:22:09 -0600 | [diff] [blame] | 180 | env_set("hwkey", (char *)buf); |
Holger Brunck | de79984 | 2011-07-04 22:23:59 +0000 | [diff] [blame] | 181 | printf("set hwkey=%s\n", buf); |
| 182 | printf("Execute manually saveenv for persistent storage.\n"); |
Holger Brunck | 3066492 | 2011-05-04 01:47:30 +0000 | [diff] [blame] | 183 | |
| 184 | return 0; |
| 185 | } |
| 186 | |
| 187 | U_BOOT_CMD(km_setboardid, 1, 0, do_setboardid, "setboardid", "read out bid and " |
| 188 | "hwkey from IVM and set in environment"); |
Thomas Herzmann | 2c8a0c8 | 2011-05-12 19:59:22 +0000 | [diff] [blame] | 189 | |
| 190 | /* |
| 191 | * command km_checkbidhwk |
| 192 | * if "boardid" and "hwkey" are not already set in the environment, do: |
| 193 | * if a "boardIdListHex" exists in the environment: |
| 194 | * - read ivm data for boardid and hwkey |
| 195 | * - compare each entry of the boardIdListHex with the |
| 196 | * IVM data: |
| 197 | * if match: |
| 198 | * set environment variables boardid, boardId, |
| 199 | * hwkey, hwKey to the found values |
| 200 | * both (boardid and boardId) are set because |
| 201 | * they might be used differently in the |
| 202 | * application and in the init scripts (?) |
| 203 | * return 0 in case of match, 1 if not match or error |
| 204 | */ |
Holger Brunck | 828411f | 2013-05-06 15:02:40 +0200 | [diff] [blame] | 205 | static int do_checkboardidhwk(cmd_tbl_t *cmdtp, int flag, int argc, |
Thomas Herzmann | 2c8a0c8 | 2011-05-12 19:59:22 +0000 | [diff] [blame] | 206 | char *const argv[]) |
| 207 | { |
| 208 | unsigned long ivmbid = 0, ivmhwkey = 0; |
| 209 | unsigned long envbid = 0, envhwkey = 0; |
| 210 | char *p; |
| 211 | int verbose = argc > 1 && *argv[1] == 'v'; |
| 212 | int rc = 0; |
| 213 | |
| 214 | /* |
| 215 | * first read out the real inventory values, these values are |
| 216 | * already stored in the local hush variables |
| 217 | */ |
| 218 | p = get_local_var("IVM_BoardId"); |
| 219 | if (p == NULL) { |
| 220 | printf("can't get the IVM_Boardid\n"); |
| 221 | return 1; |
| 222 | } |
| 223 | rc = strict_strtoul(p, 16, &ivmbid); |
| 224 | |
| 225 | p = get_local_var("IVM_HWKey"); |
| 226 | if (p == NULL) { |
| 227 | printf("can't get the IVM_HWKey\n"); |
| 228 | return 1; |
| 229 | } |
| 230 | rc = strict_strtoul(p, 16, &ivmhwkey); |
| 231 | |
| 232 | if (!ivmbid || !ivmhwkey) { |
| 233 | printf("Error: IVM_BoardId and/or IVM_HWKey not set!\n"); |
| 234 | return rc; |
| 235 | } |
| 236 | |
| 237 | /* now try to read values from environment if available */ |
Simon Glass | 64b723f | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 238 | p = env_get("boardid"); |
Thomas Herzmann | 2c8a0c8 | 2011-05-12 19:59:22 +0000 | [diff] [blame] | 239 | if (p != NULL) |
| 240 | rc = strict_strtoul(p, 16, &envbid); |
Simon Glass | 64b723f | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 241 | p = env_get("hwkey"); |
Thomas Herzmann | 2c8a0c8 | 2011-05-12 19:59:22 +0000 | [diff] [blame] | 242 | if (p != NULL) |
| 243 | rc = strict_strtoul(p, 16, &envhwkey); |
| 244 | |
| 245 | if (rc != 0) { |
| 246 | printf("strict_strtoul returns error: %d", rc); |
| 247 | return rc; |
| 248 | } |
| 249 | |
| 250 | if (!envbid || !envhwkey) { |
| 251 | /* |
| 252 | * BoardId/HWkey not available in the environment, so try the |
| 253 | * environment variable for BoardId/HWkey list |
| 254 | */ |
Simon Glass | 64b723f | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 255 | char *bidhwklist = env_get("boardIdListHex"); |
Thomas Herzmann | 2c8a0c8 | 2011-05-12 19:59:22 +0000 | [diff] [blame] | 256 | |
| 257 | if (bidhwklist) { |
| 258 | int found = 0; |
| 259 | char *rest = bidhwklist; |
| 260 | char *endp; |
| 261 | |
| 262 | if (verbose) { |
| 263 | printf("IVM_BoardId: %ld, IVM_HWKey=%ld\n", |
| 264 | ivmbid, ivmhwkey); |
| 265 | printf("boardIdHwKeyList: %s\n", |
| 266 | bidhwklist); |
| 267 | } |
| 268 | while (!found) { |
| 269 | /* loop over each bid/hwkey pair in the list */ |
| 270 | unsigned long bid = 0; |
| 271 | unsigned long hwkey = 0; |
| 272 | |
| 273 | while (*rest && !isxdigit(*rest)) |
| 274 | rest++; |
| 275 | /* |
| 276 | * use simple_strtoul because we need &end and |
| 277 | * we know we got non numeric char at the end |
| 278 | */ |
| 279 | bid = simple_strtoul(rest, &endp, 16); |
| 280 | /* BoardId and HWkey are separated with a "_" */ |
| 281 | if (*endp == '_') { |
| 282 | rest = endp + 1; |
| 283 | /* |
| 284 | * use simple_strtoul because we need |
| 285 | * &end |
| 286 | */ |
| 287 | hwkey = simple_strtoul(rest, &endp, 16); |
| 288 | rest = endp; |
| 289 | while (*rest && !isxdigit(*rest)) |
| 290 | rest++; |
| 291 | } |
| 292 | if ((!bid) || (!hwkey)) { |
| 293 | /* end of list */ |
| 294 | break; |
| 295 | } |
| 296 | if (verbose) { |
| 297 | printf("trying bid=0x%lX, hwkey=%ld\n", |
| 298 | bid, hwkey); |
| 299 | } |
| 300 | /* |
| 301 | * Compare the values of the found entry in the |
| 302 | * list with the valid values which are stored |
| 303 | * in the inventory eeprom. If they are equal |
Holger Brunck | bc4e15f | 2011-06-05 22:22:17 +0000 | [diff] [blame] | 304 | * set the values in environment variables. |
Thomas Herzmann | 2c8a0c8 | 2011-05-12 19:59:22 +0000 | [diff] [blame] | 305 | */ |
| 306 | if ((bid == ivmbid) && (hwkey == ivmhwkey)) { |
| 307 | char buf[10]; |
| 308 | |
| 309 | found = 1; |
| 310 | envbid = bid; |
| 311 | envhwkey = hwkey; |
| 312 | sprintf(buf, "%lx", bid); |
Simon Glass | 6a38e41 | 2017-08-03 12:22:09 -0600 | [diff] [blame] | 313 | env_set("boardid", buf); |
Thomas Herzmann | 2c8a0c8 | 2011-05-12 19:59:22 +0000 | [diff] [blame] | 314 | sprintf(buf, "%lx", hwkey); |
Simon Glass | 6a38e41 | 2017-08-03 12:22:09 -0600 | [diff] [blame] | 315 | env_set("hwkey", buf); |
Thomas Herzmann | 2c8a0c8 | 2011-05-12 19:59:22 +0000 | [diff] [blame] | 316 | } |
| 317 | } /* end while( ! found ) */ |
| 318 | } |
| 319 | } |
| 320 | |
| 321 | /* compare now the values */ |
| 322 | if ((ivmbid == envbid) && (ivmhwkey == envhwkey)) { |
| 323 | printf("boardid=0x%3lX, hwkey=%ld\n", envbid, envhwkey); |
| 324 | rc = 0; /* match */ |
| 325 | } else { |
Holger Brunck | de79984 | 2011-07-04 22:23:59 +0000 | [diff] [blame] | 326 | printf("Error: env boardid=0x%3lX, hwkey=%ld\n", envbid, |
| 327 | envhwkey); |
Thomas Herzmann | 2c8a0c8 | 2011-05-12 19:59:22 +0000 | [diff] [blame] | 328 | printf(" IVM bId=0x%3lX, hwKey=%ld\n", ivmbid, ivmhwkey); |
| 329 | rc = 1; /* don't match */ |
| 330 | } |
| 331 | return rc; |
| 332 | } |
| 333 | |
| 334 | U_BOOT_CMD(km_checkbidhwk, 2, 0, do_checkboardidhwk, |
| 335 | "check boardid and hwkey", |
| 336 | "[v]\n - check environment parameter "\ |
| 337 | "\"boardIdListHex\" against stored boardid and hwkey "\ |
| 338 | "from the IVM\n v: verbose output" |
| 339 | ); |
Thomas Herzmann | b2c3160 | 2012-05-04 10:55:58 +0200 | [diff] [blame] | 340 | |
| 341 | /* |
| 342 | * command km_checktestboot |
| 343 | * if the testpin of the board is asserted, return 1 |
| 344 | * * else return 0 |
| 345 | */ |
Holger Brunck | 828411f | 2013-05-06 15:02:40 +0200 | [diff] [blame] | 346 | static int do_checktestboot(cmd_tbl_t *cmdtp, int flag, int argc, |
Thomas Herzmann | b2c3160 | 2012-05-04 10:55:58 +0200 | [diff] [blame] | 347 | char *const argv[]) |
| 348 | { |
| 349 | int testpin = 0; |
| 350 | char *s = NULL; |
| 351 | int testboot = 0; |
| 352 | int verbose = argc > 1 && *argv[1] == 'v'; |
| 353 | |
| 354 | #if defined(CONFIG_POST) |
| 355 | testpin = post_hotkeys_pressed(); |
Thomas Herzmann | b2c3160 | 2012-05-04 10:55:58 +0200 | [diff] [blame] | 356 | #endif |
Simon Glass | 64b723f | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 357 | s = env_get("test_bank"); |
Thomas Herzmann | b2c3160 | 2012-05-04 10:55:58 +0200 | [diff] [blame] | 358 | /* when test_bank is not set, act as if testpin is not asserted */ |
| 359 | testboot = (testpin != 0) && (s); |
| 360 | if (verbose) { |
| 361 | printf("testpin = %d\n", testpin); |
Wolfgang Denk | 6ae8083 | 2014-11-06 14:02:57 +0100 | [diff] [blame] | 362 | /* cppcheck-suppress nullPointer */ |
Thomas Herzmann | b2c3160 | 2012-05-04 10:55:58 +0200 | [diff] [blame] | 363 | printf("test_bank = %s\n", s ? s : "not set"); |
| 364 | printf("boot test app : %s\n", (testboot) ? "yes" : "no"); |
| 365 | } |
| 366 | /* return 0 means: testboot, therefore we need the inversion */ |
| 367 | return !testboot; |
| 368 | } |
| 369 | |
| 370 | U_BOOT_CMD(km_checktestboot, 2, 0, do_checktestboot, |
| 371 | "check if testpin is asserted", |
| 372 | "[v]\n v - verbose output" |
| 373 | ); |