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