diff options
Diffstat (limited to 'cmd/sbc_harness')
-rw-r--r-- | cmd/sbc_harness/config/config.h | 5 | ||||
-rw-r--r-- | cmd/sbc_harness/fs_harness_flash_bin.c | 69 | ||||
-rw-r--r-- | cmd/sbc_harness/fs_harness_flash_bin.h | 1 | ||||
-rw-r--r-- | cmd/sbc_harness/fs_harness_uptime_txt.c | 44 | ||||
-rw-r--r-- | cmd/sbc_harness/fs_harness_uptime_txt.h | 1 | ||||
-rw-r--r-- | cmd/sbc_harness/main.c | 20 |
6 files changed, 58 insertions, 82 deletions
diff --git a/cmd/sbc_harness/config/config.h b/cmd/sbc_harness/config/config.h index ca23462..61745e5 100644 --- a/cmd/sbc_harness/config/config.h +++ b/cmd/sbc_harness/config/config.h @@ -37,8 +37,6 @@ /* 9P *************************************************************************/ -#define CONFIG_9P_MAX_ERR_SIZE 128 /* 128 is what Plan 9 4e uses */ - #define CONFIG_9P_ENABLE_9P2000 1 /* bool */ #define CONFIG_9P_ENABLE_9P2000_u 1 /* bool */ #define CONFIG_9P_ENABLE_9P2000_e 0 /* bool */ @@ -49,8 +47,6 @@ #define CONFIG_9P_SRV_DEBUG 1 /* bool */ -#define CONFIG_9P_SRV_MAX_MSG_SIZE ((4*1024)+24) - /** * This max-msg-size is sized so that a Twrite message can return * 8KiB of data. @@ -69,6 +65,7 @@ * (8*1024)+160 in 2e and 3e. */ #define CONFIG_9P_SRV_MAX_MSG_SIZE ((4*1024)+24) +#define CONFIG_9P_SRV_MAX_ERR_SIZE 128 /* 128 is what Plan 9 4e uses */ /** * Maximum host-data-structure size. A message may be larger in * unmarshaled-host-structures than marshaled-net-bytes due to (1) diff --git a/cmd/sbc_harness/fs_harness_flash_bin.c b/cmd/sbc_harness/fs_harness_flash_bin.c index 5e6f49c..ea60447 100644 --- a/cmd/sbc_harness/fs_harness_flash_bin.c +++ b/cmd/sbc_harness/fs_harness_flash_bin.c @@ -148,11 +148,11 @@ static struct lib9p_qid flash_file_qid(struct flash_file *self) { }; } -static struct lib9p_srv_stat flash_file_stat(struct flash_file *self, struct lib9p_srv_ctx *ctx) { +static lib9p_srv_stat_or_error flash_file_stat(struct flash_file *self, struct lib9p_srv_ctx *ctx) { assert(self); assert(ctx); - return (struct lib9p_srv_stat){ + return ERROR_NEW_VAL(lib9p_srv_stat, ((struct lib9p_srv_stat){ .qid = flash_file_qid(self), .mode = LIB9P_DM_EXCL|0666, .atime_sec = UTIL9P_ATIME, @@ -163,25 +163,25 @@ static struct lib9p_srv_stat flash_file_stat(struct flash_file *self, struct lib .owner_gid = { .name = lib9p_str("root"), .num = 0 }, .last_modifier_uid = { .name = lib9p_str("root"), .num = 0 }, .extension = lib9p_str(NULL), - }; + })); } -static void flash_file_wstat(struct flash_file *self, struct lib9p_srv_ctx *ctx, +static error flash_file_wstat(struct flash_file *self, struct lib9p_srv_ctx *ctx, struct lib9p_srv_stat) { assert(self); assert(ctx); - lib9p_error(&ctx->basectx, LIB9P_ERRNO_L_EROFS, "read-only part of filesystem"); + return error_new(E_POSIX_EROFS, "read-only part of filesystem"); } -static void flash_file_remove(struct flash_file *self, struct lib9p_srv_ctx *ctx) { +static error flash_file_remove(struct flash_file *self, struct lib9p_srv_ctx *ctx) { assert(self); assert(ctx); - lib9p_error(&ctx->basectx, LIB9P_ERRNO_L_EROFS, "read-only part of filesystem"); + return error_new(E_POSIX_EROFS, "read-only part of filesystem"); } LIB9P_SRV_NOTDIR(struct flash_file, flash_file); -static lo_interface lib9p_srv_fio flash_file_fopen(struct flash_file *self, struct lib9p_srv_ctx *ctx, +static lib9p_srv_fio_or_error flash_file_fopen(struct flash_file *self, struct lib9p_srv_ctx *ctx, bool rd, bool wr, bool trunc) { assert(self); assert(ctx); @@ -201,7 +201,7 @@ static lo_interface lib9p_srv_fio flash_file_fopen(struct flash_file *self, stru self->wbuf.ok = false; } - return lo_box_flash_file_as_lib9p_srv_fio(self); + return ERROR_NEW_VAL(lib9p_srv_fio, LO_BOX(lib9p_srv_fio, self)); } /* srv_fio ********************************************************************/ @@ -221,18 +221,13 @@ static void flash_file_iofree(struct flash_file *self) { ab_flash_finalize(self->wbuf.dat); } -static void flash_file_pread(struct flash_file *self, struct lib9p_srv_ctx *ctx, - uint32_t byte_count, uint64_t byte_offset, - struct iovec *ret) { +static iovec_or_error flash_file_pread(struct flash_file *self, struct lib9p_srv_ctx *ctx, + uint32_t byte_count, uint64_t byte_offset) { assert(self); assert(ctx); - assert(ret); - if (byte_offset > DATA_SIZE) { - lib9p_error(&ctx->basectx, - LIB9P_ERRNO_L_EINVAL, "offset is past the chip size"); - return; - } + if (byte_offset > DATA_SIZE) + return ERROR_NEW_ERR(iovec, error_new(E_POSIX_EINVAL, "offset is past the chip size")); /* Assume that somewhere down the line the iovec we return * will be passed to DMA. We don't want the DMA engine to hit @@ -241,12 +236,10 @@ static void flash_file_pread(struct flash_file *self, struct lib9p_srv_ctx *ctx, * data to a buffer in (fast) RAM first. It's lame that the * DMA engine can only have a DREQ on one side of the channel. */ - if (byte_offset == DATA_SIZE) { - *ret = (struct iovec){ + if (byte_offset == DATA_SIZE) + return ERROR_NEW_VAL(iovec, ((struct iovec){ .iov_len = 0, - }; - return; - } + })); size_t sector_base = LM_ROUND_DOWN(byte_offset, FLASH_SECTOR_SIZE); if (byte_offset + byte_count > sector_base + FLASH_SECTOR_SIZE) byte_count = (sector_base + FLASH_SECTOR_SIZE) - byte_offset; @@ -258,34 +251,28 @@ static void flash_file_pread(struct flash_file *self, struct lib9p_srv_ctx *ctx, memcpy(self->rbuf.dat, DATA_START+sector_base, FLASH_SECTOR_SIZE); } - *ret = (struct iovec){ + return ERROR_NEW_VAL(iovec, ((struct iovec){ .iov_base = &self->rbuf.dat[byte_offset-sector_base], .iov_len = byte_count, - }; + })); } /* TODO: Short/corrupt writes are dangerous. This should either (1) * check a checksum, (2) use uf2 instead of verbatim data, or (3) use * ihex instead of verbatim data. */ -static uint32_t flash_file_pwrite(struct flash_file *self, struct lib9p_srv_ctx *ctx, - void *buf, - uint32_t byte_count, - uint64_t byte_offset) { +static uint32_t_or_error flash_file_pwrite(struct flash_file *self, struct lib9p_srv_ctx *ctx, + void *buf, + uint32_t byte_count, + uint64_t byte_offset) { assert(self); assert(ctx); - if (byte_offset > DATA_HSIZE) { - lib9p_error(&ctx->basectx, - LIB9P_ERRNO_L_EINVAL, "offset is past half the chip size"); - return 0; - } + if (byte_offset > DATA_HSIZE) + return ERROR_NEW_ERR(uint32_t, error_new(E_POSIX_EINVAL, "offset is past half the chip size")); if (byte_count == 0) - return 0; - if (byte_offset == DATA_HSIZE) { - lib9p_error(&ctx->basectx, - LIB9P_ERRNO_L_EINVAL, "offset is at half the chip size"); - return 0; - } + return ERROR_NEW_VAL(uint32_t, 0); + if (byte_offset == DATA_HSIZE) + return ERROR_NEW_ERR(uint32_t, error_new(E_POSIX_EINVAL, "offset is at half the chip size")); size_t sector_base = LM_ROUND_DOWN(byte_offset, FLASH_SECTOR_SIZE); if (byte_offset + byte_count > sector_base + FLASH_SECTOR_SIZE) @@ -303,5 +290,5 @@ static uint32_t flash_file_pwrite(struct flash_file *self, struct lib9p_srv_ctx memcpy(&self->wbuf.dat[byte_offset-sector_base], buf, byte_count); self->written = true; - return byte_count; + return ERROR_NEW_VAL(uint32_t, byte_count); } diff --git a/cmd/sbc_harness/fs_harness_flash_bin.h b/cmd/sbc_harness/fs_harness_flash_bin.h index 36382be..148a446 100644 --- a/cmd/sbc_harness/fs_harness_flash_bin.h +++ b/cmd/sbc_harness/fs_harness_flash_bin.h @@ -25,6 +25,5 @@ struct flash_file { END_PRIVATE(FS_HARNESS_FLASH_BIN); }; LO_IMPLEMENTATION_H(lib9p_srv_file, struct flash_file, flash_file); -#define lo_box_flash_file_as_lib9p_srv_file(obj) util9p_box(flash_file, obj) #endif /* _SBC_HARNESS_FS_HARNESS_FLASH_BIN_H_ */ diff --git a/cmd/sbc_harness/fs_harness_uptime_txt.c b/cmd/sbc_harness/fs_harness_uptime_txt.c index 339b410..021a8bd 100644 --- a/cmd/sbc_harness/fs_harness_uptime_txt.c +++ b/cmd/sbc_harness/fs_harness_uptime_txt.c @@ -37,7 +37,7 @@ static struct lib9p_qid uptime_file_qid(struct uptime_file *self) { }; } -static struct lib9p_srv_stat uptime_file_stat(struct uptime_file *self, struct lib9p_srv_ctx *ctx) { +static lib9p_srv_stat_or_error uptime_file_stat(struct uptime_file *self, struct lib9p_srv_ctx *ctx) { assert(self); assert(ctx); @@ -51,7 +51,7 @@ static struct lib9p_srv_stat uptime_file_stat(struct uptime_file *self, struct l size++; size += 3; - return (struct lib9p_srv_stat){ + return ERROR_NEW_VAL(lib9p_srv_stat, ((struct lib9p_srv_stat){ .qid = uptime_file_qid(self), .mode = 0444, .atime_sec = UTIL9P_ATIME, @@ -62,26 +62,26 @@ static struct lib9p_srv_stat uptime_file_stat(struct uptime_file *self, struct l .owner_gid = { .name = lib9p_str("root"), .num = 0 }, .last_modifier_uid = { .name = lib9p_str("root"), .num = 0 }, .extension = lib9p_str(NULL), - }; + })); } -static void uptime_file_wstat(struct uptime_file *self, struct lib9p_srv_ctx *ctx, - struct lib9p_srv_stat) { +static error uptime_file_wstat(struct uptime_file *self, struct lib9p_srv_ctx *ctx, + struct lib9p_srv_stat) { assert(self); assert(ctx); - lib9p_error(&ctx->basectx, LIB9P_ERRNO_L_EROFS, "read-only part of filesystem"); + return error_new(E_POSIX_EROFS, "read-only part of filesystem"); } -static void uptime_file_remove(struct uptime_file *self, struct lib9p_srv_ctx *ctx) { +static error uptime_file_remove(struct uptime_file *self, struct lib9p_srv_ctx *ctx) { assert(self); assert(ctx); - lib9p_error(&ctx->basectx, LIB9P_ERRNO_L_EROFS, "read-only part of filesystem"); + return error_new(E_POSIX_EROFS, "read-only part of filesystem"); } LIB9P_SRV_NOTDIR(struct uptime_file, uptime_file); -static lo_interface lib9p_srv_fio uptime_file_fopen(struct uptime_file *self, struct lib9p_srv_ctx *ctx, - bool LM_UNUSED(rd), bool LM_UNUSED(wr), bool LM_UNUSED(trunc)) { +static lib9p_srv_fio_or_error uptime_file_fopen(struct uptime_file *self, struct lib9p_srv_ctx *ctx, + bool LM_UNUSED(rd), bool LM_UNUSED(wr), bool LM_UNUSED(trunc)) { assert(self); assert(ctx); @@ -89,7 +89,7 @@ static lo_interface lib9p_srv_fio uptime_file_fopen(struct uptime_file *self, st ret->parent = self; ret->buf_len = 0; - return lo_box_uptime_fio_as_lib9p_srv_fio(ret); + return ERROR_NEW_VAL(lib9p_srv_fio, LO_BOX(lib9p_srv_fio, ret)); } /* srv_fio ********************************************************************/ @@ -110,41 +110,35 @@ static struct lib9p_qid uptime_fio_qid(struct uptime_fio *self) { return uptime_file_qid(self->parent); } -static void uptime_fio_pread(struct uptime_fio *self, struct lib9p_srv_ctx *ctx, - uint32_t byte_count, uint64_t byte_offset, - struct iovec *ret) { +static iovec_or_error uptime_fio_pread(struct uptime_fio *self, struct lib9p_srv_ctx *ctx, + uint32_t byte_count, uint64_t byte_offset) { assert(self); assert(ctx); - assert(ret); if (byte_offset == 0 || self->buf_len == 0) { uint64_t now = LO_CALL(bootclock, get_time_ns); self->buf_len = fmt_snprint(self->buf, sizeof(self->buf), now, "ns\n"); } - if (byte_offset > (uint64_t)self->buf_len) { - lib9p_error(&ctx->basectx, - LIB9P_ERRNO_L_EINVAL, "offset is past end-of-file length"); - return; - } + if (byte_offset > (uint64_t)self->buf_len) + return ERROR_NEW_ERR(iovec, error_new(E_POSIX_EINVAL, "offset is past end-of-file length")); size_t beg_off = (size_t)byte_offset; size_t end_off = beg_off + (size_t)byte_count; if (end_off > self->buf_len) end_off = self->buf_len; - *ret = (struct iovec){ + return ERROR_NEW_VAL(iovec, ((struct iovec){ .iov_base = &self->buf[beg_off], .iov_len = end_off-beg_off, - }; + })); } -static uint32_t uptime_fio_pwrite(struct uptime_fio *self, struct lib9p_srv_ctx *ctx, +static uint32_t_or_error uptime_fio_pwrite(struct uptime_fio *self, struct lib9p_srv_ctx *ctx, void *LM_UNUSED(buf), uint32_t LM_UNUSED(byte_count), uint64_t LM_UNUSED(byte_offset)) { assert(self); assert(ctx); - lib9p_error(&ctx->basectx, LIB9P_ERRNO_L_EROFS, "read-only part of filesystem"); - return 0; + return ERROR_NEW_ERR(uint32_t, error_new(E_POSIX_EROFS, "read-only part of filesystem")); } diff --git a/cmd/sbc_harness/fs_harness_uptime_txt.h b/cmd/sbc_harness/fs_harness_uptime_txt.h index 7bf2945..c575580 100644 --- a/cmd/sbc_harness/fs_harness_uptime_txt.h +++ b/cmd/sbc_harness/fs_harness_uptime_txt.h @@ -14,6 +14,5 @@ struct uptime_file { uint64_t pathnum; }; LO_IMPLEMENTATION_H(lib9p_srv_file, struct uptime_file, uptime_file); -#define lo_box_uptime_file_as_lib9p_srv_file(obj) util9p_box(uptime_file, obj) #endif /* _SBC_HARNESS_FS_HARNESS_UPTIME_TXT_H_ */ diff --git a/cmd/sbc_harness/main.c b/cmd/sbc_harness/main.c index 71c39b2..82519ae 100644 --- a/cmd/sbc_harness/main.c +++ b/cmd/sbc_harness/main.c @@ -54,11 +54,11 @@ enum { PATH_BASE = __COUNTER__ }; #define STATIC_FILE(STRNAME, ...) UTIL9P_STATIC_FILE(PATH_COUNTER, STRNAME, __VA_ARGS__) #define STATIC_DIR(STRNAME, ...) UTIL9P_STATIC_DIR(PATH_COUNTER, STRNAME, __VA_ARGS__) -#define API_FILE(STRNAME, SYMNAME, ...) \ - lo_box_##SYMNAME##_file_as_lib9p_srv_file(&((struct SYMNAME##_file){ \ - .name = STRNAME, \ - .pathnum = PATH_COUNTER \ - __VA_OPT__(,) __VA_ARGS__ \ +#define API_FILE(STRNAME, SYMNAME, ...) \ + LO_BOX(lib9p_srv_file, &((struct SYMNAME##_file){ \ + .name = STRNAME, \ + .pathnum = PATH_COUNTER \ + __VA_OPT__(,) __VA_ARGS__ \ })) static struct lib9p_srv_file root = @@ -114,8 +114,8 @@ static struct lib9p_srv_file root = ), ); -static lo_interface lib9p_srv_file get_root(struct lib9p_srv_ctx *LM_UNUSED(ctx), struct lib9p_s LM_UNUSED(treename)) { - return root; +static lib9p_srv_file_or_error get_root(struct lib9p_srv_ctx *LM_UNUSED(ctx), struct lib9p_s LM_UNUSED(treename)) { + return ERROR_NEW_VAL(lib9p_srv_file, root); } /* Code ***********************************************************************/ @@ -149,7 +149,7 @@ struct { static COROUTINE dhcp_cr(void *) { cr_begin(); - dhcp_client_main(lo_box_w5500_if_as_net_iface(&globals.dev_w5500), "harness"); + dhcp_client_main(LO_BOX(net_iface, &globals.dev_w5500), "harness"); cr_end(); } @@ -157,7 +157,7 @@ static COROUTINE dhcp_cr(void *) { static COROUTINE read9p_cr(void *) { cr_begin(); - lo_interface net_iface iface = lo_box_w5500_if_as_net_iface(&globals.dev_w5500); + lo_interface net_iface iface = LO_BOX(net_iface, &globals.dev_w5500); lo_interface net_stream_listener listener = LO_CALL(iface, tcp_listen, LIB9P_DEFAULT_PORT_9FS); lib9p_srv_accept_and_read_loop(&globals.srv, listener); @@ -204,7 +204,7 @@ COROUTINE init_cr(void *) { 17, /* PIN_CS */ 0, 1, 2, 3); /* DMA channels */ w5500_init(&globals.dev_w5500, "W5500", - lo_box_rp2040_hwspi_as_spi(&globals.dev_spi), + LO_BOX(spi, &globals.dev_spi), 21, /* PIN_INTR */ 20, /* PIN_RESET */ ((struct net_eth_addr){{ |