From 6cb02526b729cd14714c710b7332f0a4f0fccca0 Mon Sep 17 00:00:00 2001 From: Travis Geiselbrecht Date: Sat, 13 Jul 2019 16:56:33 -0700 Subject: [PATCH] [include][console] split lib/console.h into two TL;DR most uses of lib/console.h -> lk/console_cmd.h Move the part that lets a piece of code somewhere in the system to define a console command from the actual lib/console api to start an instance of the console. Move in almost every place the user of the console command definition to the new header, lk/console_cmd.h which is always in the include path. Also remove most uses of testing for WITH_LIB_CONSOLE since you can almost always just safely define it and then let the linker remove it. --- app/accelerometer/accelerometer.c | 7 +---- app/loader/loader.c | 6 +--- app/loader/rules.mk | 1 + app/pcitests/pci_tests.c | 6 +--- app/stringtests/string_tests.c | 6 +--- app/tests/cache_tests.c | 2 +- app/tests/cbuf_tests.c | 2 +- app/tests/float.c | 2 +- app/tests/include/app/tests.h | 2 +- app/tests/mem_tests.c | 2 +- app/tests/tests.c | 5 +-- arch/arm/arm/debug.c | 8 ++--- dev/gpio/debug.c | 6 +--- external/lib/aes/test/aes_test.c | 2 +- external/lib/cksum/debug.c | 6 +--- external/lib/lwip/cmd.c | 5 +-- kernel/debug.c | 10 +----- kernel/novm/novm.c | 5 +-- kernel/vm/pmm.c | 2 +- kernel/vm/vm.c | 2 +- kernel/vm/vmm.c | 2 +- lib/bio/debug.c | 6 +--- lib/buildsig/buildsig.c | 7 +---- lib/console/console.c | 3 +- lib/console/include/lib/console.h | 31 +++++++++++++++++++ lib/debugcommands/debugcommands.c | 2 +- lib/fs/debug.c | 7 +---- lib/fs/shell.c | 7 +---- lib/fs/spifs/spifs.c | 2 +- lib/fs/spifs/test/spifstest.c | 2 +- lib/gfx/gfx.c | 5 +-- lib/heap/heap_wrapper.c | 6 +--- lib/heap/page_alloc.c | 5 +-- lib/klog/klog.c | 8 +---- lib/minip/lk_console.c | 5 +-- lib/minip/tcp.c | 2 +- lib/ptable/ptable.c | 8 +---- lib/sysparam/sysparam.c | 6 +--- lib/version/version.c | 9 +----- platform/power.c | 12 +++---- platform/stm32f4xx/flash.c | 2 +- platform/zynq/gem.c | 2 +- platform/zynq/gpio.c | 5 +-- platform/zynq/platform.c | 4 +-- platform/zynq/qspi.c | 2 +- platform/zynq/spiflash.c | 7 +---- target/nucleo-f072rb/init.c | 2 +- .../console.h => top/include/lk/console_cmd.h | 21 +++---------- 48 files changed, 88 insertions(+), 179 deletions(-) create mode 100644 lib/console/include/lib/console.h rename include/lib/console.h => top/include/lk/console_cmd.h (82%) diff --git a/app/accelerometer/accelerometer.c b/app/accelerometer/accelerometer.c index c5e65f18..d38964f8 100644 --- a/app/accelerometer/accelerometer.c +++ b/app/accelerometer/accelerometer.c @@ -10,10 +10,7 @@ #include #include #include - - -#if defined(WITH_LIB_CONSOLE) -#include +#include void read_xyz(void); @@ -21,8 +18,6 @@ STATIC_COMMAND_START STATIC_COMMAND("read_xyz", "read xyz vectors", (console_cmd)&read_xyz) STATIC_COMMAND_END(accelerometer); -#endif - void read_xyz(void) { position_vector_t pos_vector; acc_read_xyz(&pos_vector); diff --git a/app/loader/loader.c b/app/loader/loader.c index c1e4e6c2..22c12c1e 100644 --- a/app/loader/loader.c +++ b/app/loader/loader.c @@ -18,11 +18,7 @@ #include -#if defined(WITH_LIB_CONSOLE) -#include -#else -#error "loader app needs a console" -#endif +#include #if defined(SDRAM_BASE) #define DOWNLOAD_BASE ((void*)SDRAM_BASE) diff --git a/app/loader/rules.mk b/app/loader/rules.mk index e1a1f11f..d05cb3ee 100644 --- a/app/loader/rules.mk +++ b/app/loader/rules.mk @@ -8,6 +8,7 @@ MODULE_SRCS += \ MODULE_DEPS := \ lib/cksum \ + lib/console \ lib/tftp \ lib/elf diff --git a/app/pcitests/pci_tests.c b/app/pcitests/pci_tests.c index c28e2943..05746573 100644 --- a/app/pcitests/pci_tests.c +++ b/app/pcitests/pci_tests.c @@ -14,9 +14,7 @@ #include #include #include - -#if defined(WITH_LIB_CONSOLE) -#include +#include /* * enumerates pci devices @@ -235,8 +233,6 @@ STATIC_COMMAND_START STATIC_COMMAND("pci", "pci toolbox", &pci_cmd) STATIC_COMMAND_END(pcitests); -#endif - APP_START(pcitests) APP_END diff --git a/app/stringtests/string_tests.c b/app/stringtests/string_tests.c index 9eff7cf4..bed46917 100644 --- a/app/stringtests/string_tests.c +++ b/app/stringtests/string_tests.c @@ -11,6 +11,7 @@ #include #include #include +#include static uint8_t *src; static uint8_t *dst; @@ -273,9 +274,6 @@ static void validate_memset(void) { } } -#if defined(WITH_LIB_CONSOLE) -#include - static int string_tests(int argc, const cmd_args *argv) { src = memalign(64, BUFFER_SIZE + 256); dst = memalign(64, BUFFER_SIZE + 256); @@ -327,8 +325,6 @@ STATIC_COMMAND_START STATIC_COMMAND("string", "memcpy tests", &string_tests) STATIC_COMMAND_END(stringtests); -#endif - APP_START(stringtests) APP_END diff --git a/app/tests/cache_tests.c b/app/tests/cache_tests.c index c1dcf76d..70ebecc9 100644 --- a/app/tests/cache_tests.c +++ b/app/tests/cache_tests.c @@ -13,7 +13,7 @@ #include #include #include -#include +#include #include static void bench_cache(size_t bufsize, uint8_t *buf) { diff --git a/app/tests/cbuf_tests.c b/app/tests/cbuf_tests.c index ebf4659f..ef0d8bc9 100644 --- a/app/tests/cbuf_tests.c +++ b/app/tests/cbuf_tests.c @@ -2,7 +2,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/app/tests/float.c b/app/tests/float.c index 7ec708bb..5ebaa562 100644 --- a/app/tests/float.c +++ b/app/tests/float.c @@ -10,7 +10,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/app/tests/include/app/tests.h b/app/tests/include/app/tests.h index c6f0ee12..9367b3c6 100644 --- a/app/tests/include/app/tests.h +++ b/app/tests/include/app/tests.h @@ -8,7 +8,7 @@ #ifndef __APP_TESTS_H #define __APP_TESTS_H -#include +#include int cbuf_tests(int argc, const cmd_args *argv); int fibo(int argc, const cmd_args *argv); diff --git a/app/tests/mem_tests.c b/app/tests/mem_tests.c index 65d6a16e..e500a298 100644 --- a/app/tests/mem_tests.c +++ b/app/tests/mem_tests.c @@ -11,7 +11,7 @@ #include #include #include -#include +#include #include #include diff --git a/app/tests/tests.c b/app/tests/tests.c index 08240d8c..6d798ee8 100644 --- a/app/tests/tests.c +++ b/app/tests/tests.c @@ -10,8 +10,7 @@ #include #include -#if defined(WITH_LIB_CONSOLE) -#include +#include STATIC_COMMAND_START STATIC_COMMAND("printf_tests", "test printf", &printf_tests) @@ -25,8 +24,6 @@ STATIC_COMMAND("spinner", "create a spinning thread", &spinner) STATIC_COMMAND("cbuf_tests", "test lib/cbuf", &cbuf_tests) STATIC_COMMAND_END(tests); -#endif - static void tests_init(const struct app_descriptor *app) { } diff --git a/arch/arm/arm/debug.c b/arch/arm/arm/debug.c index 1a5e8c24..ec320d64 100644 --- a/arch/arm/arm/debug.c +++ b/arch/arm/arm/debug.c @@ -14,6 +14,8 @@ #include #include #include +#include +#include struct dcc_state { dcc_rx_callback_t rx_callback; @@ -127,10 +129,6 @@ ssize_t arm_dcc_write(const uint32_t *buf, size_t len, lk_time_t timeout) { return count; } -#if WITH_LIB_CONSOLE -#include -#include - static void dcc_rx_callback(uint32_t val) { static int count = 0; count += 4; @@ -184,5 +182,3 @@ STATIC_COMMAND("dcc", "dcc stuff", &cmd_dcc) #endif STATIC_COMMAND_END(dcc); -#endif - diff --git a/dev/gpio/debug.c b/dev/gpio/debug.c index f1382ae0..2676d20f 100644 --- a/dev/gpio/debug.c +++ b/dev/gpio/debug.c @@ -7,12 +7,10 @@ */ #include -#include +#include #include #include -#if WITH_LIB_CONSOLE - struct flag_labels { unsigned id; const char *label; @@ -79,5 +77,3 @@ static int cmd_gpio(int argc, const cmd_args *argv) { STATIC_COMMAND_START STATIC_COMMAND("gpio", "commands for manipulating system gpios", &cmd_gpio) STATIC_COMMAND_END(gpio); - -#endif diff --git a/external/lib/aes/test/aes_test.c b/external/lib/aes/test/aes_test.c index 855aa41a..94ee3cb0 100644 --- a/external/lib/aes/test/aes_test.c +++ b/external/lib/aes/test/aes_test.c @@ -10,7 +10,7 @@ #include #include #include -#include +#include /* * These sample values come from publication "FIPS-197", Appendix C.1 diff --git a/external/lib/cksum/debug.c b/external/lib/cksum/debug.c index 1089f8a6..11df79b8 100644 --- a/external/lib/cksum/debug.c +++ b/external/lib/cksum/debug.c @@ -20,8 +20,6 @@ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#if WITH_LIB_CONSOLE - #include #include #include @@ -30,7 +28,7 @@ #include #include -#include +#include static int cmd_crc16(int argc, const cmd_args *argv); static int cmd_crc32(int argc, const cmd_args *argv); @@ -139,5 +137,3 @@ static int cmd_cksum_bench(int argc, const cmd_args *argv) free(buf); return 0; } - -#endif // WITH_LIB_CONSOLE diff --git a/external/lib/lwip/cmd.c b/external/lib/lwip/cmd.c index 4f26829c..c4d85e78 100644 --- a/external/lib/lwip/cmd.c +++ b/external/lib/lwip/cmd.c @@ -21,8 +21,7 @@ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#if defined(WITH_LIB_CONSOLE) -#include +#include #include #include @@ -66,5 +65,3 @@ STATIC_COMMAND_START STATIC_COMMAND("net", "net toolbox", &net_cmd) STATIC_COMMAND_END(net); -#endif - diff --git a/kernel/debug.c b/kernel/debug.c index 7f1dbf40..746cd213 100644 --- a/kernel/debug.c +++ b/kernel/debug.c @@ -24,9 +24,7 @@ #include #include #include - -#if WITH_LIB_CONSOLE -#include +#include static int cmd_threads(int argc, const cmd_args *argv); static int cmd_threadstats(int argc, const cmd_args *argv); @@ -147,8 +145,6 @@ static int cmd_threadload(int argc, const cmd_args *argv) { #endif // THREAD_STATS -#endif // WITH_LIB_CONSOLE - #if WITH_KERNEL_EVLOG #include @@ -173,8 +169,6 @@ void kernel_evlog_add(uintptr_t id, uintptr_t arg0, uintptr_t arg1) { } } -#if WITH_LIB_CONSOLE - static void kevdump_cb(const uintptr_t *i) { switch (i[1] & 0xffff) { case KERNEL_EVLOG_CONTEXT_SWITCH: @@ -213,6 +207,4 @@ static int cmd_kevlog(int argc, const cmd_args *argv) { return NO_ERROR; } -#endif - #endif // WITH_KERNEL_EVLOG diff --git a/kernel/novm/novm.c b/kernel/novm/novm.c index dfda1693..6c5096c0 100644 --- a/kernel/novm/novm.c +++ b/kernel/novm/novm.c @@ -15,6 +15,7 @@ #include #include #include +#include #define LOCAL_TRACE 0 @@ -233,9 +234,6 @@ status_t novm_alloc_specific_pages(void *address, size_t pages) { #if LK_DEBUGLEVEL > 1 -#if WITH_LIB_CONSOLE - -#include static int cmd_novm(int argc, const cmd_args *argv); static void novm_dump(void); @@ -310,5 +308,4 @@ static void novm_dump(void) { } #endif -#endif diff --git a/kernel/vm/pmm.c b/kernel/vm/pmm.c index 17eb9936..6603fac8 100644 --- a/kernel/vm/pmm.c +++ b/kernel/vm/pmm.c @@ -15,7 +15,7 @@ #include #include #include -#include +#include #include #define LOCAL_TRACE 0 diff --git a/kernel/vm/vm.c b/kernel/vm/vm.c index f0689a91..b973c1c2 100644 --- a/kernel/vm/vm.c +++ b/kernel/vm/vm.c @@ -12,7 +12,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/kernel/vm/vmm.c b/kernel/vm/vmm.c index 0512380a..55e12be8 100644 --- a/kernel/vm/vmm.c +++ b/kernel/vm/vmm.c @@ -9,7 +9,7 @@ #include #include #include -#include +#include #include #include #include "vm_priv.h" diff --git a/lib/bio/debug.c b/lib/bio/debug.c index ba8b1edc..dc4761e3 100644 --- a/lib/bio/debug.c +++ b/lib/bio/debug.c @@ -11,7 +11,7 @@ #include #include #include -#include +#include #include #include #include @@ -27,8 +27,6 @@ #define THREE_BYTE_ADDR_BOUNDARY (16777216) #define SUB_ERASE_TEST_SAMPLES (32) -#if defined(WITH_LIB_CONSOLE) - #if LK_DEBUGLEVEL > 0 static int cmd_bio(int argc, const cmd_args *argv); static int bio_test_device(bdev_t *device); @@ -273,8 +271,6 @@ usage: #endif -#endif - // Returns the number of blocks that do not match the reference pattern. static bool is_valid_block(bdev_t *device, bnum_t block_num, uint8_t *pattern, size_t pattern_length) { diff --git a/lib/buildsig/buildsig.c b/lib/buildsig/buildsig.c index e5ff2e08..7993ca75 100644 --- a/lib/buildsig/buildsig.c +++ b/lib/buildsig/buildsig.c @@ -14,6 +14,7 @@ #include #include #include +#include #define MAGIC ((uint32_t)'BSIG') #define MAGIC2 (~MAGIC) @@ -95,10 +96,6 @@ status_t buildsig_search(const void *_ptr, size_t search_len, size_t max_len, co return ERR_NOT_FOUND; } -#if WITH_LIB_CONSOLE - -#include - extern char __rom_start; static int cmd_buildsig(int argc, const cmd_args *argv) { @@ -140,5 +137,3 @@ STATIC_COMMAND("buildsig", "scan for and dump build signature", &cmd_buildsig) #endif STATIC_COMMAND_END(buildid); -#endif - diff --git a/lib/console/console.c b/lib/console/console.c index c03804c6..efa4262b 100644 --- a/lib/console/console.c +++ b/lib/console/console.c @@ -5,6 +5,8 @@ * license that can be found in the LICENSE file or at * https://opensource.org/licenses/MIT */ +#include + #include #include #include @@ -15,7 +17,6 @@ #include #include #include -#include #if WITH_LIB_ENV #include #endif diff --git a/lib/console/include/lib/console.h b/lib/console/include/lib/console.h new file mode 100644 index 00000000..f72e7d85 --- /dev/null +++ b/lib/console/include/lib/console.h @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2008-2009 Travis Geiselbrecht + * + * Use of this source code is governed by a MIT-style + * license that can be found in the LICENSE file or at + * https://opensource.org/licenses/MIT + */ +#pragma once + + +/* Previously, this file was included to get access to defining a console + * command. This logic has been moved into the following header, which is + * what in almost every case what regular code wants to include instead of + * this file. + */ +#include + +/* external api */ +int console_init(void); +void console_start(void); +void console_register_commands(cmd_block *block); +int console_run_script(const char *string); +int console_run_script_locked(const char *string); // special case from inside a command +console_cmd console_get_command_handler(const char *command); +void console_abort_script(void); + +/* panic shell api */ +void panic_shell_start(void); + +extern int lastresult; + diff --git a/lib/debugcommands/debugcommands.c b/lib/debugcommands/debugcommands.c index e5d7d2f0..a23a66ab 100644 --- a/lib/debugcommands/debugcommands.c +++ b/lib/debugcommands/debugcommands.c @@ -18,7 +18,7 @@ #include #include -#include +#include #if WITH_KERNEL_VM #include diff --git a/lib/fs/debug.c b/lib/fs/debug.c index 1df091c9..89bc0efe 100644 --- a/lib/fs/debug.c +++ b/lib/fs/debug.c @@ -7,7 +7,7 @@ */ #include #include -#include +#include #include #include #include @@ -51,8 +51,6 @@ test_normalize("/bleh/bar/../../foo/.."); test_normalize("/bleh/bar/../../foo/../meh"); #endif -#if defined(WITH_LIB_CONSOLE) - #if LK_DEBUGLEVEL > 1 static int cmd_fs(int argc, const cmd_args *argv); @@ -262,6 +260,3 @@ usage: } #endif - -#endif - diff --git a/lib/fs/shell.c b/lib/fs/shell.c index f4927af4..fec715c3 100644 --- a/lib/fs/shell.c +++ b/lib/fs/shell.c @@ -13,13 +13,11 @@ #include #include #include -#include +#include #include /* shell console hooks for manipulating the file system */ -#if WITH_LIB_CONSOLE - static char *cwd = NULL; static void set_cwd(const char *path) { @@ -285,6 +283,3 @@ STATIC_COMMAND("rm", "remove file", &cmd_rm) STATIC_COMMAND("stat", "stat file", &cmd_stat) STATIC_COMMAND("cat", "cat file", &cmd_cat) STATIC_COMMAND_END(fs_shell); - -#endif - diff --git a/lib/fs/spifs/spifs.c b/lib/fs/spifs/spifs.c index 32eeb2c9..5da42205 100644 --- a/lib/fs/spifs/spifs.c +++ b/lib/fs/spifs/spifs.c @@ -18,7 +18,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/lib/fs/spifs/test/spifstest.c b/lib/fs/spifs/test/spifstest.c index a5cf3d71..71367c4d 100644 --- a/lib/fs/spifs/test/spifstest.c +++ b/lib/fs/spifs/test/spifstest.c @@ -13,9 +13,9 @@ #include #include #include +#include #include -#include #include #define FS_NAME "spifs" diff --git a/lib/gfx/gfx.c b/lib/gfx/gfx.c index c24d6010..9b1e31d8 100644 --- a/lib/gfx/gfx.c +++ b/lib/gfx/gfx.c @@ -26,6 +26,7 @@ #include #include #include +#include #define LOCAL_TRACE 0 @@ -718,10 +719,7 @@ void gfx_draw_pattern_white(void) { gfx_surface_destroy(surface); } -#if defined(WITH_LIB_CONSOLE) - #if LK_DEBUGLEVEL > 1 -#include static int cmd_gfx(int argc, const cmd_args *argv); @@ -852,4 +850,3 @@ usage: } #endif -#endif diff --git a/lib/heap/heap_wrapper.c b/lib/heap/heap_wrapper.c index b85e0dd5..88c7d903 100644 --- a/lib/heap/heap_wrapper.c +++ b/lib/heap/heap_wrapper.c @@ -15,7 +15,7 @@ #include #include #include -#include +#include #include #define LOCAL_TRACE 0 @@ -297,9 +297,6 @@ static void heap_test(void) { #if LK_DEBUGLEVEL > 1 -#if WITH_LIB_CONSOLE - -#include static int cmd_heap(int argc, const cmd_args *argv); @@ -354,6 +351,5 @@ usage: } #endif -#endif diff --git a/lib/heap/page_alloc.c b/lib/heap/page_alloc.c index b9dc3e43..6f73071e 100644 --- a/lib/heap/page_alloc.c +++ b/lib/heap/page_alloc.c @@ -12,6 +12,7 @@ #include #include #include +#include #if WITH_KERNEL_VM #include #else @@ -74,9 +75,6 @@ void *page_first_alloc(size_t *size_return) { } #if LK_DEBUGLEVEL > 1 -#if WITH_LIB_CONSOLE - -#include static int cmd_page_alloc(int argc, const cmd_args *argv); static void page_alloc_dump(void); @@ -114,4 +112,3 @@ static void page_alloc_dump(void) { } #endif -#endif diff --git a/lib/klog/klog.c b/lib/klog/klog.c index f78ceae6..952f6a78 100644 --- a/lib/klog/klog.c +++ b/lib/klog/klog.c @@ -16,6 +16,7 @@ #include #include #include +#include #define LOCAL_TRACE 0 @@ -440,10 +441,6 @@ void klog_dump(int buffer) { } } -#if WITH_LIB_CONSOLE - -#include - #define KLOG_RETENTION_TEST 0 #if KLOG_RETENTION_TEST #include @@ -572,6 +569,3 @@ usage: STATIC_COMMAND_START STATIC_COMMAND("klog", "commands for manipulating klog", &cmd_klog) STATIC_COMMAND_END(klog); - -#endif // WITH_LIB_CONSOLE - diff --git a/lib/minip/lk_console.c b/lib/minip/lk_console.c index a97c6378..74904432 100644 --- a/lib/minip/lk_console.c +++ b/lib/minip/lk_console.c @@ -8,7 +8,7 @@ #include "minip-internal.h" -#include +#include #include #include #include @@ -17,8 +17,6 @@ #include #include -#if WITH_LIB_CONSOLE - uint32_t str_ip_to_int(const char *s, size_t len) { uint8_t ip[4] = { 0, 0, 0, 0 }; uint8_t pos = 0, i = 0; @@ -152,4 +150,3 @@ STATIC_COMMAND_START STATIC_COMMAND("arp", "arp commands", &cmd_arp) STATIC_COMMAND("mi", "minip commands", &cmd_minip) STATIC_COMMAND_END(minip); -#endif diff --git a/lib/minip/tcp.c b/lib/minip/tcp.c index b6174b84..05e489bc 100644 --- a/lib/minip/tcp.c +++ b/lib/minip/tcp.c @@ -15,7 +15,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/lib/ptable/ptable.c b/lib/ptable/ptable.c index 807426f5..ba57fd17 100644 --- a/lib/ptable/ptable.c +++ b/lib/ptable/ptable.c @@ -18,6 +18,7 @@ #include #include #include +#include #define LOCAL_TRACE 0 @@ -816,10 +817,6 @@ void ptable_dump(void) { } } -#if WITH_LIB_CONSOLE - -#include - static int cmd_ptable(int argc, const cmd_args *argv) { if (argc < 2) { notenoughargs: @@ -897,6 +894,3 @@ usage: STATIC_COMMAND_START STATIC_COMMAND("ptable", "commands for manipulating the flash partition table", &cmd_ptable) STATIC_COMMAND_END(ptable); - -#endif // WITH_LIB_CONSOLE - diff --git a/lib/sysparam/sysparam.c b/lib/sysparam/sysparam.c index 27680efa..a7cc4e30 100644 --- a/lib/sysparam/sysparam.c +++ b/lib/sysparam/sysparam.c @@ -18,6 +18,7 @@ #include #include #include +#include /* implementation of system parameter block, stored on a block device */ /* sysparams are simple name/value pairs, with the data unstructured */ @@ -468,9 +469,6 @@ void sysparam_dump(bool show_all) { printf("total in-memory usage: %zu bytes\n", total_memlen); } -#if WITH_LIB_CONSOLE - -#include #include static ssize_t hexstr_to_val(const char *str, uint8_t **buf) { @@ -678,5 +676,3 @@ done: STATIC_COMMAND_START STATIC_COMMAND("sysparam", "commands for manipulating system parameters", &cmd_sysparam) STATIC_COMMAND_END(sysparam); - -#endif // WITH_LIB_CONSOLE diff --git a/lib/version/version.c b/lib/version/version.c index 0eb88fb6..ace7937c 100644 --- a/lib/version/version.c +++ b/lib/version/version.c @@ -10,6 +10,7 @@ #include #include #include +#include /* generated for us */ #include @@ -39,11 +40,6 @@ void print_version(void) { printf("\tbuildid: %s\n", version.buildid); } -#if WITH_LIB_CONSOLE - -#include -#include - static int cmd_version(int argc, const cmd_args *argv) { print_version(); return 0; @@ -53,10 +49,7 @@ STATIC_COMMAND_START STATIC_COMMAND("version", "print version", &cmd_version) STATIC_COMMAND_END(version); -#endif // WITH_LIB_CONSOLE - #if LK_DEBUGLEVEL > 0 // print the version string if any level of debug is set LK_INIT_HOOK(version, (void *)&print_version, LK_INIT_LEVEL_HEAP - 1); #endif - diff --git a/platform/power.c b/platform/power.c index 42adb026..1e190851 100644 --- a/platform/power.c +++ b/platform/power.c @@ -12,7 +12,11 @@ #include #include #include +#include + +#if WITH_LIB_CONSOLE #include +#endif /* * default implementations of these routines, if the platform code @@ -20,7 +24,7 @@ */ __WEAK void platform_halt(platform_halt_action suggested_action, platform_halt_reason reason) { -#if ENABLE_PANIC_SHELL +#if WITH_LIB_CONSOLE && ENABLE_PANIC_SHELL if (reason == HALT_REASON_SW_PANIC) { dprintf(ALWAYS, "CRASH: starting debug shell... (reason = %d)\n", reason); @@ -35,10 +39,6 @@ __WEAK void platform_halt(platform_halt_action suggested_action, for (;;); } -#if WITH_LIB_CONSOLE - -#include - static int cmd_reboot(int argc, const cmd_args *argv) { platform_halt(HALT_ACTION_REBOOT, HALT_REASON_SW_RESET); return 0; @@ -55,5 +55,3 @@ STATIC_COMMAND("reboot", "soft reset", &cmd_reboot) STATIC_COMMAND("poweroff", "powerdown", &cmd_poweroff) #endif STATIC_COMMAND_END(platform_power); - -#endif diff --git a/platform/stm32f4xx/flash.c b/platform/stm32f4xx/flash.c index 31a9df00..af187657 100644 --- a/platform/stm32f4xx/flash.c +++ b/platform/stm32f4xx/flash.c @@ -10,7 +10,7 @@ #include #include #include -#include +#include #include #include diff --git a/platform/zynq/gem.c b/platform/zynq/gem.c index 3575fdb8..24f90dff 100644 --- a/platform/zynq/gem.c +++ b/platform/zynq/gem.c @@ -6,7 +6,7 @@ * https://opensource.org/licenses/MIT */ #include -#include +#include #include #include #include diff --git a/platform/zynq/gpio.c b/platform/zynq/gpio.c index c304da21..dcd32a54 100644 --- a/platform/zynq/gpio.c +++ b/platform/zynq/gpio.c @@ -15,6 +15,7 @@ #include #include #include +#include #define MAX_GPIO 128 @@ -232,8 +233,6 @@ int gpio_get(unsigned gpio) { return ((*REG32(GPIO_DATA_RO(bank)) & (1 << bit)) > 0); } -#include -#ifdef WITH_LIB_CONSOLE static int cmd_zynq_gpio(int argc, const cmd_args *argv) { for (unsigned int bank = 0; bank < 4; bank++) { printf("DIRM_%u (0x%08x): 0x%08x\n", bank, GPIO_DIRM(bank), *REG32(GPIO_DIRM(bank))); @@ -255,5 +254,3 @@ STATIC_COMMAND_START STATIC_COMMAND("zynq_gpio", "Dump Zynq GPIO registers", &cmd_zynq_gpio) #endif STATIC_COMMAND_END(zynq_gpio); - -#endif diff --git a/platform/zynq/platform.c b/platform/zynq/platform.c index b36c0ecd..ecbdbfd8 100644 --- a/platform/zynq/platform.c +++ b/platform/zynq/platform.c @@ -14,7 +14,7 @@ #include #include #include -#include +#include #include #include #include @@ -457,7 +457,6 @@ bool platform_abort_autoboot(void) { return false; } -#if WITH_LIB_CONSOLE static int cmd_zynq(int argc, const cmd_args *argv) { if (argc < 2) { notenoughargs: @@ -518,4 +517,3 @@ STATIC_COMMAND_START STATIC_COMMAND("zynq", "zynq configuration commands", &cmd_zynq) #endif STATIC_COMMAND_END(zynq); -#endif // WITH_LIB_CONSOLE diff --git a/platform/zynq/qspi.c b/platform/zynq/qspi.c index e48b86d2..cca016ad 100644 --- a/platform/zynq/qspi.c +++ b/platform/zynq/qspi.c @@ -15,7 +15,7 @@ #include #include -#include +#include #include diff --git a/platform/zynq/spiflash.c b/platform/zynq/spiflash.c index 4056dcf7..f89fec99 100644 --- a/platform/zynq/spiflash.c +++ b/platform/zynq/spiflash.c @@ -19,7 +19,7 @@ #include #include -#include +#include #include #include @@ -537,11 +537,6 @@ usage: return 0; } -#if defined(WITH_LIB_CONSOLE) -#include - STATIC_COMMAND_START STATIC_COMMAND("spiflash", "spi flash manipulation utilities", cmd_spiflash) STATIC_COMMAND_END(qspi); - -#endif diff --git a/target/nucleo-f072rb/init.c b/target/nucleo-f072rb/init.c index 237e5b9c..efa123cd 100644 --- a/target/nucleo-f072rb/init.c +++ b/target/nucleo-f072rb/init.c @@ -11,12 +11,12 @@ #include #include #include -#include #include #include #include #include #include +#include void target_early_init(void) { /* configure the usart2 pins */ diff --git a/include/lib/console.h b/top/include/lk/console_cmd.h similarity index 82% rename from include/lib/console.h rename to top/include/lk/console_cmd.h index 39db7102..8763d2b2 100644 --- a/include/lib/console.h +++ b/top/include/lk/console_cmd.h @@ -41,7 +41,10 @@ typedef struct _cmd_block { const cmd *list; } cmd_block; -/* register a static block of commands at init time */ +/* Register a static block of commands at init time when lib/console is + * paret of the build. Otherwise stub out these definitions so that they do + * not get included. + */ #if WITH_LIB_CONSOLE /* enable the panic shell if we're being built */ @@ -71,22 +74,8 @@ typedef struct _cmd_block { #define STATIC_COMMAND_END_NAMED(name) #define STATIC_COMMAND(command_str, help_str, func) +#define STATIC_COMMAND_MASKED(command_str, help_str, func, availability_mask) #endif #define COMMAND_BLOCK_INIT_ITEM(cmd_block_ptr, cmd_ptr) {(cmd_block_ptr)->next = NULL; (cmd_block_ptr)->count = 1; (cmd_block_ptr)->list = cmd_ptr;} - -/* external api */ -int console_init(void); -void console_start(void); -void console_register_commands(cmd_block *block); -int console_run_script(const char *string); -int console_run_script_locked(const char *string); // special case from inside a command -console_cmd console_get_command_handler(const char *command); -void console_abort_script(void); - -/* panic shell api */ -void panic_shell_start(void); - -extern int lastresult; -