From 9a3eec7d4d7fbf7f6983facc66af03f568007df1 Mon Sep 17 00:00:00 2001 From: Michal Moskal Date: Tue, 25 Jul 2017 19:09:32 +0100 Subject: [PATCH] dmesg logging --- brick/ins | 3 ++- brick/uf2daemon/main.c | 28 +++++++++++++++++++++++++--- brick/uf2daemon/uf2.h | 15 ++++----------- 3 files changed, 31 insertions(+), 15 deletions(-) diff --git a/brick/ins b/brick/ins index abeb7604..5d4370b2 100755 --- a/brick/ins +++ b/brick/ins @@ -1,7 +1,8 @@ #!/bin/sh set -ex +echo Y > /sys/module/printk/parameters/time cd /mnt/ramdisk/prjs/ko -echo 3 > /proc/sys/kernel/printk +#echo 3 > /proc/sys/kernel/printk insmod ./nbd.ko sleep 1 ./uf2d > /tmp/uf2d.log 2> /tmp/uf2derr.log diff --git a/brick/uf2daemon/main.c b/brick/uf2daemon/main.c index 0910baf0..b207827e 100644 --- a/brick/uf2daemon/main.c +++ b/brick/uf2daemon/main.c @@ -16,6 +16,7 @@ #include #include #include +#include #include "uf2.h" @@ -26,6 +27,27 @@ uint64_t ntohll(uint64_t a) { } #define htonll ntohll +void mylog(const char *fmt, ...) { + va_list args; + char *p; + + va_start(args, fmt); + vasprintf(&p, fmt, args); + vprintf(fmt, args); + va_end(args); + + int len = strlen(p) + 1; + p[len - 1] = '\n'; + +#ifdef X86 + write(2, p, len); +#else + int fd = open("/dev/kmsg", O_WRONLY); + write(fd, p, len); + close(fd); +#endif +} + void readAll(int fd, void *dst, uint32_t length) { while (length) { int curr = read(fd, dst, length); @@ -71,7 +93,7 @@ void startclient() { void handleread(int off, int len) { uint8_t buf[512]; - //LOG("read @%d len=%d", off, len); + // LOG("read @%d len=%d", off, len); reply.error = 0; // htonl(EPERM); writeAll(sock, &reply, sizeof(struct nbd_reply)); for (int i = 0; i < len; ++i) { @@ -82,7 +104,7 @@ void handleread(int off, int len) { void handlewrite(int off, int len) { uint8_t buf[512]; - //LOG("write @%d len=%d", off, len); + // LOG("write @%d len=%d", off, len); for (int i = 0; i < len; ++i) { readAll(sock, buf, 512); write_block(off + i, buf); @@ -121,7 +143,7 @@ void runNBD() { reply.error = htonl(0); for (;;) { - //nbd_ioctl(BLKFLSBUF, 0); // flush buffers - we don't want the kernel to cache the writes + // nbd_ioctl(BLKFLSBUF, 0); // flush buffers - we don't want the kernel to cache the writes int nread = read(sock, &request, sizeof(request)); if (nread < 0) { diff --git a/brick/uf2daemon/uf2.h b/brick/uf2daemon/uf2.h index 168ce081..25431c38 100644 --- a/brick/uf2daemon/uf2.h +++ b/brick/uf2daemon/uf2.h @@ -25,8 +25,7 @@ void write_block(uint32_t block_no, uint8_t *data); #define CONCAT_1(a, b) a##b #define CONCAT_0(a, b) CONCAT_1(a, b) -#define STATIC_ASSERT(e) \ - enum { CONCAT_0(_static_assert_, __LINE__) = 1 / ((e) ? 1 : 0) } +#define STATIC_ASSERT(e) enum { CONCAT_0(_static_assert_, __LINE__) = 1 / ((e) ? 1 : 0) } extern const char infoUf2File[]; @@ -34,20 +33,14 @@ void readAll(int fd, void *dst, uint32_t length); STATIC_ASSERT(sizeof(UF2_Block) == 512); +void mylog(const char *fmt, ...); #define FAIL(args...) \ do { \ - fprintf(stderr, args); \ - fprintf(stderr, "\n"); \ + mylog(args); \ exit(1); \ } while (0) -#define LOG(args...) \ - do { \ - fprintf(stderr, args); \ - fprintf(stderr, "\n"); \ - fflush(stderr); \ - } while (0) - +#define LOG mylog #endif