xref: /rk3399_rockchip-uboot/board/keymile/common/common.c (revision 00caae6d47645e68d6e5277aceb69592b49381a6)
1c2485364SHeiko Schocher /*
2c2485364SHeiko Schocher  * (C) Copyright 2008
3c2485364SHeiko Schocher  * Heiko Schocher, DENX Software Engineering, hs@denx.de.
4c2485364SHeiko Schocher  *
54f745bf4SHolger Brunck  * (C) Copyright 2011
64f745bf4SHolger Brunck  * Holger Brunck, Keymile GmbH Hannover, holger.brunck@keymile.com
74f745bf4SHolger Brunck  *
81a459660SWolfgang Denk  * SPDX-License-Identifier:	GPL-2.0+
9c2485364SHeiko Schocher  */
10c2485364SHeiko Schocher 
11c2485364SHeiko Schocher #include <common.h>
12c2485364SHeiko Schocher #include <ioports.h>
13a9417ce7SHolger Brunck #include <command.h>
14c2485364SHeiko Schocher #include <malloc.h>
15eca86fadSSimon Glass #include <cli_hush.h>
16210c8c00SHeiko Schocher #include <net.h>
1762ddcf05SHeiko Schocher #include <netdev.h>
18210c8c00SHeiko Schocher #include <asm/io.h>
1992c91080SThomas Herzmann #include <linux/ctype.h>
20c2485364SHeiko Schocher 
21c1b3d841SThomas Herzmann #if defined(CONFIG_POST)
22c1b3d841SThomas Herzmann #include "post.h"
23c1b3d841SThomas Herzmann #endif
244f745bf4SHolger Brunck #include "common.h"
25c2485364SHeiko Schocher #include <i2c.h>
26c2485364SHeiko Schocher 
27f1fef1d8SHeiko Schocher DECLARE_GLOBAL_DATA_PTR;
286c11aeafSHeiko Schocher 
29f1fef1d8SHeiko Schocher /*
30f1fef1d8SHeiko Schocher  * Set Keymile specific environment variables
31f1fef1d8SHeiko Schocher  * Currently only some memory layout variables are calculated here
32f1fef1d8SHeiko Schocher  * ... ------------------------------------------------
33f1fef1d8SHeiko Schocher  * ... |@rootfsaddr |@pnvramaddr |@varaddr |@reserved |@END_OF_RAM
34f1fef1d8SHeiko Schocher  * ... |<------------------- pram ------------------->|
35f1fef1d8SHeiko Schocher  * ... ------------------------------------------------
36f1fef1d8SHeiko Schocher  * @END_OF_RAM: denotes the RAM size
37f1fef1d8SHeiko Schocher  * @pnvramaddr: Startadress of pseudo non volatile RAM in hex
38f1fef1d8SHeiko Schocher  * @pram      : preserved ram size in k
39f1fef1d8SHeiko Schocher  * @varaddr   : startadress for /var mounted into RAM
40f1fef1d8SHeiko Schocher  */
set_km_env(void)41f1fef1d8SHeiko Schocher int set_km_env(void)
42f1fef1d8SHeiko Schocher {
43f1fef1d8SHeiko Schocher 	uchar buf[32];
44f1fef1d8SHeiko Schocher 	unsigned int pnvramaddr;
45f1fef1d8SHeiko Schocher 	unsigned int pram;
46f1fef1d8SHeiko Schocher 	unsigned int varaddr;
472a7714ceSAndreas Huber 	unsigned int kernelmem;
482a7714ceSAndreas Huber 	char *p;
492a7714ceSAndreas Huber 	unsigned long rootfssize = 0;
50f1fef1d8SHeiko Schocher 
51f1fef1d8SHeiko Schocher 	pnvramaddr = gd->ram_size - CONFIG_KM_RESERVED_PRAM - CONFIG_KM_PHRAM
52f1fef1d8SHeiko Schocher 			- CONFIG_KM_PNVRAM;
53f1fef1d8SHeiko Schocher 	sprintf((char *)buf, "0x%x", pnvramaddr);
54382bee57SSimon Glass 	env_set("pnvramaddr", (char *)buf);
55f1fef1d8SHeiko Schocher 
5662a3b7ddSRobert P. J. Day 	/* try to read rootfssize (ram image) from environment */
57*00caae6dSSimon Glass 	p = env_get("rootfssize");
582a7714ceSAndreas Huber 	if (p != NULL)
592a7714ceSAndreas Huber 		strict_strtoul(p, 16, &rootfssize);
602a7714ceSAndreas Huber 	pram = (rootfssize + CONFIG_KM_RESERVED_PRAM + CONFIG_KM_PHRAM +
612a7714ceSAndreas Huber 		CONFIG_KM_PNVRAM) / 0x400;
62f1fef1d8SHeiko Schocher 	sprintf((char *)buf, "0x%x", pram);
63382bee57SSimon Glass 	env_set("pram", (char *)buf);
64f1fef1d8SHeiko Schocher 
65f1fef1d8SHeiko Schocher 	varaddr = gd->ram_size - CONFIG_KM_RESERVED_PRAM - CONFIG_KM_PHRAM;
66f1fef1d8SHeiko Schocher 	sprintf((char *)buf, "0x%x", varaddr);
67382bee57SSimon Glass 	env_set("varaddr", (char *)buf);
682a7714ceSAndreas Huber 
692a7714ceSAndreas Huber 	kernelmem = gd->ram_size - 0x400 * pram;
702a7714ceSAndreas Huber 	sprintf((char *)buf, "0x%x", kernelmem);
71382bee57SSimon Glass 	env_set("kernelmem", (char *)buf);
722a7714ceSAndreas Huber 
73f1fef1d8SHeiko Schocher 	return 0;
74f1fef1d8SHeiko Schocher }
75f1fef1d8SHeiko Schocher 
76e792affeSHolger Brunck #if defined(CONFIG_SYS_I2C_INIT_BOARD)
i2c_write_start_seq(void)776c11aeafSHeiko Schocher static void i2c_write_start_seq(void)
78c2485364SHeiko Schocher {
79c2485364SHeiko Schocher 	set_sda(1);
80c2485364SHeiko Schocher 	udelay(DELAY_HALF_PERIOD);
81c2485364SHeiko Schocher 	set_scl(1);
82c2485364SHeiko Schocher 	udelay(DELAY_HALF_PERIOD);
83c2485364SHeiko Schocher 	set_sda(0);
84c2485364SHeiko Schocher 	udelay(DELAY_HALF_PERIOD);
85c2485364SHeiko Schocher 	set_scl(0);
86c2485364SHeiko Schocher 	udelay(DELAY_HALF_PERIOD);
87c2485364SHeiko Schocher }
88c2485364SHeiko Schocher 
89b11f53f3SHeiko Schocher /*
90b11f53f3SHeiko Schocher  * I2C is a synchronous protocol and resets of the processor in the middle
91b11f53f3SHeiko Schocher  * of an access can block the I2C Bus until a powerdown of the full unit is
92b11f53f3SHeiko Schocher  * done. This function toggles the SCL until the SCL and SCA line are
93b11f53f3SHeiko Schocher  * released, but max. 16 times, after this a I2C start-sequence is sent.
94b11f53f3SHeiko Schocher  * This I2C Deblocking mechanism was developed by Keymile in association
95b11f53f3SHeiko Schocher  * with Anatech and Atmel in 1998.
96c2485364SHeiko Schocher  */
i2c_make_abort(void)974f745bf4SHolger Brunck int i2c_make_abort(void)
98c2485364SHeiko Schocher {
99c2485364SHeiko Schocher 	int	scl_state = 0;
100c2485364SHeiko Schocher 	int	sda_state = 0;
101c2485364SHeiko Schocher 	int	i = 0;
102c2485364SHeiko Schocher 	int	ret = 0;
103c2485364SHeiko Schocher 
104c2485364SHeiko Schocher 	if (!get_sda()) {
105c2485364SHeiko Schocher 		ret = -1;
106c2485364SHeiko Schocher 		while (i < 16) {
107c2485364SHeiko Schocher 			i++;
108c2485364SHeiko Schocher 			set_scl(0);
109c2485364SHeiko Schocher 			udelay(DELAY_ABORT_SEQ);
110c2485364SHeiko Schocher 			set_scl(1);
111c2485364SHeiko Schocher 			udelay(DELAY_ABORT_SEQ);
112c2485364SHeiko Schocher 			scl_state = get_scl();
113c2485364SHeiko Schocher 			sda_state = get_sda();
114c2485364SHeiko Schocher 			if (scl_state && sda_state) {
115c2485364SHeiko Schocher 				ret = 0;
116c2485364SHeiko Schocher 				break;
117c2485364SHeiko Schocher 			}
118c2485364SHeiko Schocher 		}
119c2485364SHeiko Schocher 	}
120b11f53f3SHeiko Schocher 	if (ret == 0)
121b11f53f3SHeiko Schocher 		for (i = 0; i < 5; i++)
1226c11aeafSHeiko Schocher 			i2c_write_start_seq();
123b11f53f3SHeiko Schocher 
1246c11aeafSHeiko Schocher 	/* respect stop setup time */
1256c11aeafSHeiko Schocher 	udelay(DELAY_ABORT_SEQ);
1266c11aeafSHeiko Schocher 	set_scl(1);
1276c11aeafSHeiko Schocher 	udelay(DELAY_ABORT_SEQ);
1286c11aeafSHeiko Schocher 	set_sda(1);
129c2485364SHeiko Schocher 	get_sda();
130c2485364SHeiko Schocher 
1316c11aeafSHeiko Schocher 	return ret;
1326c11aeafSHeiko Schocher }
1336c11aeafSHeiko Schocher 
1346c11aeafSHeiko Schocher /**
1356c11aeafSHeiko Schocher  * i2c_init_board - reset i2c bus. When the board is powercycled during a
1366c11aeafSHeiko Schocher  * bus transfer it might hang; for details see doc/I2C_Edge_Conditions.
1376c11aeafSHeiko Schocher  */
i2c_init_board(void)1386c11aeafSHeiko Schocher void i2c_init_board(void)
1396c11aeafSHeiko Schocher {
1406c11aeafSHeiko Schocher 	/* Now run the AbortSequence() */
1416c11aeafSHeiko Schocher 	i2c_make_abort();
142c2485364SHeiko Schocher }
143e792affeSHolger Brunck #endif
144e792affeSHolger Brunck 
14599f6249aSValentin Longchamp #if defined(CONFIG_KM_COMMON_ETH_INIT)
board_eth_init(bd_t * bis)146210c8c00SHeiko Schocher int board_eth_init(bd_t *bis)
147210c8c00SHeiko Schocher {
148b11f53f3SHeiko Schocher 	if (ethernet_present())
14962ddcf05SHeiko Schocher 		return cpu_eth_init(bis);
15062ddcf05SHeiko Schocher 
151210c8c00SHeiko Schocher 	return -1;
152210c8c00SHeiko Schocher }
15399f6249aSValentin Longchamp #endif
154a9417ce7SHolger Brunck 
155a9417ce7SHolger Brunck /*
156a9417ce7SHolger Brunck  * do_setboardid command
157a9417ce7SHolger Brunck  * read out the board id and the hw key from the intventory EEPROM and set
158a9417ce7SHolger Brunck  * this values as environment variables.
159a9417ce7SHolger Brunck  */
do_setboardid(cmd_tbl_t * cmdtp,int flag,int argc,char * const argv[])160a9417ce7SHolger Brunck static int do_setboardid(cmd_tbl_t *cmdtp, int flag, int argc,
161a9417ce7SHolger Brunck 				char *const argv[])
162a9417ce7SHolger Brunck {
163a9417ce7SHolger Brunck 	unsigned char buf[32];
164a9417ce7SHolger Brunck 	char *p;
165a9417ce7SHolger Brunck 
166a9417ce7SHolger Brunck 	p = get_local_var("IVM_BoardId");
167a9417ce7SHolger Brunck 	if (p == NULL) {
168a9417ce7SHolger Brunck 		printf("can't get the IVM_Boardid\n");
169a9417ce7SHolger Brunck 		return 1;
170a9417ce7SHolger Brunck 	}
171192bc694SBen Whitten 	strcpy((char *)buf, p);
172382bee57SSimon Glass 	env_set("boardid", (char *)buf);
1739485e779SHolger Brunck 	printf("set boardid=%s\n", buf);
174a9417ce7SHolger Brunck 
175a9417ce7SHolger Brunck 	p = get_local_var("IVM_HWKey");
176a9417ce7SHolger Brunck 	if (p == NULL) {
177a9417ce7SHolger Brunck 		printf("can't get the IVM_HWKey\n");
178a9417ce7SHolger Brunck 		return 1;
179a9417ce7SHolger Brunck 	}
180192bc694SBen Whitten 	strcpy((char *)buf, p);
181382bee57SSimon Glass 	env_set("hwkey", (char *)buf);
1829485e779SHolger Brunck 	printf("set hwkey=%s\n", buf);
1839485e779SHolger Brunck 	printf("Execute manually saveenv for persistent storage.\n");
184a9417ce7SHolger Brunck 
185a9417ce7SHolger Brunck 	return 0;
186a9417ce7SHolger Brunck }
187a9417ce7SHolger Brunck 
188a9417ce7SHolger Brunck U_BOOT_CMD(km_setboardid, 1, 0, do_setboardid, "setboardid", "read out bid and "
189a9417ce7SHolger Brunck 				 "hwkey from IVM and set in environment");
19092c91080SThomas Herzmann 
19192c91080SThomas Herzmann /*
19292c91080SThomas Herzmann  * command km_checkbidhwk
19392c91080SThomas Herzmann  *	if "boardid" and "hwkey" are not already set in the environment, do:
19492c91080SThomas Herzmann  *		if a "boardIdListHex" exists in the environment:
19592c91080SThomas Herzmann  *			- read ivm data for boardid and hwkey
19692c91080SThomas Herzmann  *			- compare each entry of the boardIdListHex with the
19792c91080SThomas Herzmann  *				IVM data:
19892c91080SThomas Herzmann  *			if match:
19992c91080SThomas Herzmann  *				set environment variables boardid, boardId,
20092c91080SThomas Herzmann  *				hwkey, hwKey to	the found values
20192c91080SThomas Herzmann  *				both (boardid and boardId) are set because
20292c91080SThomas Herzmann  *				they might be used differently in the
20392c91080SThomas Herzmann  *				application and in the init scripts (?)
20492c91080SThomas Herzmann  *	return 0 in case of match, 1 if not match or error
20592c91080SThomas Herzmann  */
do_checkboardidhwk(cmd_tbl_t * cmdtp,int flag,int argc,char * const argv[])206283857daSHolger Brunck static int do_checkboardidhwk(cmd_tbl_t *cmdtp, int flag, int argc,
20792c91080SThomas Herzmann 			char *const argv[])
20892c91080SThomas Herzmann {
20992c91080SThomas Herzmann 	unsigned long ivmbid = 0, ivmhwkey = 0;
21092c91080SThomas Herzmann 	unsigned long envbid = 0, envhwkey = 0;
21192c91080SThomas Herzmann 	char *p;
21292c91080SThomas Herzmann 	int verbose = argc > 1 && *argv[1] == 'v';
21392c91080SThomas Herzmann 	int rc = 0;
21492c91080SThomas Herzmann 
21592c91080SThomas Herzmann 	/*
21692c91080SThomas Herzmann 	 * first read out the real inventory values, these values are
21792c91080SThomas Herzmann 	 * already stored in the local hush variables
21892c91080SThomas Herzmann 	 */
21992c91080SThomas Herzmann 	p = get_local_var("IVM_BoardId");
22092c91080SThomas Herzmann 	if (p == NULL) {
22192c91080SThomas Herzmann 		printf("can't get the IVM_Boardid\n");
22292c91080SThomas Herzmann 		return 1;
22392c91080SThomas Herzmann 	}
22492c91080SThomas Herzmann 	rc = strict_strtoul(p, 16, &ivmbid);
22592c91080SThomas Herzmann 
22692c91080SThomas Herzmann 	p = get_local_var("IVM_HWKey");
22792c91080SThomas Herzmann 	if (p == NULL) {
22892c91080SThomas Herzmann 		printf("can't get the IVM_HWKey\n");
22992c91080SThomas Herzmann 		return 1;
23092c91080SThomas Herzmann 	}
23192c91080SThomas Herzmann 	rc = strict_strtoul(p, 16, &ivmhwkey);
23292c91080SThomas Herzmann 
23392c91080SThomas Herzmann 	if (!ivmbid || !ivmhwkey) {
23492c91080SThomas Herzmann 		printf("Error: IVM_BoardId and/or IVM_HWKey not set!\n");
23592c91080SThomas Herzmann 		return rc;
23692c91080SThomas Herzmann 	}
23792c91080SThomas Herzmann 
23892c91080SThomas Herzmann 	/* now try to read values from environment if available */
239*00caae6dSSimon Glass 	p = env_get("boardid");
24092c91080SThomas Herzmann 	if (p != NULL)
24192c91080SThomas Herzmann 		rc = strict_strtoul(p, 16, &envbid);
242*00caae6dSSimon Glass 	p = env_get("hwkey");
24392c91080SThomas Herzmann 	if (p != NULL)
24492c91080SThomas Herzmann 		rc = strict_strtoul(p, 16, &envhwkey);
24592c91080SThomas Herzmann 
24692c91080SThomas Herzmann 	if (rc != 0) {
24792c91080SThomas Herzmann 		printf("strict_strtoul returns error: %d", rc);
24892c91080SThomas Herzmann 		return rc;
24992c91080SThomas Herzmann 	}
25092c91080SThomas Herzmann 
25192c91080SThomas Herzmann 	if (!envbid || !envhwkey) {
25292c91080SThomas Herzmann 		/*
25392c91080SThomas Herzmann 		 * BoardId/HWkey not available in the environment, so try the
25492c91080SThomas Herzmann 		 * environment variable for BoardId/HWkey list
25592c91080SThomas Herzmann 		 */
256*00caae6dSSimon Glass 		char *bidhwklist = env_get("boardIdListHex");
25792c91080SThomas Herzmann 
25892c91080SThomas Herzmann 		if (bidhwklist) {
25992c91080SThomas Herzmann 			int found = 0;
26092c91080SThomas Herzmann 			char *rest = bidhwklist;
26192c91080SThomas Herzmann 			char *endp;
26292c91080SThomas Herzmann 
26392c91080SThomas Herzmann 			if (verbose) {
26492c91080SThomas Herzmann 				printf("IVM_BoardId: %ld, IVM_HWKey=%ld\n",
26592c91080SThomas Herzmann 					ivmbid, ivmhwkey);
26692c91080SThomas Herzmann 				printf("boardIdHwKeyList: %s\n",
26792c91080SThomas Herzmann 					bidhwklist);
26892c91080SThomas Herzmann 			}
26992c91080SThomas Herzmann 			while (!found) {
27092c91080SThomas Herzmann 				/* loop over each bid/hwkey pair in the list */
27192c91080SThomas Herzmann 				unsigned long bid   = 0;
27292c91080SThomas Herzmann 				unsigned long hwkey = 0;
27392c91080SThomas Herzmann 
27492c91080SThomas Herzmann 				while (*rest && !isxdigit(*rest))
27592c91080SThomas Herzmann 					rest++;
27692c91080SThomas Herzmann 				/*
27792c91080SThomas Herzmann 				 * use simple_strtoul because we need &end and
27892c91080SThomas Herzmann 				 * we know we got non numeric char at the end
27992c91080SThomas Herzmann 				 */
28092c91080SThomas Herzmann 				bid = simple_strtoul(rest, &endp, 16);
28192c91080SThomas Herzmann 				/* BoardId and HWkey are separated with a "_" */
28292c91080SThomas Herzmann 				if (*endp == '_') {
28392c91080SThomas Herzmann 					rest  = endp + 1;
28492c91080SThomas Herzmann 					/*
28592c91080SThomas Herzmann 					 * use simple_strtoul because we need
28692c91080SThomas Herzmann 					 * &end
28792c91080SThomas Herzmann 					 */
28892c91080SThomas Herzmann 					hwkey = simple_strtoul(rest, &endp, 16);
28992c91080SThomas Herzmann 					rest  = endp;
29092c91080SThomas Herzmann 					while (*rest && !isxdigit(*rest))
29192c91080SThomas Herzmann 						rest++;
29292c91080SThomas Herzmann 				}
29392c91080SThomas Herzmann 				if ((!bid) || (!hwkey)) {
29492c91080SThomas Herzmann 					/* end of list */
29592c91080SThomas Herzmann 					break;
29692c91080SThomas Herzmann 				}
29792c91080SThomas Herzmann 				if (verbose) {
29892c91080SThomas Herzmann 					printf("trying bid=0x%lX, hwkey=%ld\n",
29992c91080SThomas Herzmann 						bid, hwkey);
30092c91080SThomas Herzmann 				}
30192c91080SThomas Herzmann 				/*
30292c91080SThomas Herzmann 				 * Compare the values of the found entry in the
30392c91080SThomas Herzmann 				 * list with the valid values which are stored
30492c91080SThomas Herzmann 				 * in the inventory eeprom. If they are equal
305ba8be32aSHolger Brunck 				 * set the values in environment variables.
30692c91080SThomas Herzmann 				 */
30792c91080SThomas Herzmann 				if ((bid == ivmbid) && (hwkey == ivmhwkey)) {
30892c91080SThomas Herzmann 					char buf[10];
30992c91080SThomas Herzmann 
31092c91080SThomas Herzmann 					found = 1;
31192c91080SThomas Herzmann 					envbid   = bid;
31292c91080SThomas Herzmann 					envhwkey = hwkey;
31392c91080SThomas Herzmann 					sprintf(buf, "%lx", bid);
314382bee57SSimon Glass 					env_set("boardid", buf);
31592c91080SThomas Herzmann 					sprintf(buf, "%lx", hwkey);
316382bee57SSimon Glass 					env_set("hwkey", buf);
31792c91080SThomas Herzmann 				}
31892c91080SThomas Herzmann 			} /* end while( ! found ) */
31992c91080SThomas Herzmann 		}
32092c91080SThomas Herzmann 	}
32192c91080SThomas Herzmann 
32292c91080SThomas Herzmann 	/* compare now the values */
32392c91080SThomas Herzmann 	if ((ivmbid == envbid) && (ivmhwkey == envhwkey)) {
32492c91080SThomas Herzmann 		printf("boardid=0x%3lX, hwkey=%ld\n", envbid, envhwkey);
32592c91080SThomas Herzmann 		rc = 0; /* match */
32692c91080SThomas Herzmann 	} else {
3279485e779SHolger Brunck 		printf("Error: env boardid=0x%3lX, hwkey=%ld\n", envbid,
3289485e779SHolger Brunck 			envhwkey);
32992c91080SThomas Herzmann 		printf("       IVM bId=0x%3lX, hwKey=%ld\n", ivmbid, ivmhwkey);
33092c91080SThomas Herzmann 		rc = 1; /* don't match */
33192c91080SThomas Herzmann 	}
33292c91080SThomas Herzmann 	return rc;
33392c91080SThomas Herzmann }
33492c91080SThomas Herzmann 
33592c91080SThomas Herzmann U_BOOT_CMD(km_checkbidhwk, 2, 0, do_checkboardidhwk,
33692c91080SThomas Herzmann 		"check boardid and hwkey",
33792c91080SThomas Herzmann 		"[v]\n  - check environment parameter "\
33892c91080SThomas Herzmann 		"\"boardIdListHex\" against stored boardid and hwkey "\
33992c91080SThomas Herzmann 		"from the IVM\n    v: verbose output"
34092c91080SThomas Herzmann );
341c1b3d841SThomas Herzmann 
342c1b3d841SThomas Herzmann /*
343c1b3d841SThomas Herzmann  * command km_checktestboot
344c1b3d841SThomas Herzmann  *  if the testpin of the board is asserted, return 1
345c1b3d841SThomas Herzmann  *  *	else return 0
346c1b3d841SThomas Herzmann  */
do_checktestboot(cmd_tbl_t * cmdtp,int flag,int argc,char * const argv[])347283857daSHolger Brunck static int do_checktestboot(cmd_tbl_t *cmdtp, int flag, int argc,
348c1b3d841SThomas Herzmann 			char *const argv[])
349c1b3d841SThomas Herzmann {
350c1b3d841SThomas Herzmann 	int testpin = 0;
351c1b3d841SThomas Herzmann 	char *s = NULL;
352c1b3d841SThomas Herzmann 	int testboot = 0;
353c1b3d841SThomas Herzmann 	int verbose = argc > 1 && *argv[1] == 'v';
354c1b3d841SThomas Herzmann 
355c1b3d841SThomas Herzmann #if defined(CONFIG_POST)
356c1b3d841SThomas Herzmann 	testpin = post_hotkeys_pressed();
357c1b3d841SThomas Herzmann #endif
358*00caae6dSSimon Glass 	s = env_get("test_bank");
359c1b3d841SThomas Herzmann 	/* when test_bank is not set, act as if testpin is not asserted */
360c1b3d841SThomas Herzmann 	testboot = (testpin != 0) && (s);
361c1b3d841SThomas Herzmann 	if (verbose) {
362c1b3d841SThomas Herzmann 		printf("testpin   = %d\n", testpin);
3630060517aSWolfgang Denk 		/* cppcheck-suppress nullPointer */
364c1b3d841SThomas Herzmann 		printf("test_bank = %s\n", s ? s : "not set");
365c1b3d841SThomas Herzmann 		printf("boot test app : %s\n", (testboot) ? "yes" : "no");
366c1b3d841SThomas Herzmann 	}
367c1b3d841SThomas Herzmann 	/* return 0 means: testboot, therefore we need the inversion */
368c1b3d841SThomas Herzmann 	return !testboot;
369c1b3d841SThomas Herzmann }
370c1b3d841SThomas Herzmann 
371c1b3d841SThomas Herzmann U_BOOT_CMD(km_checktestboot, 2, 0, do_checktestboot,
372c1b3d841SThomas Herzmann 		"check if testpin is asserted",
373c1b3d841SThomas Herzmann 		"[v]\n  v - verbose output"
374c1b3d841SThomas Herzmann );
375