From d57cd3a0bf2594a3de6646ba13e76d8b3aa26a99 Mon Sep 17 00:00:00 2001 From: Piotr Dymacz Date: Sun, 21 Aug 2016 00:32:13 +0200 Subject: [PATCH] Include two trivial commands: button and sleep These simple commands might be very useful in scripts and as we already using Hush shell type, it would be easier to transform recovery modes into some set of scripts instead of hard-coding them. --- u-boot/common/cmd_custom.c | 81 +++++++++++++++++++++++++++------- u-boot/common/main.c | 1 - u-boot/include/common.h | 17 +++---- u-boot/include/configs/ap121.h | 2 + u-boot/include/configs/ap143.h | 2 + u-boot/include/configs/db12x.h | 2 + 6 files changed, 79 insertions(+), 26 deletions(-) diff --git a/u-boot/common/cmd_custom.c b/u-boot/common/cmd_custom.c index 94b7cbd..4e49479 100644 --- a/u-boot/common/cmd_custom.c +++ b/u-boot/common/cmd_custom.c @@ -1,22 +1,11 @@ /* - * (C) Copyright 2013 - * Piotr Dymacz (pepe2k), Real Time Systems, piotr@realtimesystems.pl, pepe2k@gmail.com - * Custom commands for U-Boot 1.1.4 modification. + * Copyright (C) 2016 Piotr Dymacz * - * See file CREDITS for list of people who contributed to U-Boot project. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * SPDX-License-Identifier: GPL-2.0 + */ + +/* + * Custom/miscellaneous commands */ #include @@ -241,3 +230,61 @@ int do_default_env(cmd_tbl_t * cmdtp, int flag, int argc, char *argv[]){ U_BOOT_CMD(defenv, 1, 0, do_default_env, "reset environment variables to their default values\n", NULL); #endif /* if !defined(CONFIG_FOR_DLINK_DIR505_A1) */ + +/* + * Allows to get reset button status: + * - returns 0 if button is pressed + * - returns 1 if button is not pressed + * + * Logic here must be inverted as in shell + * 0 means success/true + * + * This allows to use it in scripts, ex.: + * if button; then ...; else ...; fi ... + * + * or, simply: + * button && echo pressed! + * button || echo not pressed! + */ +#if defined(CONFIG_CMD_BUTTON) +int do_button(cmd_tbl_t * cmdtp, int flag, int argc, char *argv[]) +{ +#if defined(CFG_HUSH_PARSER) + return !reset_button_status(); +#else + int btn = reset_button_status(); + + if (btn) + puts("Reset button is pressed\n"); + else + puts("Reset button is not pressed\n"); + + return !btn; +#endif +} + +U_BOOT_CMD(button, 1, 1, do_button, + "get reset button status\n", NULL); +#endif /* CONFIG_CMD_BUTTON */ + +/* + * Allows to delay execution + * for a given/specified time (in ms) + */ +#if defined(CONFIG_CMD_SLEEP) +int do_sleep(cmd_tbl_t * cmdtp, int flag, int argc, char *argv[]) +{ + if (argc != 2) { + print_cmd_help(cmdtp); + return 1; + } + + milisecdelay(simple_strtoul(argv[1], NULL, 10)); + + return 0; +} + +U_BOOT_CMD(sleep, 2, 1, do_sleep, + "sleep for specified time\n", "ms\n" + "\t- sleep for 'ms' number of milliseconds\n"); +#endif /* CONFIG_CMD_SLEEP */ diff --git a/u-boot/common/main.c b/u-boot/common/main.c index a0b3e14..17a5e58 100644 --- a/u-boot/common/main.c +++ b/u-boot/common/main.c @@ -34,7 +34,6 @@ DECLARE_GLOBAL_DATA_PTR; #endif -extern int reset_button_status(void); extern void all_led_on(void); extern void all_led_off(void); extern int NetLoopHttpd(void); diff --git a/u-boot/include/common.h b/u-boot/include/common.h index 3a69e21..5c66dc5 100644 --- a/u-boot/include/common.h +++ b/u-boot/include/common.h @@ -184,14 +184,15 @@ void init_cmd_timeout(void); void reset_cmd_timeout(void); /* lib_$(ARCH)/board.c */ -void board_init_f (ulong); -void board_init_r (gd_t *, ulong); -int checkboard (void); -int checkflash (void); -int checkdram (void); -char * strmhz(char *buf, long hz); -int last_stage_init(void); -extern ulong monitor_flash_len; +void board_init_f(ulong); +void board_init_r(gd_t *, ulong); +char *strmhz(char *buf, long hz); +int checkboard(void); +int checkflash(void); +int checkdram(void); +int last_stage_init(void); +int reset_button_status(void); +extern ulong monitor_flash_len; /* common/flash.c */ void flash_perror (int); diff --git a/u-boot/include/configs/ap121.h b/u-boot/include/configs/ap121.h index 19f8be8..337e199 100644 --- a/u-boot/include/configs/ap121.h +++ b/u-boot/include/configs/ap121.h @@ -411,6 +411,8 @@ #define CONFIG_CMD_IMI #define CONFIG_CMD_ENV #define CONFIG_CMD_LOADB + #define CONFIG_CMD_BUTTON + #define CONFIG_CMD_SLEEP #endif diff --git a/u-boot/include/configs/ap143.h b/u-boot/include/configs/ap143.h index 7350dcf..5f4db9f 100644 --- a/u-boot/include/configs/ap143.h +++ b/u-boot/include/configs/ap143.h @@ -225,6 +225,8 @@ #define CONFIG_CMD_IMI #define CONFIG_CMD_ENV #define CONFIG_CMD_LOADB +#define CONFIG_CMD_BUTTON +#define CONFIG_CMD_SLEEP // Enable NetConsole and custom NetConsole port #define CONFIG_NETCONSOLE diff --git a/u-boot/include/configs/db12x.h b/u-boot/include/configs/db12x.h index abfb824..d2b3885 100644 --- a/u-boot/include/configs/db12x.h +++ b/u-boot/include/configs/db12x.h @@ -189,6 +189,8 @@ #define CONFIG_CMD_IMI #define CONFIG_CMD_ENV #define CONFIG_CMD_LOADB +#define CONFIG_CMD_BUTTON +#define CONFIG_CMD_SLEEP // Enable NetConsole and custom NetConsole port #define CONFIG_NETCONSOLE -- 2.25.1