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