dmesg logging

This commit is contained in:
Michal Moskal 2017-07-25 19:09:32 +01:00
parent d2f6395443
commit 9a3eec7d4d
3 changed files with 31 additions and 15 deletions

View File

@ -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

View File

@ -16,6 +16,7 @@
#include <sys/stat.h>
#include <unistd.h>
#include <sys/wait.h>
#include <stdarg.h>
#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) {

View File

@ -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