diff options
author | Luke T. Shumaker <lukeshu@lukeshu.com> | 2025-02-21 10:34:00 -0700 |
---|---|---|
committer | Luke T. Shumaker <lukeshu@lukeshu.com> | 2025-02-21 10:34:00 -0700 |
commit | 19a41387633e53d64d8a0ae69f3d3d3e35641c8d (patch) | |
tree | a89dead6dd34f95b3e644edeb02fe1ca70a28784 /cmd/sbc_harness/main.c | |
parent | 4ba0b95dc825a83748b7cb2aa528411026d5bada (diff) | |
parent | 5dab625d981e0039a5d874f5d8a6f795472785bc (diff) |
Merge branch 'lukeshu/misc'
Diffstat (limited to 'cmd/sbc_harness/main.c')
-rw-r--r-- | cmd/sbc_harness/main.c | 115 |
1 files changed, 109 insertions, 6 deletions
diff --git a/cmd/sbc_harness/main.c b/cmd/sbc_harness/main.c index ce80711..2e83476 100644 --- a/cmd/sbc_harness/main.c +++ b/cmd/sbc_harness/main.c @@ -4,28 +4,128 @@ * SPDX-License-Identifier: AGPL-3.0-or-later */ -#include <string.h> /* libc: for strlen() */ +/* libc */ +#include <string.h> /* libc: for strlen() */ +/* pico-sdk */ #include <pico/stdio_uart.h> /* pico-sdk:pico_stdio_uart: for stdio_uart_init() */ #include <hardware/flash.h> /* pico-sdk:hardware_flash: for flash_get_unique_id() */ +/* our OS */ #include <libcr/coroutine.h> #include <libhw/generic/alarmclock.h> /* so we can set `bootclock` */ #include <libhw/rp2040_hwspi.h> #include <libhw/rp2040_hwtimer.h> #include <libhw/w5500.h> -#include <libmisc/hash.h> -#include <libusb/usb_common.h> + +/* our application libraries */ #include <libdhcp/client.h> +#include <libusb/usb_common.h> #include <lib9p/srv.h> +#include <util9p/static.h> +/* our utility libraries */ +#include <libmisc/hash.h> #define LOG_NAME MAIN #include <libmisc/log.h> +/* local headers */ #include "usb_keyboard.h" +#include "static.h" + +/* configuration **************************************************************/ #include "config.h" +/* file tree ******************************************************************/ + +#define _box(nam, obj) \ + ((struct lib9p_srv_file){ \ + .self = obj, \ + .vtable = (void*)&_lo_##nam##_lib9p_srv_file_vtable, \ + }) +#define lo_box_util9p_static_file_as_lib9p_srv_file(obj) _box(util9p_static_file, obj) +#define lo_box_util9p_static_dir_as_lib9p_srv_file(obj) _box(util9p_static_dir, obj) +#define lo_box_api_as_lib9p_srv_file(obj) _box(api, obj) + +enum { PATH_BASE = __COUNTER__ }; +#define PATH_COUNTER __COUNTER__ - PATH_BASE + +#define STATIC_COMMON(STRNAME, MODE) \ + { \ + .u_name = "root", .u_num = 0, /* owner user */ \ + .g_name = "root", .g_num = 0, /* owner group */ \ + .m_name = "root", .m_num = 0, /* last-modified-by user */ \ + \ + .pathnum = PATH_COUNTER, \ + .name = STRNAME, \ + .perm = MODE, \ + .atime = 1728337905, \ + .mtime = 1728337904, \ + } + +#define STATIC_FILE(STRNAME, ...) \ + lo_box_util9p_static_file_as_lib9p_srv_file(&((struct util9p_static_file){ \ + ._util9p_static_common = STATIC_COMMON(STRNAME, 0444), \ + __VA_ARGS__ \ + })) + +#define STATIC_DIR(STRNAME, ...) \ + lo_box_util9p_static_dir_as_lib9p_srv_file(&((struct util9p_static_dir){ \ + ._util9p_static_common = STATIC_COMMON(STRNAME, 0555), \ + .members = { __VA_ARGS__ LO_NULL(lib9p_srv_file) }, \ + })) + +struct lib9p_srv_file root = + STATIC_DIR("", + STATIC_DIR("Documentation", + STATIC_FILE("YOUR_RIGHTS_AND_OBLIGATIONS.md", + .data_start = _binary_static_Documentation_YOUR_RIGHTS_AND_OBLIGATIONS_md_start, + .data_end = _binary_static_Documentation_YOUR_RIGHTS_AND_OBLIGATIONS_md_end), + STATIC_DIR("YOUR_RIGHTS_AND_OBLIGATIONS", + STATIC_FILE("agpl-3.0.txt", + .data_start = _binary_static_Documentation_YOUR_RIGHTS_AND_OBLIGATIONS_agpl_3_0_txt_start, + .data_end = _binary_static_Documentation_YOUR_RIGHTS_AND_OBLIGATIONS_agpl_3_0_txt_end), + STATIC_FILE("pico-sdk.bsd3.txt", + .data_start = _binary_static_Documentation_YOUR_RIGHTS_AND_OBLIGATIONS_pico_sdk_bsd3_txt_start, + .data_end = _binary_static_Documentation_YOUR_RIGHTS_AND_OBLIGATIONS_pico_sdk_bsd3_txt_end), + STATIC_FILE("printf.mit.txt", + .data_start = _binary_static_Documentation_YOUR_RIGHTS_AND_OBLIGATIONS_printf_mit_txt_start, + .data_end = _binary_static_Documentation_YOUR_RIGHTS_AND_OBLIGATIONS_printf_mit_txt_end), + STATIC_FILE("tinyusb.mit.txt", + .data_start = _binary_static_Documentation_YOUR_RIGHTS_AND_OBLIGATIONS_tinyusb_mit_txt_start, + .data_end = _binary_static_Documentation_YOUR_RIGHTS_AND_OBLIGATIONS_tinyusb_mit_txt_end), + STATIC_FILE("newlib.txt", + .data_start = _binary_static_Documentation_YOUR_RIGHTS_AND_OBLIGATIONS_newlib_txt_start, + .data_end = _binary_static_Documentation_YOUR_RIGHTS_AND_OBLIGATIONS_newlib_txt_end), + ), + ), + STATIC_DIR("harness", + STATIC_FILE("rom.bin", + .data_start = (void*)0x00000000, + .data_size = 16*1024), + // TODO: Make flash.bin writable. + STATIC_FILE("flash.bin", + .data_start = (void*)0x10000000, + .data_size = PICO_FLASH_SIZE_BYTES), + // TODO: system.log + // TODO: proc.txt + // TODO: ctl + ), + STATIC_DIR("dut", + // TODO: hdmi.nut + // TODO: uart.txt + // TODO: usb-keyboard.txt + ), + ); + +static lo_interface lib9p_srv_file get_root(struct lib9p_srv_ctx *LM_UNUSED(ctx), struct lib9p_s LM_UNUSED(treename)) { + return root; +} + +/* Code ***********************************************************************/ + +/* static COROUTINE hello_world_cr(void *_chan) { const char *msg = "Hello world!\n"; usb_keyboard_rpc_t *chan = _chan; @@ -41,6 +141,7 @@ static COROUTINE hello_world_cr(void *_chan) { cr_end(); } +*/ struct { struct rp2040_hwspi dev_spi; @@ -67,7 +168,7 @@ static COROUTINE read9p_cr(void *) { cr_end(); } -const char *hexdig = "0123456789ABCDEF"; +const char *const hexdig = "0123456789ABCDEF"; static_assert(CONFIG_9P_SRV_MAX_REQS*_CONFIG_9P_NUM_SOCKS <= 16); COROUTINE init_cr(void *) { @@ -114,11 +215,13 @@ COROUTINE init_cr(void *) { globals.keyboard_chan = (usb_keyboard_rpc_t){0}; + globals.srv.rootdir = get_root; + /* set up coroutines **************************************************/ coroutine_add("usb_common", usb_common_cr, NULL); coroutine_add("usb_keyboard", usb_keyboard_cr, &globals.keyboard_chan); - coroutine_add("hello_world", hello_world_cr, &globals.keyboard_chan); - coroutine_add_with_stack_size(4*1024, "dhcp", dhcp_cr, NULL); + //coroutine_add("hello_world", hello_world_cr, &globals.keyboard_chan); + coroutine_add("dhcp", dhcp_cr, NULL); for (int i = 0; i < _CONFIG_9P_NUM_SOCKS; i++) { char name[] = {'r', 'e', 'a', 'd', '-', hexdig[i], '\0'}; coroutine_add(name, read9p_cr, NULL); |