Commit 54055ff7a6e66e7206db6f5e350f3880983afdd8

Authored by Stefan Roese
1 parent ef13016573

arm: mvebu: theadorable: Add test for ctrl-c in PCIe PEX switch test

The check for the missing PEX switch can lead to an infinite loop, when
the PCIe device is not found. It is helpful to enable the user to break
out of this boot-loop, to enable booting to the prompt for test cases.
This patch adds a 3 second delay in the error case before rebooting.
The user can press Ctrl-C in this time to abort the boot-loop.

This patch also calls bootcount_inc() before rebooting in the error
case. This is needed to increment the bootcounter, since this function
is called earlier than the main bootcounter increment. Otherwise the
bootcounter will not be incremented in the error case at all.

Signed-off-by: Stefan Roese <sr@denx.de>

Showing 1 changed file with 30 additions and 2 deletions Side-by-side Diff

board/theadorable/theadorable.c
1 1 // SPDX-License-Identifier: GPL-2.0+
2 2 /*
3   - * Copyright (C) 2015-2016 Stefan Roese <sr@denx.de>
  3 + * Copyright (C) 2015-2019 Stefan Roese <sr@denx.de>
4 4 */
5 5  
6 6 #include <common.h>
  7 +#include <console.h>
7 8 #include <i2c.h>
8 9 #include <pci.h>
  10 +#if !defined(CONFIG_SPL_BUILD)
  11 +#include <bootcount.h>
  12 +#endif
9 13 #include <asm/gpio.h>
10 14 #include <asm/io.h>
11 15 #include <asm/arch/cpu.h>
... ... @@ -42,6 +46,7 @@
42 46 #define STM_I2C_BUS 1
43 47 #define STM_I2C_ADDR 0x27
44 48 #define REBOOT_DELAY 1000 /* reboot-delay in ms */
  49 +#define ABORT_TIMEOUT 3000 /* 3 seconds reboot abort timeout */
45 50  
46 51 /* DDR3 static configuration */
47 52 static MV_DRAM_MC_INIT ddr3_theadorable[MV_MAX_DDR3_STATIC_SIZE] = {
... ... @@ -218,7 +223,7 @@
218 223 }
219 224 #endif
220 225  
221   -#ifdef CONFIG_BOARD_LATE_INIT
  226 +#if !defined(CONFIG_SPL_BUILD) && defined(CONFIG_BOARD_LATE_INIT)
222 227 int board_late_init(void)
223 228 {
224 229 pci_dev_t bdf;
... ... @@ -232,6 +237,7 @@
232 237 */
233 238 bdf = pci_find_device(PCI_VENDOR_ID_PLX, 0x8619, 0);
234 239 if (bdf == -1) {
  240 + unsigned long start_time = get_timer(0);
235 241 u8 i2c_buf[8];
236 242 int ret;
237 243  
... ... @@ -239,6 +245,28 @@
239 245 bootcount = bootcount_load();
240 246 printf("Failed to find PLX PEX-switch (bootcount=%ld)\n",
241 247 bootcount);
  248 +
  249 + /*
  250 + * The user can exit this boot-loop in the error case by
  251 + * hitting Ctrl-C. So wait some time for this key here.
  252 + */
  253 + printf("Continue booting with Ctrl-C, otherwise rebooting\n");
  254 + do {
  255 + /* Handle control-c and timeouts */
  256 + if (ctrlc()) {
  257 + printf("PEX error boot-loop aborted!\n");
  258 + return 0;
  259 + }
  260 + } while (get_timer(start_time) < ABORT_TIMEOUT);
  261 +
  262 +
  263 + /*
  264 + * At this stage the bootcounter has not been incremented
  265 + * yet. We need to do this manually here to get an actually
  266 + * working bootcounter in this error case.
  267 + */
  268 + bootcount_inc();
  269 +
242 270 if (bootcount > PEX_SWITCH_NOT_FOUNT_LIMIT) {
243 271 printf("Issuing power-switch via uC!\n");
244 272