dmesg logging
This commit is contained in:
parent
d2f6395443
commit
9a3eec7d4d
@ -1,7 +1,8 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
set -ex
|
set -ex
|
||||||
|
echo Y > /sys/module/printk/parameters/time
|
||||||
cd /mnt/ramdisk/prjs/ko
|
cd /mnt/ramdisk/prjs/ko
|
||||||
echo 3 > /proc/sys/kernel/printk
|
#echo 3 > /proc/sys/kernel/printk
|
||||||
insmod ./nbd.ko
|
insmod ./nbd.ko
|
||||||
sleep 1
|
sleep 1
|
||||||
./uf2d > /tmp/uf2d.log 2> /tmp/uf2derr.log
|
./uf2d > /tmp/uf2d.log 2> /tmp/uf2derr.log
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <sys/wait.h>
|
#include <sys/wait.h>
|
||||||
|
#include <stdarg.h>
|
||||||
|
|
||||||
#include "uf2.h"
|
#include "uf2.h"
|
||||||
|
|
||||||
@ -26,6 +27,27 @@ uint64_t ntohll(uint64_t a) {
|
|||||||
}
|
}
|
||||||
#define htonll ntohll
|
#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) {
|
void readAll(int fd, void *dst, uint32_t length) {
|
||||||
while (length) {
|
while (length) {
|
||||||
int curr = read(fd, dst, length);
|
int curr = read(fd, dst, length);
|
||||||
@ -71,7 +93,7 @@ void startclient() {
|
|||||||
|
|
||||||
void handleread(int off, int len) {
|
void handleread(int off, int len) {
|
||||||
uint8_t buf[512];
|
uint8_t buf[512];
|
||||||
//LOG("read @%d len=%d", off, len);
|
// LOG("read @%d len=%d", off, len);
|
||||||
reply.error = 0; // htonl(EPERM);
|
reply.error = 0; // htonl(EPERM);
|
||||||
writeAll(sock, &reply, sizeof(struct nbd_reply));
|
writeAll(sock, &reply, sizeof(struct nbd_reply));
|
||||||
for (int i = 0; i < len; ++i) {
|
for (int i = 0; i < len; ++i) {
|
||||||
@ -82,7 +104,7 @@ void handleread(int off, int len) {
|
|||||||
|
|
||||||
void handlewrite(int off, int len) {
|
void handlewrite(int off, int len) {
|
||||||
uint8_t buf[512];
|
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) {
|
for (int i = 0; i < len; ++i) {
|
||||||
readAll(sock, buf, 512);
|
readAll(sock, buf, 512);
|
||||||
write_block(off + i, buf);
|
write_block(off + i, buf);
|
||||||
@ -121,7 +143,7 @@ void runNBD() {
|
|||||||
reply.error = htonl(0);
|
reply.error = htonl(0);
|
||||||
|
|
||||||
for (;;) {
|
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));
|
int nread = read(sock, &request, sizeof(request));
|
||||||
|
|
||||||
if (nread < 0) {
|
if (nread < 0) {
|
||||||
|
@ -25,8 +25,7 @@ void write_block(uint32_t block_no, uint8_t *data);
|
|||||||
|
|
||||||
#define CONCAT_1(a, b) a##b
|
#define CONCAT_1(a, b) a##b
|
||||||
#define CONCAT_0(a, b) CONCAT_1(a, b)
|
#define CONCAT_0(a, b) CONCAT_1(a, b)
|
||||||
#define STATIC_ASSERT(e) \
|
#define STATIC_ASSERT(e) enum { CONCAT_0(_static_assert_, __LINE__) = 1 / ((e) ? 1 : 0) }
|
||||||
enum { CONCAT_0(_static_assert_, __LINE__) = 1 / ((e) ? 1 : 0) }
|
|
||||||
|
|
||||||
extern const char infoUf2File[];
|
extern const char infoUf2File[];
|
||||||
|
|
||||||
@ -34,20 +33,14 @@ void readAll(int fd, void *dst, uint32_t length);
|
|||||||
|
|
||||||
STATIC_ASSERT(sizeof(UF2_Block) == 512);
|
STATIC_ASSERT(sizeof(UF2_Block) == 512);
|
||||||
|
|
||||||
|
void mylog(const char *fmt, ...);
|
||||||
|
|
||||||
#define FAIL(args...) \
|
#define FAIL(args...) \
|
||||||
do { \
|
do { \
|
||||||
fprintf(stderr, args); \
|
mylog(args); \
|
||||||
fprintf(stderr, "\n"); \
|
|
||||||
exit(1); \
|
exit(1); \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
#define LOG(args...) \
|
#define LOG mylog
|
||||||
do { \
|
|
||||||
fprintf(stderr, args); \
|
|
||||||
fprintf(stderr, "\n"); \
|
|
||||||
fflush(stderr); \
|
|
||||||
} while (0)
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user