Compare commits

..

13 Commits

Author SHA1 Message Date
4c45ab8701 Add more debug 2017-07-26 16:17:59 +01:00
f4c9e85924 Bring back read page alignmnet 2017-07-26 11:52:51 +01:00
33863b8b96 Fix warning 2017-07-26 11:38:31 +01:00
b167d4f9df Apply a283c03a3a 2017-07-26 11:36:52 +01:00
f00b4d432e Apply b894f60a23 2017-07-26 11:36:26 +01:00
f361b6ecc1 Apply e5fd39d9b8 2017-07-26 11:32:49 +01:00
b46e18b807 Apply aae86e8adb 2017-07-26 11:27:15 +01:00
067f8727a6 Apply b00ce11f00 2017-07-26 11:27:01 +01:00
52ef98e249 Add more logging 2017-07-26 10:43:43 +01:00
9a3eec7d4d dmesg logging 2017-07-25 19:09:32 +01:00
d2f6395443 Cleanup logging; remove excessive flush 2017-07-25 18:37:52 +01:00
7960c9f15e Logging fixes 2017-07-25 15:28:28 +01:00
d84b2b187c Remove unnecessary changes; trim down logging 2017-07-25 15:10:06 +01:00
10 changed files with 289 additions and 162 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

@ -38,6 +38,13 @@
// Keep Eclipse happy
#endif
#if 1
#undef dev_vdbg
#undef dev_dbg
#define dev_vdbg(d, args...) printk(args)
#define dev_dbg(d, args...) printk(args)
#endif
/* big enough to hold our biggest descriptor */
#define USB_BUFSIZ 1024
@ -867,6 +874,12 @@ composite_setup(struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
req->length = USB_BUFSIZ;
gadget->ep0->driver_data = cdev;
VDBG(cdev,
"setup req %02x.%02x v%04x i%04x l%d\n",
ctrl->bRequestType, ctrl->bRequest,
w_value, w_index, w_length);
switch (ctrl->bRequest) {
/* we handle all standard USB descriptors */
case USB_REQ_GET_DESCRIPTOR:

View File

@ -40,8 +40,8 @@
#include <asm/types.h>
#endif
#include "../../lms2012/source/lms2012.h"
#include "../../lms2012/source/am1808.h"
#include "source/lms2012.h"
#include "source/am1808.h"
#define MODULE_NAME "usbdev_module"
@ -80,12 +80,15 @@ static void ModuleExit(void);
#include <linux/utsname.h>
#include <linux/device.h>
static struct fsg_common *fsg_common;
#include "computil.c" // The composite framework used as utility file
#include <../drivers/usb/gadget/gadget_chips.h>
#include <../drivers/usb/gadget/usbstring.c>
#include <../drivers/usb/gadget/config.c>
#include <../drivers/usb/gadget/epautoconf.c>
#include "f_mass_storage.c"
/*-------------------------------------------------------------------------*/
@ -170,9 +173,10 @@ static struct usb_device_descriptor device_desc = {
.bDescriptorType = USB_DT_DEVICE,
.bcdUSB = cpu_to_le16(0x0200),
.bDeviceClass = 0,
.bDeviceSubClass = 0,
.bDeviceProtocol = 0,
.bDeviceClass = 0xEF,
.bDeviceSubClass = 2,
.bDeviceProtocol = 1,
/*.bMaxPacketSize0 = f(hardware) */
.idVendor = cpu_to_le16(DRIVER_VENDOR_NUM),
.idProduct = cpu_to_le16(DRIVER_PRODUCT_NUM),
@ -330,6 +334,9 @@ static void zero_resume(struct usb_composite_dev *cdev)
/*-------------------------------------------------------------------------*/
static int msg_bind(struct usb_composite_dev *cdev);
static void msg_bind2(struct usb_composite_dev *cdev);
static int zero_bind(struct usb_composite_dev *cdev)
{
int gcnum;
@ -362,6 +369,10 @@ static int zero_bind(struct usb_composite_dev *cdev)
strings_dev[STRING_SERIAL_IDX].id = id;
device_desc.iSerialNumber = id;
id = msg_bind(cdev);
if (id < 0)
return id;
setup_timer(&autoresume_timer, zero_autoresume, (unsigned long) cdev);
rudolf_add(cdev, autoresume != 0);
@ -381,6 +392,9 @@ static int zero_bind(struct usb_composite_dev *cdev)
longname, gadget->name);
device_desc.bcdDevice = cpu_to_le16(0x9999);
}
msg_bind2(cdev);
return 0;
}
@ -696,3 +710,38 @@ static void ModuleExit(void)
}
// MSG
/****************************** Configurations ******************************/
static struct fsg_module_parameters fsg_mod_data = {
.stall = 1
};
FSG_MODULE_PARAMETERS(/* no prefix */, fsg_mod_data);
/****************************** Gadget Bind ******************************/
static void msg_bind2(struct usb_composite_dev *cdev)
{
fsg_common_put(fsg_common);
}
static int msg_bind(struct usb_composite_dev *cdev)
{
/* set up mass storage function */
fsg_common = fsg_common_from_params(0, cdev, &fsg_mod_data);
if (IS_ERR(fsg_common)) {
return PTR_ERR(fsg_common);
}
return 0;
}
static int msg_config(struct usb_configuration *c) {
return fsg_add(c->cdev, c, fsg_common);
}

View File

@ -288,6 +288,7 @@
#include <linux/usb/ch9.h>
#include <linux/usb/gadget.h>
#include <linux/usb/composite.h>
#include "gadget_chips.h"
@ -302,7 +303,6 @@ static const char fsg_string_interface[] = "Mass Storage";
#define FSG_NO_INTR_EP 1
#define FSG_BUFFHD_STATIC_BUFFER 1
#define FSG_NO_DEVICE_STRINGS 1
#define FSG_NO_OTG 1
#define FSG_NO_INTR_EP 1
@ -318,8 +318,8 @@ struct fsg_dev;
/* Data shared by all the FSG instances. */
struct fsg_common {
struct usb_gadget *gadget;
struct fsg_dev *fsg;
struct fsg_dev *prev_fsg;
struct fsg_dev *fsg, *new_fsg;
wait_queue_head_t fsg_wait;
/* filesem protects: backing files in use */
struct rw_semaphore filesem;
@ -348,7 +348,6 @@ struct fsg_common {
enum fsg_state state; /* For exception handling */
unsigned int exception_req_tag;
u8 config, new_config;
enum data_direction data_dir;
u32 data_size;
u32 data_size_from_cmnd;
@ -588,7 +587,7 @@ static int fsg_setup(struct usb_function *f,
u16 w_value = le16_to_cpu(ctrl->wValue);
u16 w_length = le16_to_cpu(ctrl->wLength);
if (!fsg->common->config)
if (!fsg_is_set(fsg->common))
return -EOPNOTSUPP;
switch (ctrl->bRequest) {
@ -614,7 +613,12 @@ static int fsg_setup(struct usb_function *f,
return -EDOM;
VDBG(fsg, "get max LUN\n");
*(u8 *) req->buf = fsg->common->nluns - 1;
return 1;
/* Respond with data/status */
req->length = min((u16)1, w_length);
fsg->common->ep0req_name =
ctrl->bRequestType & USB_DIR_IN ? "ep0-in" : "ep0-out";
return ep0_queue(fsg->common);
}
VDBG(fsg,
@ -731,6 +735,9 @@ static int do_read(struct fsg_common *common)
/* Carry out the file reads */
amount_left = common->data_size_from_cmnd;
LDBG(curlun, "Uread off=%d cnt=%d\n", (int)lba, amount_left);
if (unlikely(amount_left == 0))
return -EIO; /* No default reply */
@ -751,7 +758,6 @@ static int do_read(struct fsg_common *common)
if (partial_page > 0)
amount = min(amount, (unsigned int) PAGE_CACHE_SIZE -
partial_page);
/* Wait for the next buffer to become available */
bh = common->next_buffhd_to_fill;
while (bh->state != BUF_STATE_EMPTY) {
@ -843,7 +849,7 @@ static int do_write(struct fsg_common *common)
return -EINVAL;
}
spin_lock(&curlun->filp->f_lock);
curlun->filp->f_flags &= ~O_SYNC; /* Default is not to wait */
curlun->filp->f_flags |= O_SYNC; /* Default is to wait */
spin_unlock(&curlun->filp->f_lock);
/* Get the starting Logical Block Address and check that it's
@ -878,6 +884,8 @@ static int do_write(struct fsg_common *common)
amount_left_to_req = common->data_size_from_cmnd;
amount_left_to_write = common->data_size_from_cmnd;
LDBG(curlun, "Uwrite off=%d cnt=%d\n", (int)lba, amount_left_to_req);
while (amount_left_to_write > 0) {
/* Queue a request for more data from the host */
@ -930,6 +938,7 @@ static int do_write(struct fsg_common *common)
bh->outreq->length = amount;
bh->bulk_out_intended_length = amount;
bh->outreq->short_not_ok = 1;
printk("write transfer %d\n", amount);
START_TRANSFER_OR(common, bulk_out, bh->outreq,
&bh->outreq_busy, &bh->state)
/* Don't know what to do if
@ -1006,10 +1015,14 @@ static int do_write(struct fsg_common *common)
continue;
}
printk("before sleep\n");
/* Wait for something to happen */
rc = sleep_thread(common);
if (rc)
return rc;
printk("after sleep\n");
}
return -EIO; /* No default reply */
@ -2253,24 +2266,20 @@ static int alloc_request(struct fsg_common *common, struct usb_ep *ep,
return -ENOMEM;
}
/*
* Reset interface setting and re-init endpoint state (toggle etc).
* Call with altsetting < 0 to disable the interface. The only other
* available altsetting is 0, which enables the interface.
*/
static int do_set_interface(struct fsg_common *common, int altsetting)
/* Reset interface setting and re-init endpoint state (toggle etc). */
static int do_set_interface(struct fsg_common *common, struct fsg_dev *new_fsg)
{
int rc = 0;
int i;
const struct usb_endpoint_descriptor *d;
const struct usb_endpoint_descriptor *d;
struct fsg_dev *fsg;
int i, rc = 0;
if (common->running)
DBG(common, "reset interface\n");
reset:
/* Deallocate the requests */
if (common->prev_fsg) {
struct fsg_dev *fsg = common->prev_fsg;
if (common->fsg) {
fsg = common->fsg;
for (i = 0; i < FSG_NUM_BUFFERS; ++i) {
struct fsg_buffhd *bh = &common->buffhds[i];
@ -2295,88 +2304,53 @@ reset:
fsg->bulk_out_enabled = 0;
}
common->prev_fsg = 0;
common->fsg = NULL;
wake_up(&common->fsg_wait);
}
common->running = 0;
if (altsetting < 0 || rc != 0)
if (!new_fsg || rc)
return rc;
DBG(common, "set interface %d\n", altsetting);
common->fsg = new_fsg;
fsg = common->fsg;
if (fsg_is_set(common)) {
struct fsg_dev *fsg = common->fsg;
common->prev_fsg = common->fsg;
/* Enable the endpoints */
d = fsg_ep_desc(common->gadget,
&fsg_fs_bulk_in_desc, &fsg_hs_bulk_in_desc);
rc = enable_endpoint(common, fsg->bulk_in, d);
if (rc)
goto reset;
fsg->bulk_in_enabled = 1;
/* Enable the endpoints */
d = fsg_ep_desc(common->gadget,
&fsg_fs_bulk_in_desc, &fsg_hs_bulk_in_desc);
rc = enable_endpoint(common, fsg->bulk_in, d);
d = fsg_ep_desc(common->gadget,
&fsg_fs_bulk_out_desc, &fsg_hs_bulk_out_desc);
rc = enable_endpoint(common, fsg->bulk_out, d);
if (rc)
goto reset;
fsg->bulk_out_enabled = 1;
common->bulk_out_maxpacket = le16_to_cpu(d->wMaxPacketSize);
clear_bit(IGNORE_BULK_OUT, &fsg->atomic_bitflags);
/* Allocate the requests */
for (i = 0; i < FSG_NUM_BUFFERS; ++i) {
struct fsg_buffhd *bh = &common->buffhds[i];
rc = alloc_request(common, fsg->bulk_in, &bh->inreq);
if (rc)
goto reset;
fsg->bulk_in_enabled = 1;
d = fsg_ep_desc(common->gadget,
&fsg_fs_bulk_out_desc, &fsg_hs_bulk_out_desc);
rc = enable_endpoint(common, fsg->bulk_out, d);
rc = alloc_request(common, fsg->bulk_out, &bh->outreq);
if (rc)
goto reset;
fsg->bulk_out_enabled = 1;
common->bulk_out_maxpacket = le16_to_cpu(d->wMaxPacketSize);
clear_bit(IGNORE_BULK_OUT, &fsg->atomic_bitflags);
/* Allocate the requests */
for (i = 0; i < FSG_NUM_BUFFERS; ++i) {
struct fsg_buffhd *bh = &common->buffhds[i];
rc = alloc_request(common, fsg->bulk_in, &bh->inreq);
if (rc)
goto reset;
rc = alloc_request(common, fsg->bulk_out, &bh->outreq);
if (rc)
goto reset;
bh->inreq->buf = bh->outreq->buf = bh->buf;
bh->inreq->context = bh->outreq->context = bh;
bh->inreq->complete = bulk_in_complete;
bh->outreq->complete = bulk_out_complete;
}
common->running = 1;
for (i = 0; i < common->nluns; ++i)
common->luns[i].unit_attention_data = SS_RESET_OCCURRED;
return rc;
} else {
return -EIO;
}
}
/*
* Change our operational configuration. This code must agree with the code
* that returns config descriptors, and with interface altsetting code.
*
* It's also responsible for power management interactions. Some
* configurations might not work with our current power sources.
* For now we just assume the gadget is always self-powered.
*/
static int do_set_config(struct fsg_common *common, u8 new_config)
{
int rc = 0;
/* Disable the single interface */
if (common->config != 0) {
DBG(common, "reset config\n");
common->config = 0;
rc = do_set_interface(common, -1);
bh->inreq->buf = bh->outreq->buf = bh->buf;
bh->inreq->context = bh->outreq->context = bh;
bh->inreq->complete = bulk_in_complete;
bh->outreq->complete = bulk_out_complete;
}
/* Enable the interface */
if (new_config != 0) {
common->config = new_config;
rc = do_set_interface(common, 0);
if (rc != 0)
common->config = 0; /* Reset on errors */
}
common->running = 1;
for (i = 0; i < common->nluns; ++i)
common->luns[i].unit_attention_data = SS_RESET_OCCURRED;
return rc;
}
@ -2387,9 +2361,7 @@ static int do_set_config(struct fsg_common *common, u8 new_config)
static int fsg_set_alt(struct usb_function *f, unsigned intf, unsigned alt)
{
struct fsg_dev *fsg = fsg_from_func(f);
fsg->common->prev_fsg = fsg->common->fsg;
fsg->common->fsg = fsg;
fsg->common->new_config = 1;
fsg->common->new_fsg = fsg;
raise_exception(fsg->common, FSG_STATE_CONFIG_CHANGE);
return 0;
}
@ -2397,9 +2369,7 @@ static int fsg_set_alt(struct usb_function *f, unsigned intf, unsigned alt)
static void fsg_disable(struct usb_function *f)
{
struct fsg_dev *fsg = fsg_from_func(f);
fsg->common->prev_fsg = fsg->common->fsg;
fsg->common->fsg = fsg;
fsg->common->new_config = 0;
fsg->common->new_fsg = NULL;
raise_exception(fsg->common, FSG_STATE_CONFIG_CHANGE);
}
@ -2409,19 +2379,17 @@ static void fsg_disable(struct usb_function *f)
static void handle_exception(struct fsg_common *common)
{
siginfo_t info;
int sig;
int i;
struct fsg_buffhd *bh;
enum fsg_state old_state;
u8 new_config;
struct fsg_lun *curlun;
unsigned int exception_req_tag;
int rc;
/* Clear the existing signals. Anything but SIGUSR1 is converted
* into a high-priority EXIT exception. */
for (;;) {
sig = dequeue_signal_lock(current, &current->blocked, &info);
int sig =
dequeue_signal_lock(current, &current->blocked, &info);
if (!sig)
break;
if (sig != SIGUSR1) {
@ -2432,7 +2400,7 @@ static void handle_exception(struct fsg_common *common)
}
/* Cancel all the pending transfers */
if (fsg_is_set(common)) {
if (likely(common->fsg)) {
for (i = 0; i < FSG_NUM_BUFFERS; ++i) {
bh = &common->buffhds[i];
if (bh->inreq_busy)
@ -2473,7 +2441,6 @@ static void handle_exception(struct fsg_common *common)
common->next_buffhd_to_fill = &common->buffhds[0];
common->next_buffhd_to_drain = &common->buffhds[0];
exception_req_tag = common->exception_req_tag;
new_config = common->new_config;
old_state = common->state;
if (old_state == FSG_STATE_ABORT_BULK_OUT)
@ -2523,20 +2490,12 @@ static void handle_exception(struct fsg_common *common)
break;
case FSG_STATE_CONFIG_CHANGE:
rc = do_set_config(common, new_config);
if (common->ep0_req_tag != exception_req_tag)
break;
if (rc != 0) { /* STALL on errors */
DBG(common, "ep0 set halt\n");
usb_ep_set_halt(common->ep0);
} else { /* Complete the status stage */
ep0_queue(common);
}
do_set_interface(common, common->new_fsg);
break;
case FSG_STATE_EXIT:
case FSG_STATE_TERMINATED:
do_set_config(common, 0); /* Free resources */
do_set_interface(common, NULL); /* Free resources */
spin_lock_irq(&common->lock);
common->state = FSG_STATE_TERMINATED; /* Stop the thread */
spin_unlock_irq(&common->lock);
@ -2629,6 +2588,41 @@ static int fsg_main_thread(void *common_)
static DEVICE_ATTR(ro, 0644, fsg_show_ro, fsg_store_ro);
static DEVICE_ATTR(file, 0644, fsg_show_file, fsg_store_file);
static struct fsg_dev *_fsg;
static int isActive(void) {
return _fsg->function.config->cdev->deactivations == 0 ? 1 : 0;
}
static ssize_t fsg_show_active(struct device *dev, struct device_attribute *attr,
char *buf)
{
return sprintf(buf, "%d\n", isActive());
}
static ssize_t fsg_store_active(struct device *dev, struct device_attribute *attr,
const char *buf, size_t count)
{
int i;
if (sscanf(buf, "%d", &i) != 1)
return -EINVAL;
if (isActive() != i) {
if (i == 0) {
usb_function_deactivate(&_fsg->function);
} else if (i == 1) {
usb_function_activate(&_fsg->function);
} else {
return -EINVAL;
}
}
return count;
}
static DEVICE_ATTR(active, 0644, fsg_show_active, fsg_store_active);
/****************************** FSG COMMON ******************************/
@ -2675,7 +2669,7 @@ static struct fsg_common *fsg_common_init(struct fsg_common *common,
return ERR_PTR(-ENOMEM);
common->free_storage_on_release = 1;
} else {
memset(common, 0, sizeof common);
memset(common, 0, sizeof *common);
common->free_storage_on_release = 0;
}
@ -2735,6 +2729,10 @@ static struct fsg_common *fsg_common_init(struct fsg_common *common,
if (rc)
goto error_luns;
rc = device_create_file(&curlun->dev, &dev_attr_active);
if (rc)
goto error_luns;
if (lcfg->filename) {
rc = fsg_lun_open(curlun, lcfg->filename);
if (rc)
@ -2749,13 +2747,19 @@ static struct fsg_common *fsg_common_init(struct fsg_common *common,
/* Data buffers cyclic list */
/* Buffers in buffhds are static -- no need for additional
* allocation. */
bh = common->buffhds;
i = FSG_NUM_BUFFERS - 1;
i = FSG_NUM_BUFFERS;
goto buffhds_first_it;
do {
bh->next = bh + 1;
} while (++bh, --i);
++bh;
buffhds_first_it:
bh->buf = kmalloc(FSG_BUFLEN, GFP_KERNEL);
if (unlikely(!bh->buf)) {
rc = -ENOMEM;
goto error_release;
}
} while (--i);
bh->next = common->buffhds;
@ -2809,6 +2813,7 @@ static struct fsg_common *fsg_common_init(struct fsg_common *common,
goto error_release;
}
init_completion(&common->thread_notifier);
init_waitqueue_head(&common->fsg_wait);
#undef OR
@ -2863,6 +2868,7 @@ static void fsg_common_release(struct kref *ref)
container_of(ref, struct fsg_common, ref);
unsigned i = common->nluns;
struct fsg_lun *lun = common->luns;
struct fsg_buffhd *bh;
/* If the thread isn't already dead, tell it to exit now */
if (common->state != FSG_STATE_TERMINATED) {
@ -2884,6 +2890,13 @@ static void fsg_common_release(struct kref *ref)
}
kfree(common->luns);
i = FSG_NUM_BUFFERS;
bh = common->buffhds;
do {
kfree(bh->buf);
} while (++bh, --i);
if (common->free_storage_on_release)
kfree(common);
}
@ -2895,9 +2908,19 @@ static void fsg_common_release(struct kref *ref)
static void fsg_unbind(struct usb_configuration *c, struct usb_function *f)
{
struct fsg_dev *fsg = fsg_from_func(f);
struct fsg_common *common = fsg->common;
DBG(fsg, "unbind\n");
fsg_common_put(fsg->common);
if (fsg->common->fsg == fsg) {
fsg->common->new_fsg = NULL;
raise_exception(fsg->common, FSG_STATE_CONFIG_CHANGE);
/* FIXME: make interruptible or killable somehow? */
wait_event(common->fsg_wait, common->fsg != fsg);
}
fsg_common_put(common);
kfree(fsg);
}
@ -2906,7 +2929,6 @@ static int fsg_bind(struct usb_configuration *c, struct usb_function *f)
{
struct fsg_dev *fsg = fsg_from_func(f);
struct usb_gadget *gadget = c->cdev->gadget;
int rc;
int i;
struct usb_ep *ep;
@ -2932,6 +2954,13 @@ static int fsg_bind(struct usb_configuration *c, struct usb_function *f)
ep->driver_data = fsg->common; /* claim the endpoint */
fsg->bulk_out = ep;
/* Copy descriptors */
f->descriptors = usb_copy_descriptors(fsg_fs_function);
if (unlikely(!f->descriptors)) {
usb_free_descriptors(f->descriptors);
return -ENOMEM;
}
if (gadget_is_dualspeed(gadget)) {
/* Assume endpoint addresses are the same for both speeds */
fsg_hs_bulk_in_desc.bEndpointAddress =
@ -2945,9 +2974,8 @@ static int fsg_bind(struct usb_configuration *c, struct usb_function *f)
autoconf_fail:
ERROR(fsg, "unable to autoconfigure all endpoints\n");
rc = -ENOTSUPP;
fsg_unbind(c, f);
return rc;
return -ENOTSUPP;
}
@ -2966,6 +2994,7 @@ static int fsg_add(struct usb_composite_dev *cdev,
int rc;
fsg = kzalloc(sizeof *fsg, GFP_KERNEL);
_fsg = fsg;
if (unlikely(!fsg))
return -ENOMEM;

View File

@ -73,6 +73,7 @@
#undef DUMP_MSGS
#endif /* !DEBUG */
#define VERBOSE_DEBUG
#ifdef VERBOSE_DEBUG
#define VLDBG LDBG
#else

View File

@ -551,6 +551,8 @@ static void f_rudolf_disable(struct usb_function *f)
/*-------------------------------------------------------------------------*/
static int msg_config(struct usb_configuration *c);
static int rudolf_bind_config(struct usb_configuration *c)
{
struct f_rudolf *rudolf;
@ -568,8 +570,18 @@ static int rudolf_bind_config(struct usb_configuration *c)
rudolf->function.disable = f_rudolf_disable;
status = usb_add_function(c, &rudolf->function);
if (status)
if (status) {
kfree(rudolf);
return status;
}
status = msg_config(c);
if (status) {
kfree(rudolf);
return status;
}
return status;
}

View File

@ -6,4 +6,5 @@ ev3duder up bin/nbd.ko ../prjs/ko/nbd.ko
ev3duder up ins ../prjs/ko/ins
ev3duder exec 'rm ../prjs/ko/uf2d'
ev3duder up bin/uf2d ../prjs/ko/uf2d
#ev3duder exec 'echo . /mnt/ramdisk/prjs/ko/ins > /mnt/ramdisk/rc.local'

View File

@ -36,7 +36,7 @@
#include "uf2.h"
#define DBG printf
#define DBG LOG
typedef struct {
uint8_t JumpInstruction[3];
@ -332,8 +332,7 @@ void addClusterData(ClusterData *c, FsEntry *e) {
c->myfile = e;
DBG("add cluster: flags=%d size=%d numcl=%d name=%s\n", c->flags, (int)c->st.st_size,
c->numclusters, c->name);
DBG("add cluster: flags=%d size=%d numcl=%d", c->flags, (int)c->st.st_size, c->numclusters);
}
FsEntry *addRootText(const char *filename, const char *contents) {
@ -393,7 +392,7 @@ void setFatNames(FsEntry *dirent) {
}
}
DBG("setname: %s [%s] cl=%s @ %d sz=%d dents=%d\n", p->vfatname, p->fatname,
DBG("setname: %s [%s] cl=%s @ %d sz=%d dents=%d", p->vfatname, p->fatname,
p->data ? p->data->name : "(no data)", p->startCluster, p->size, p->numdirentries);
}
}
@ -528,7 +527,7 @@ void readDirData(uint8_t *dest, FsEntry *dirdata, int blkno) {
if (idx >= 16)
break;
// DBG("dir idx=%d %s\n", idx, e->vfatname);
// DBG("dir idx=%d %s", idx, e->vfatname);
for (int i = 0; i < e->numdirentries; ++i, ++idx) {
if (0 <= idx && idx < 16) {
@ -562,15 +561,15 @@ void readDirData(uint8_t *dest, FsEntry *dirdata, int blkno) {
}
void readBlock(uint8_t *dest, int blkno) {
// DBG("readbl %d\n", blkno);
// DBG("readbl %d", blkno);
int blkno0 = blkno;
for (ClusterData *c = firstCluster; c; c = c->cnext) {
// DBG("off=%d sz=%d\n", blkno, c->numclusters);
// DBG("off=%d sz=%d", blkno, c->numclusters);
if (blkno >= c->numclusters) {
blkno -= c->numclusters;
continue;
}
// DBG("readbl off=%d %p\n", blkno, c);
// DBG("readbl off=%d %p", blkno, c);
if (c->dirdata) {
readDirData(dest, c->dirdata, blkno);
} else if (c->flags & F_TEXT) {
@ -592,6 +591,7 @@ void readBlock(uint8_t *dest, int blkno) {
if (fd >= 0) {
lseek(fd, bl->targetAddr, SEEK_SET);
bl->payloadSize = read(fd, bl->data, 256);
close(fd);
} else {
bl->payloadSize = -1;
}
@ -666,10 +666,10 @@ void stopLMS() {
closedir(dir);
if (lmsPid) {
DBG("SIGSTOP to lmsPID=%d\n", lmsPid);
DBG("SIGSTOP to lmsPID=%d", lmsPid);
kill(lmsPid, SIGSTOP);
} else {
DBG("LMS not found\n");
DBG("LMS not found");
}
}
@ -679,15 +679,16 @@ void waitAndContinue() {
close(fd);
pid_t child = fork();
if (child == 0) {
DBG("start %s\n", elfPath);
execl(elfPath, elfPath, "--msd", (char*) NULL);
DBG("start %s", elfPath);
execl(elfPath, elfPath, "--msd", (char *)NULL);
exit(128);
}
int status;
waitpid(child, &status, 0);
DBG("re-start LMS\n");
if (lmsPid)
DBG("re-start LMS");
if (lmsPid) {
kill(lmsPid, SIGCONT);
}
exit(0);
}
@ -749,7 +750,7 @@ void write_block(uint32_t block_no, uint8_t *data) {
if (fd >= 0) {
ftruncate(fd, bl->fileSize);
lseek(fd, bl->targetAddr, SEEK_SET);
// DBG("write %d bytes at %d to %s\n", bl->payloadSize, bl->targetAddr, fn);
// DBG("write %d bytes at %d to %s", bl->payloadSize, bl->targetAddr, fn);
write(fd, bl->data, bl->payloadSize);
close(fd);
@ -773,6 +774,7 @@ void write_block(uint32_t block_no, uint8_t *data) {
// logval("incr", state->numWritten);
state->writtenMask[pos] |= mask;
state->numWritten++;
DBG("write %d/%d #%d", state->numWritten, state->numBlocks, bl->blockNo);
}
if (state->numWritten >= state->numBlocks) {
restartProgram();

View File

@ -16,27 +16,38 @@
#include <sys/stat.h>
#include <unistd.h>
#include <sys/wait.h>
#include <stdarg.h>
#include "uf2.h"
#define NUM_BLOCKS NUM_FAT_BLOCKS
#define FAIL(args...) \
do { \
fprintf(stderr, args); \
fprintf(stderr, "\n"); \
exit(1); \
} while (0)
#define LOG(args...) \
do { \
fprintf(stderr, args); \
fprintf(stderr, "\n"); \
} while (0)
uint64_t ntohll(uint64_t a) { return ((uint64_t)ntohl(a & 0xffffffff) << 32) | ntohl(a >> 32); }
uint64_t ntohll(uint64_t a) {
return ((uint64_t)ntohl(a & 0xffffffff) << 32) | ntohl(a >> 32);
}
#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);
@ -82,9 +93,8 @@ void startclient() {
void handleread(int off, int len) {
uint8_t buf[512];
// fprintf(stderr, "read @%d len=%d\n", off, len);
// htonl(EPERM);
reply.error = 0;
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) {
read_block(off + i, buf);
@ -94,7 +104,7 @@ void handleread(int off, int len) {
void handlewrite(int off, int len) {
uint8_t buf[512];
// fprintf(stderr, "write @%d len=%d\n", 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);
@ -133,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,4 +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 { \
mylog(args); \
exit(1); \
} while (0)
#define LOG mylog
#endif