Compare commits
1 Commits
kernelport
...
orignalmod
Author | SHA1 | Date | |
---|---|---|---|
|
eb660e4a2d |
@@ -1,8 +1,7 @@
|
|||||||
#!/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
|
||||||
|
@@ -38,13 +38,6 @@
|
|||||||
// Keep Eclipse happy
|
// Keep Eclipse happy
|
||||||
#endif
|
#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 */
|
/* big enough to hold our biggest descriptor */
|
||||||
#define USB_BUFSIZ 1024
|
#define USB_BUFSIZ 1024
|
||||||
|
|
||||||
@@ -874,12 +867,6 @@ composite_setup(struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
|
|||||||
req->length = USB_BUFSIZ;
|
req->length = USB_BUFSIZ;
|
||||||
gadget->ep0->driver_data = cdev;
|
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) {
|
switch (ctrl->bRequest) {
|
||||||
/* we handle all standard USB descriptors */
|
/* we handle all standard USB descriptors */
|
||||||
case USB_REQ_GET_DESCRIPTOR:
|
case USB_REQ_GET_DESCRIPTOR:
|
||||||
|
@@ -40,8 +40,8 @@
|
|||||||
#include <asm/types.h>
|
#include <asm/types.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "source/lms2012.h"
|
#include "../../lms2012/source/lms2012.h"
|
||||||
#include "source/am1808.h"
|
#include "../../lms2012/source/am1808.h"
|
||||||
|
|
||||||
|
|
||||||
#define MODULE_NAME "usbdev_module"
|
#define MODULE_NAME "usbdev_module"
|
||||||
@@ -80,15 +80,12 @@ static void ModuleExit(void);
|
|||||||
#include <linux/utsname.h>
|
#include <linux/utsname.h>
|
||||||
#include <linux/device.h>
|
#include <linux/device.h>
|
||||||
|
|
||||||
static struct fsg_common *fsg_common;
|
|
||||||
|
|
||||||
#include "computil.c" // The composite framework used as utility file
|
#include "computil.c" // The composite framework used as utility file
|
||||||
#include <../drivers/usb/gadget/gadget_chips.h>
|
#include <../drivers/usb/gadget/gadget_chips.h>
|
||||||
#include <../drivers/usb/gadget/usbstring.c>
|
#include <../drivers/usb/gadget/usbstring.c>
|
||||||
#include <../drivers/usb/gadget/config.c>
|
#include <../drivers/usb/gadget/config.c>
|
||||||
#include <../drivers/usb/gadget/epautoconf.c>
|
#include <../drivers/usb/gadget/epautoconf.c>
|
||||||
|
|
||||||
#include "f_mass_storage.c"
|
|
||||||
|
|
||||||
/*-------------------------------------------------------------------------*/
|
/*-------------------------------------------------------------------------*/
|
||||||
|
|
||||||
@@ -173,10 +170,9 @@ static struct usb_device_descriptor device_desc = {
|
|||||||
.bDescriptorType = USB_DT_DEVICE,
|
.bDescriptorType = USB_DT_DEVICE,
|
||||||
|
|
||||||
.bcdUSB = cpu_to_le16(0x0200),
|
.bcdUSB = cpu_to_le16(0x0200),
|
||||||
.bDeviceClass = 0xEF,
|
.bDeviceClass = 0,
|
||||||
.bDeviceSubClass = 2,
|
.bDeviceSubClass = 0,
|
||||||
.bDeviceProtocol = 1,
|
.bDeviceProtocol = 0,
|
||||||
|
|
||||||
/*.bMaxPacketSize0 = f(hardware) */
|
/*.bMaxPacketSize0 = f(hardware) */
|
||||||
.idVendor = cpu_to_le16(DRIVER_VENDOR_NUM),
|
.idVendor = cpu_to_le16(DRIVER_VENDOR_NUM),
|
||||||
.idProduct = cpu_to_le16(DRIVER_PRODUCT_NUM),
|
.idProduct = cpu_to_le16(DRIVER_PRODUCT_NUM),
|
||||||
@@ -334,9 +330,6 @@ 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)
|
static int zero_bind(struct usb_composite_dev *cdev)
|
||||||
{
|
{
|
||||||
int gcnum;
|
int gcnum;
|
||||||
@@ -369,10 +362,6 @@ static int zero_bind(struct usb_composite_dev *cdev)
|
|||||||
strings_dev[STRING_SERIAL_IDX].id = id;
|
strings_dev[STRING_SERIAL_IDX].id = id;
|
||||||
device_desc.iSerialNumber = id;
|
device_desc.iSerialNumber = id;
|
||||||
|
|
||||||
id = msg_bind(cdev);
|
|
||||||
if (id < 0)
|
|
||||||
return id;
|
|
||||||
|
|
||||||
setup_timer(&autoresume_timer, zero_autoresume, (unsigned long) cdev);
|
setup_timer(&autoresume_timer, zero_autoresume, (unsigned long) cdev);
|
||||||
|
|
||||||
rudolf_add(cdev, autoresume != 0);
|
rudolf_add(cdev, autoresume != 0);
|
||||||
@@ -392,9 +381,6 @@ static int zero_bind(struct usb_composite_dev *cdev)
|
|||||||
longname, gadget->name);
|
longname, gadget->name);
|
||||||
device_desc.bcdDevice = cpu_to_le16(0x9999);
|
device_desc.bcdDevice = cpu_to_le16(0x9999);
|
||||||
}
|
}
|
||||||
|
|
||||||
msg_bind2(cdev);
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -710,38 +696,3 @@ 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);
|
|
||||||
}
|
|
||||||
|
@@ -288,7 +288,6 @@
|
|||||||
|
|
||||||
#include <linux/usb/ch9.h>
|
#include <linux/usb/ch9.h>
|
||||||
#include <linux/usb/gadget.h>
|
#include <linux/usb/gadget.h>
|
||||||
#include <linux/usb/composite.h>
|
|
||||||
|
|
||||||
#include "gadget_chips.h"
|
#include "gadget_chips.h"
|
||||||
|
|
||||||
@@ -303,6 +302,7 @@ static const char fsg_string_interface[] = "Mass Storage";
|
|||||||
|
|
||||||
|
|
||||||
#define FSG_NO_INTR_EP 1
|
#define FSG_NO_INTR_EP 1
|
||||||
|
#define FSG_BUFFHD_STATIC_BUFFER 1
|
||||||
#define FSG_NO_DEVICE_STRINGS 1
|
#define FSG_NO_DEVICE_STRINGS 1
|
||||||
#define FSG_NO_OTG 1
|
#define FSG_NO_OTG 1
|
||||||
#define FSG_NO_INTR_EP 1
|
#define FSG_NO_INTR_EP 1
|
||||||
@@ -318,8 +318,8 @@ struct fsg_dev;
|
|||||||
/* Data shared by all the FSG instances. */
|
/* Data shared by all the FSG instances. */
|
||||||
struct fsg_common {
|
struct fsg_common {
|
||||||
struct usb_gadget *gadget;
|
struct usb_gadget *gadget;
|
||||||
struct fsg_dev *fsg, *new_fsg;
|
struct fsg_dev *fsg;
|
||||||
wait_queue_head_t fsg_wait;
|
struct fsg_dev *prev_fsg;
|
||||||
|
|
||||||
/* filesem protects: backing files in use */
|
/* filesem protects: backing files in use */
|
||||||
struct rw_semaphore filesem;
|
struct rw_semaphore filesem;
|
||||||
@@ -348,6 +348,7 @@ struct fsg_common {
|
|||||||
enum fsg_state state; /* For exception handling */
|
enum fsg_state state; /* For exception handling */
|
||||||
unsigned int exception_req_tag;
|
unsigned int exception_req_tag;
|
||||||
|
|
||||||
|
u8 config, new_config;
|
||||||
enum data_direction data_dir;
|
enum data_direction data_dir;
|
||||||
u32 data_size;
|
u32 data_size;
|
||||||
u32 data_size_from_cmnd;
|
u32 data_size_from_cmnd;
|
||||||
@@ -587,7 +588,7 @@ static int fsg_setup(struct usb_function *f,
|
|||||||
u16 w_value = le16_to_cpu(ctrl->wValue);
|
u16 w_value = le16_to_cpu(ctrl->wValue);
|
||||||
u16 w_length = le16_to_cpu(ctrl->wLength);
|
u16 w_length = le16_to_cpu(ctrl->wLength);
|
||||||
|
|
||||||
if (!fsg_is_set(fsg->common))
|
if (!fsg->common->config)
|
||||||
return -EOPNOTSUPP;
|
return -EOPNOTSUPP;
|
||||||
|
|
||||||
switch (ctrl->bRequest) {
|
switch (ctrl->bRequest) {
|
||||||
@@ -613,12 +614,7 @@ static int fsg_setup(struct usb_function *f,
|
|||||||
return -EDOM;
|
return -EDOM;
|
||||||
VDBG(fsg, "get max LUN\n");
|
VDBG(fsg, "get max LUN\n");
|
||||||
*(u8 *) req->buf = fsg->common->nluns - 1;
|
*(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,
|
VDBG(fsg,
|
||||||
@@ -735,9 +731,6 @@ static int do_read(struct fsg_common *common)
|
|||||||
|
|
||||||
/* Carry out the file reads */
|
/* Carry out the file reads */
|
||||||
amount_left = common->data_size_from_cmnd;
|
amount_left = common->data_size_from_cmnd;
|
||||||
|
|
||||||
LDBG(curlun, "Uread off=%d cnt=%d\n", (int)lba, amount_left);
|
|
||||||
|
|
||||||
if (unlikely(amount_left == 0))
|
if (unlikely(amount_left == 0))
|
||||||
return -EIO; /* No default reply */
|
return -EIO; /* No default reply */
|
||||||
|
|
||||||
@@ -758,6 +751,7 @@ static int do_read(struct fsg_common *common)
|
|||||||
if (partial_page > 0)
|
if (partial_page > 0)
|
||||||
amount = min(amount, (unsigned int) PAGE_CACHE_SIZE -
|
amount = min(amount, (unsigned int) PAGE_CACHE_SIZE -
|
||||||
partial_page);
|
partial_page);
|
||||||
|
|
||||||
/* Wait for the next buffer to become available */
|
/* Wait for the next buffer to become available */
|
||||||
bh = common->next_buffhd_to_fill;
|
bh = common->next_buffhd_to_fill;
|
||||||
while (bh->state != BUF_STATE_EMPTY) {
|
while (bh->state != BUF_STATE_EMPTY) {
|
||||||
@@ -849,7 +843,7 @@ static int do_write(struct fsg_common *common)
|
|||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
spin_lock(&curlun->filp->f_lock);
|
spin_lock(&curlun->filp->f_lock);
|
||||||
curlun->filp->f_flags |= O_SYNC; /* Default is to wait */
|
curlun->filp->f_flags &= ~O_SYNC; /* Default is not to wait */
|
||||||
spin_unlock(&curlun->filp->f_lock);
|
spin_unlock(&curlun->filp->f_lock);
|
||||||
|
|
||||||
/* Get the starting Logical Block Address and check that it's
|
/* Get the starting Logical Block Address and check that it's
|
||||||
@@ -884,8 +878,6 @@ static int do_write(struct fsg_common *common)
|
|||||||
amount_left_to_req = common->data_size_from_cmnd;
|
amount_left_to_req = common->data_size_from_cmnd;
|
||||||
amount_left_to_write = 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) {
|
while (amount_left_to_write > 0) {
|
||||||
|
|
||||||
/* Queue a request for more data from the host */
|
/* Queue a request for more data from the host */
|
||||||
@@ -938,7 +930,6 @@ static int do_write(struct fsg_common *common)
|
|||||||
bh->outreq->length = amount;
|
bh->outreq->length = amount;
|
||||||
bh->bulk_out_intended_length = amount;
|
bh->bulk_out_intended_length = amount;
|
||||||
bh->outreq->short_not_ok = 1;
|
bh->outreq->short_not_ok = 1;
|
||||||
printk("write transfer %d\n", amount);
|
|
||||||
START_TRANSFER_OR(common, bulk_out, bh->outreq,
|
START_TRANSFER_OR(common, bulk_out, bh->outreq,
|
||||||
&bh->outreq_busy, &bh->state)
|
&bh->outreq_busy, &bh->state)
|
||||||
/* Don't know what to do if
|
/* Don't know what to do if
|
||||||
@@ -1015,14 +1006,10 @@ static int do_write(struct fsg_common *common)
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
printk("before sleep\n");
|
|
||||||
|
|
||||||
/* Wait for something to happen */
|
/* Wait for something to happen */
|
||||||
rc = sleep_thread(common);
|
rc = sleep_thread(common);
|
||||||
if (rc)
|
if (rc)
|
||||||
return rc;
|
return rc;
|
||||||
|
|
||||||
printk("after sleep\n");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return -EIO; /* No default reply */
|
return -EIO; /* No default reply */
|
||||||
@@ -2266,20 +2253,24 @@ static int alloc_request(struct fsg_common *common, struct usb_ep *ep,
|
|||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Reset interface setting and re-init endpoint state (toggle etc). */
|
/*
|
||||||
static int do_set_interface(struct fsg_common *common, struct fsg_dev *new_fsg)
|
* 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)
|
||||||
{
|
{
|
||||||
const struct usb_endpoint_descriptor *d;
|
int rc = 0;
|
||||||
struct fsg_dev *fsg;
|
int i;
|
||||||
int i, rc = 0;
|
const struct usb_endpoint_descriptor *d;
|
||||||
|
|
||||||
if (common->running)
|
if (common->running)
|
||||||
DBG(common, "reset interface\n");
|
DBG(common, "reset interface\n");
|
||||||
|
|
||||||
reset:
|
reset:
|
||||||
/* Deallocate the requests */
|
/* Deallocate the requests */
|
||||||
if (common->fsg) {
|
if (common->prev_fsg) {
|
||||||
fsg = common->fsg;
|
struct fsg_dev *fsg = common->prev_fsg;
|
||||||
|
|
||||||
for (i = 0; i < FSG_NUM_BUFFERS; ++i) {
|
for (i = 0; i < FSG_NUM_BUFFERS; ++i) {
|
||||||
struct fsg_buffhd *bh = &common->buffhds[i];
|
struct fsg_buffhd *bh = &common->buffhds[i];
|
||||||
@@ -2304,53 +2295,88 @@ reset:
|
|||||||
fsg->bulk_out_enabled = 0;
|
fsg->bulk_out_enabled = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
common->fsg = NULL;
|
common->prev_fsg = 0;
|
||||||
wake_up(&common->fsg_wait);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
common->running = 0;
|
common->running = 0;
|
||||||
if (!new_fsg || rc)
|
if (altsetting < 0 || rc != 0)
|
||||||
return rc;
|
return rc;
|
||||||
|
|
||||||
common->fsg = new_fsg;
|
DBG(common, "set interface %d\n", altsetting);
|
||||||
fsg = common->fsg;
|
|
||||||
|
|
||||||
/* Enable the endpoints */
|
if (fsg_is_set(common)) {
|
||||||
d = fsg_ep_desc(common->gadget,
|
struct fsg_dev *fsg = common->fsg;
|
||||||
&fsg_fs_bulk_in_desc, &fsg_hs_bulk_in_desc);
|
common->prev_fsg = common->fsg;
|
||||||
rc = enable_endpoint(common, fsg->bulk_in, d);
|
|
||||||
if (rc)
|
|
||||||
goto reset;
|
|
||||||
fsg->bulk_in_enabled = 1;
|
|
||||||
|
|
||||||
d = fsg_ep_desc(common->gadget,
|
/* Enable the endpoints */
|
||||||
&fsg_fs_bulk_out_desc, &fsg_hs_bulk_out_desc);
|
d = fsg_ep_desc(common->gadget,
|
||||||
rc = enable_endpoint(common, fsg->bulk_out, d);
|
&fsg_fs_bulk_in_desc, &fsg_hs_bulk_in_desc);
|
||||||
if (rc)
|
rc = enable_endpoint(common, fsg->bulk_in, d);
|
||||||
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)
|
if (rc)
|
||||||
goto reset;
|
goto reset;
|
||||||
rc = alloc_request(common, fsg->bulk_out, &bh->outreq);
|
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);
|
||||||
if (rc)
|
if (rc)
|
||||||
goto reset;
|
goto reset;
|
||||||
bh->inreq->buf = bh->outreq->buf = bh->buf;
|
fsg->bulk_out_enabled = 1;
|
||||||
bh->inreq->context = bh->outreq->context = bh;
|
common->bulk_out_maxpacket = le16_to_cpu(d->wMaxPacketSize);
|
||||||
bh->inreq->complete = bulk_in_complete;
|
clear_bit(IGNORE_BULK_OUT, &fsg->atomic_bitflags);
|
||||||
bh->outreq->complete = bulk_out_complete;
|
|
||||||
|
/* 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
common->running = 1;
|
/* Enable the interface */
|
||||||
for (i = 0; i < common->nluns; ++i)
|
if (new_config != 0) {
|
||||||
common->luns[i].unit_attention_data = SS_RESET_OCCURRED;
|
common->config = new_config;
|
||||||
|
rc = do_set_interface(common, 0);
|
||||||
|
if (rc != 0)
|
||||||
|
common->config = 0; /* Reset on errors */
|
||||||
|
}
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2361,7 +2387,9 @@ reset:
|
|||||||
static int fsg_set_alt(struct usb_function *f, unsigned intf, unsigned alt)
|
static int fsg_set_alt(struct usb_function *f, unsigned intf, unsigned alt)
|
||||||
{
|
{
|
||||||
struct fsg_dev *fsg = fsg_from_func(f);
|
struct fsg_dev *fsg = fsg_from_func(f);
|
||||||
fsg->common->new_fsg = fsg;
|
fsg->common->prev_fsg = fsg->common->fsg;
|
||||||
|
fsg->common->fsg = fsg;
|
||||||
|
fsg->common->new_config = 1;
|
||||||
raise_exception(fsg->common, FSG_STATE_CONFIG_CHANGE);
|
raise_exception(fsg->common, FSG_STATE_CONFIG_CHANGE);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -2369,7 +2397,9 @@ static int fsg_set_alt(struct usb_function *f, unsigned intf, unsigned alt)
|
|||||||
static void fsg_disable(struct usb_function *f)
|
static void fsg_disable(struct usb_function *f)
|
||||||
{
|
{
|
||||||
struct fsg_dev *fsg = fsg_from_func(f);
|
struct fsg_dev *fsg = fsg_from_func(f);
|
||||||
fsg->common->new_fsg = NULL;
|
fsg->common->prev_fsg = fsg->common->fsg;
|
||||||
|
fsg->common->fsg = fsg;
|
||||||
|
fsg->common->new_config = 0;
|
||||||
raise_exception(fsg->common, FSG_STATE_CONFIG_CHANGE);
|
raise_exception(fsg->common, FSG_STATE_CONFIG_CHANGE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2379,17 +2409,19 @@ static void fsg_disable(struct usb_function *f)
|
|||||||
static void handle_exception(struct fsg_common *common)
|
static void handle_exception(struct fsg_common *common)
|
||||||
{
|
{
|
||||||
siginfo_t info;
|
siginfo_t info;
|
||||||
|
int sig;
|
||||||
int i;
|
int i;
|
||||||
struct fsg_buffhd *bh;
|
struct fsg_buffhd *bh;
|
||||||
enum fsg_state old_state;
|
enum fsg_state old_state;
|
||||||
|
u8 new_config;
|
||||||
struct fsg_lun *curlun;
|
struct fsg_lun *curlun;
|
||||||
unsigned int exception_req_tag;
|
unsigned int exception_req_tag;
|
||||||
|
int rc;
|
||||||
|
|
||||||
/* Clear the existing signals. Anything but SIGUSR1 is converted
|
/* Clear the existing signals. Anything but SIGUSR1 is converted
|
||||||
* into a high-priority EXIT exception. */
|
* into a high-priority EXIT exception. */
|
||||||
for (;;) {
|
for (;;) {
|
||||||
int sig =
|
sig = dequeue_signal_lock(current, ¤t->blocked, &info);
|
||||||
dequeue_signal_lock(current, ¤t->blocked, &info);
|
|
||||||
if (!sig)
|
if (!sig)
|
||||||
break;
|
break;
|
||||||
if (sig != SIGUSR1) {
|
if (sig != SIGUSR1) {
|
||||||
@@ -2400,7 +2432,7 @@ static void handle_exception(struct fsg_common *common)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Cancel all the pending transfers */
|
/* Cancel all the pending transfers */
|
||||||
if (likely(common->fsg)) {
|
if (fsg_is_set(common)) {
|
||||||
for (i = 0; i < FSG_NUM_BUFFERS; ++i) {
|
for (i = 0; i < FSG_NUM_BUFFERS; ++i) {
|
||||||
bh = &common->buffhds[i];
|
bh = &common->buffhds[i];
|
||||||
if (bh->inreq_busy)
|
if (bh->inreq_busy)
|
||||||
@@ -2441,6 +2473,7 @@ static void handle_exception(struct fsg_common *common)
|
|||||||
common->next_buffhd_to_fill = &common->buffhds[0];
|
common->next_buffhd_to_fill = &common->buffhds[0];
|
||||||
common->next_buffhd_to_drain = &common->buffhds[0];
|
common->next_buffhd_to_drain = &common->buffhds[0];
|
||||||
exception_req_tag = common->exception_req_tag;
|
exception_req_tag = common->exception_req_tag;
|
||||||
|
new_config = common->new_config;
|
||||||
old_state = common->state;
|
old_state = common->state;
|
||||||
|
|
||||||
if (old_state == FSG_STATE_ABORT_BULK_OUT)
|
if (old_state == FSG_STATE_ABORT_BULK_OUT)
|
||||||
@@ -2490,12 +2523,20 @@ static void handle_exception(struct fsg_common *common)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case FSG_STATE_CONFIG_CHANGE:
|
case FSG_STATE_CONFIG_CHANGE:
|
||||||
do_set_interface(common, common->new_fsg);
|
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);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case FSG_STATE_EXIT:
|
case FSG_STATE_EXIT:
|
||||||
case FSG_STATE_TERMINATED:
|
case FSG_STATE_TERMINATED:
|
||||||
do_set_interface(common, NULL); /* Free resources */
|
do_set_config(common, 0); /* Free resources */
|
||||||
spin_lock_irq(&common->lock);
|
spin_lock_irq(&common->lock);
|
||||||
common->state = FSG_STATE_TERMINATED; /* Stop the thread */
|
common->state = FSG_STATE_TERMINATED; /* Stop the thread */
|
||||||
spin_unlock_irq(&common->lock);
|
spin_unlock_irq(&common->lock);
|
||||||
@@ -2588,41 +2629,6 @@ static int fsg_main_thread(void *common_)
|
|||||||
static DEVICE_ATTR(ro, 0644, fsg_show_ro, fsg_store_ro);
|
static DEVICE_ATTR(ro, 0644, fsg_show_ro, fsg_store_ro);
|
||||||
static DEVICE_ATTR(file, 0644, fsg_show_file, fsg_store_file);
|
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 ******************************/
|
/****************************** FSG COMMON ******************************/
|
||||||
|
|
||||||
@@ -2669,7 +2675,7 @@ static struct fsg_common *fsg_common_init(struct fsg_common *common,
|
|||||||
return ERR_PTR(-ENOMEM);
|
return ERR_PTR(-ENOMEM);
|
||||||
common->free_storage_on_release = 1;
|
common->free_storage_on_release = 1;
|
||||||
} else {
|
} else {
|
||||||
memset(common, 0, sizeof *common);
|
memset(common, 0, sizeof common);
|
||||||
common->free_storage_on_release = 0;
|
common->free_storage_on_release = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2729,10 +2735,6 @@ static struct fsg_common *fsg_common_init(struct fsg_common *common,
|
|||||||
if (rc)
|
if (rc)
|
||||||
goto error_luns;
|
goto error_luns;
|
||||||
|
|
||||||
rc = device_create_file(&curlun->dev, &dev_attr_active);
|
|
||||||
if (rc)
|
|
||||||
goto error_luns;
|
|
||||||
|
|
||||||
if (lcfg->filename) {
|
if (lcfg->filename) {
|
||||||
rc = fsg_lun_open(curlun, lcfg->filename);
|
rc = fsg_lun_open(curlun, lcfg->filename);
|
||||||
if (rc)
|
if (rc)
|
||||||
@@ -2747,19 +2749,13 @@ static struct fsg_common *fsg_common_init(struct fsg_common *common,
|
|||||||
|
|
||||||
|
|
||||||
/* Data buffers cyclic list */
|
/* Data buffers cyclic list */
|
||||||
|
/* Buffers in buffhds are static -- no need for additional
|
||||||
|
* allocation. */
|
||||||
bh = common->buffhds;
|
bh = common->buffhds;
|
||||||
i = FSG_NUM_BUFFERS;
|
i = FSG_NUM_BUFFERS - 1;
|
||||||
goto buffhds_first_it;
|
|
||||||
do {
|
do {
|
||||||
bh->next = bh + 1;
|
bh->next = bh + 1;
|
||||||
++bh;
|
} while (++bh, --i);
|
||||||
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;
|
bh->next = common->buffhds;
|
||||||
|
|
||||||
|
|
||||||
@@ -2813,7 +2809,6 @@ buffhds_first_it:
|
|||||||
goto error_release;
|
goto error_release;
|
||||||
}
|
}
|
||||||
init_completion(&common->thread_notifier);
|
init_completion(&common->thread_notifier);
|
||||||
init_waitqueue_head(&common->fsg_wait);
|
|
||||||
#undef OR
|
#undef OR
|
||||||
|
|
||||||
|
|
||||||
@@ -2868,7 +2863,6 @@ static void fsg_common_release(struct kref *ref)
|
|||||||
container_of(ref, struct fsg_common, ref);
|
container_of(ref, struct fsg_common, ref);
|
||||||
unsigned i = common->nluns;
|
unsigned i = common->nluns;
|
||||||
struct fsg_lun *lun = common->luns;
|
struct fsg_lun *lun = common->luns;
|
||||||
struct fsg_buffhd *bh;
|
|
||||||
|
|
||||||
/* If the thread isn't already dead, tell it to exit now */
|
/* If the thread isn't already dead, tell it to exit now */
|
||||||
if (common->state != FSG_STATE_TERMINATED) {
|
if (common->state != FSG_STATE_TERMINATED) {
|
||||||
@@ -2890,13 +2884,6 @@ static void fsg_common_release(struct kref *ref)
|
|||||||
}
|
}
|
||||||
|
|
||||||
kfree(common->luns);
|
kfree(common->luns);
|
||||||
|
|
||||||
i = FSG_NUM_BUFFERS;
|
|
||||||
bh = common->buffhds;
|
|
||||||
do {
|
|
||||||
kfree(bh->buf);
|
|
||||||
} while (++bh, --i);
|
|
||||||
|
|
||||||
if (common->free_storage_on_release)
|
if (common->free_storage_on_release)
|
||||||
kfree(common);
|
kfree(common);
|
||||||
}
|
}
|
||||||
@@ -2908,19 +2895,9 @@ static void fsg_common_release(struct kref *ref)
|
|||||||
static void fsg_unbind(struct usb_configuration *c, struct usb_function *f)
|
static void fsg_unbind(struct usb_configuration *c, struct usb_function *f)
|
||||||
{
|
{
|
||||||
struct fsg_dev *fsg = fsg_from_func(f);
|
struct fsg_dev *fsg = fsg_from_func(f);
|
||||||
struct fsg_common *common = fsg->common;
|
|
||||||
|
|
||||||
DBG(fsg, "unbind\n");
|
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);
|
kfree(fsg);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2929,6 +2906,7 @@ static int fsg_bind(struct usb_configuration *c, struct usb_function *f)
|
|||||||
{
|
{
|
||||||
struct fsg_dev *fsg = fsg_from_func(f);
|
struct fsg_dev *fsg = fsg_from_func(f);
|
||||||
struct usb_gadget *gadget = c->cdev->gadget;
|
struct usb_gadget *gadget = c->cdev->gadget;
|
||||||
|
int rc;
|
||||||
int i;
|
int i;
|
||||||
struct usb_ep *ep;
|
struct usb_ep *ep;
|
||||||
|
|
||||||
@@ -2954,13 +2932,6 @@ static int fsg_bind(struct usb_configuration *c, struct usb_function *f)
|
|||||||
ep->driver_data = fsg->common; /* claim the endpoint */
|
ep->driver_data = fsg->common; /* claim the endpoint */
|
||||||
fsg->bulk_out = ep;
|
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)) {
|
if (gadget_is_dualspeed(gadget)) {
|
||||||
/* Assume endpoint addresses are the same for both speeds */
|
/* Assume endpoint addresses are the same for both speeds */
|
||||||
fsg_hs_bulk_in_desc.bEndpointAddress =
|
fsg_hs_bulk_in_desc.bEndpointAddress =
|
||||||
@@ -2974,8 +2945,9 @@ static int fsg_bind(struct usb_configuration *c, struct usb_function *f)
|
|||||||
|
|
||||||
autoconf_fail:
|
autoconf_fail:
|
||||||
ERROR(fsg, "unable to autoconfigure all endpoints\n");
|
ERROR(fsg, "unable to autoconfigure all endpoints\n");
|
||||||
|
rc = -ENOTSUPP;
|
||||||
fsg_unbind(c, f);
|
fsg_unbind(c, f);
|
||||||
return -ENOTSUPP;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -2994,7 +2966,6 @@ static int fsg_add(struct usb_composite_dev *cdev,
|
|||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
fsg = kzalloc(sizeof *fsg, GFP_KERNEL);
|
fsg = kzalloc(sizeof *fsg, GFP_KERNEL);
|
||||||
_fsg = fsg;
|
|
||||||
if (unlikely(!fsg))
|
if (unlikely(!fsg))
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
|
@@ -73,7 +73,6 @@
|
|||||||
#undef DUMP_MSGS
|
#undef DUMP_MSGS
|
||||||
#endif /* !DEBUG */
|
#endif /* !DEBUG */
|
||||||
|
|
||||||
#define VERBOSE_DEBUG
|
|
||||||
#ifdef VERBOSE_DEBUG
|
#ifdef VERBOSE_DEBUG
|
||||||
#define VLDBG LDBG
|
#define VLDBG LDBG
|
||||||
#else
|
#else
|
||||||
|
@@ -551,8 +551,6 @@ 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)
|
static int rudolf_bind_config(struct usb_configuration *c)
|
||||||
{
|
{
|
||||||
struct f_rudolf *rudolf;
|
struct f_rudolf *rudolf;
|
||||||
@@ -570,18 +568,8 @@ static int rudolf_bind_config(struct usb_configuration *c)
|
|||||||
rudolf->function.disable = f_rudolf_disable;
|
rudolf->function.disable = f_rudolf_disable;
|
||||||
|
|
||||||
status = usb_add_function(c, &rudolf->function);
|
status = usb_add_function(c, &rudolf->function);
|
||||||
if (status) {
|
if (status)
|
||||||
kfree(rudolf);
|
kfree(rudolf);
|
||||||
return status;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
status = msg_config(c);
|
|
||||||
if (status) {
|
|
||||||
kfree(rudolf);
|
|
||||||
return status;
|
|
||||||
}
|
|
||||||
|
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -6,5 +6,4 @@ ev3duder up bin/nbd.ko ../prjs/ko/nbd.ko
|
|||||||
ev3duder up ins ../prjs/ko/ins
|
ev3duder up ins ../prjs/ko/ins
|
||||||
ev3duder exec 'rm ../prjs/ko/uf2d'
|
ev3duder exec 'rm ../prjs/ko/uf2d'
|
||||||
ev3duder up bin/uf2d ../prjs/ko/uf2d
|
ev3duder up bin/uf2d ../prjs/ko/uf2d
|
||||||
#ev3duder exec 'echo . /mnt/ramdisk/prjs/ko/ins > /mnt/ramdisk/rc.local'
|
|
||||||
|
|
||||||
|
@@ -36,7 +36,7 @@
|
|||||||
|
|
||||||
#include "uf2.h"
|
#include "uf2.h"
|
||||||
|
|
||||||
#define DBG LOG
|
#define DBG printf
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint8_t JumpInstruction[3];
|
uint8_t JumpInstruction[3];
|
||||||
@@ -332,7 +332,8 @@ void addClusterData(ClusterData *c, FsEntry *e) {
|
|||||||
|
|
||||||
c->myfile = e;
|
c->myfile = e;
|
||||||
|
|
||||||
DBG("add cluster: flags=%d size=%d numcl=%d", c->flags, (int)c->st.st_size, c->numclusters);
|
DBG("add cluster: flags=%d size=%d numcl=%d name=%s\n", c->flags, (int)c->st.st_size,
|
||||||
|
c->numclusters, c->name);
|
||||||
}
|
}
|
||||||
|
|
||||||
FsEntry *addRootText(const char *filename, const char *contents) {
|
FsEntry *addRootText(const char *filename, const char *contents) {
|
||||||
@@ -392,7 +393,7 @@ void setFatNames(FsEntry *dirent) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
DBG("setname: %s [%s] cl=%s @ %d sz=%d dents=%d", p->vfatname, p->fatname,
|
DBG("setname: %s [%s] cl=%s @ %d sz=%d dents=%d\n", p->vfatname, p->fatname,
|
||||||
p->data ? p->data->name : "(no data)", p->startCluster, p->size, p->numdirentries);
|
p->data ? p->data->name : "(no data)", p->startCluster, p->size, p->numdirentries);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -527,7 +528,7 @@ void readDirData(uint8_t *dest, FsEntry *dirdata, int blkno) {
|
|||||||
if (idx >= 16)
|
if (idx >= 16)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// DBG("dir idx=%d %s", idx, e->vfatname);
|
// DBG("dir idx=%d %s\n", idx, e->vfatname);
|
||||||
|
|
||||||
for (int i = 0; i < e->numdirentries; ++i, ++idx) {
|
for (int i = 0; i < e->numdirentries; ++i, ++idx) {
|
||||||
if (0 <= idx && idx < 16) {
|
if (0 <= idx && idx < 16) {
|
||||||
@@ -561,15 +562,15 @@ void readDirData(uint8_t *dest, FsEntry *dirdata, int blkno) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void readBlock(uint8_t *dest, int blkno) {
|
void readBlock(uint8_t *dest, int blkno) {
|
||||||
// DBG("readbl %d", blkno);
|
// DBG("readbl %d\n", blkno);
|
||||||
int blkno0 = blkno;
|
int blkno0 = blkno;
|
||||||
for (ClusterData *c = firstCluster; c; c = c->cnext) {
|
for (ClusterData *c = firstCluster; c; c = c->cnext) {
|
||||||
// DBG("off=%d sz=%d", blkno, c->numclusters);
|
// DBG("off=%d sz=%d\n", blkno, c->numclusters);
|
||||||
if (blkno >= c->numclusters) {
|
if (blkno >= c->numclusters) {
|
||||||
blkno -= c->numclusters;
|
blkno -= c->numclusters;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
// DBG("readbl off=%d %p", blkno, c);
|
// DBG("readbl off=%d %p\n", blkno, c);
|
||||||
if (c->dirdata) {
|
if (c->dirdata) {
|
||||||
readDirData(dest, c->dirdata, blkno);
|
readDirData(dest, c->dirdata, blkno);
|
||||||
} else if (c->flags & F_TEXT) {
|
} else if (c->flags & F_TEXT) {
|
||||||
@@ -591,7 +592,6 @@ void readBlock(uint8_t *dest, int blkno) {
|
|||||||
if (fd >= 0) {
|
if (fd >= 0) {
|
||||||
lseek(fd, bl->targetAddr, SEEK_SET);
|
lseek(fd, bl->targetAddr, SEEK_SET);
|
||||||
bl->payloadSize = read(fd, bl->data, 256);
|
bl->payloadSize = read(fd, bl->data, 256);
|
||||||
close(fd);
|
|
||||||
} else {
|
} else {
|
||||||
bl->payloadSize = -1;
|
bl->payloadSize = -1;
|
||||||
}
|
}
|
||||||
@@ -666,10 +666,10 @@ void stopLMS() {
|
|||||||
closedir(dir);
|
closedir(dir);
|
||||||
|
|
||||||
if (lmsPid) {
|
if (lmsPid) {
|
||||||
DBG("SIGSTOP to lmsPID=%d", lmsPid);
|
DBG("SIGSTOP to lmsPID=%d\n", lmsPid);
|
||||||
kill(lmsPid, SIGSTOP);
|
kill(lmsPid, SIGSTOP);
|
||||||
} else {
|
} else {
|
||||||
DBG("LMS not found");
|
DBG("LMS not found\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -679,16 +679,15 @@ void waitAndContinue() {
|
|||||||
close(fd);
|
close(fd);
|
||||||
pid_t child = fork();
|
pid_t child = fork();
|
||||||
if (child == 0) {
|
if (child == 0) {
|
||||||
DBG("start %s", elfPath);
|
DBG("start %s\n", elfPath);
|
||||||
execl(elfPath, elfPath, "--msd", (char *)NULL);
|
execl(elfPath, elfPath, "--msd", (char*) NULL);
|
||||||
exit(128);
|
exit(128);
|
||||||
}
|
}
|
||||||
int status;
|
int status;
|
||||||
waitpid(child, &status, 0);
|
waitpid(child, &status, 0);
|
||||||
DBG("re-start LMS");
|
DBG("re-start LMS\n");
|
||||||
if (lmsPid) {
|
if (lmsPid)
|
||||||
kill(lmsPid, SIGCONT);
|
kill(lmsPid, SIGCONT);
|
||||||
}
|
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -750,7 +749,7 @@ void write_block(uint32_t block_no, uint8_t *data) {
|
|||||||
if (fd >= 0) {
|
if (fd >= 0) {
|
||||||
ftruncate(fd, bl->fileSize);
|
ftruncate(fd, bl->fileSize);
|
||||||
lseek(fd, bl->targetAddr, SEEK_SET);
|
lseek(fd, bl->targetAddr, SEEK_SET);
|
||||||
// DBG("write %d bytes at %d to %s", bl->payloadSize, bl->targetAddr, fn);
|
// DBG("write %d bytes at %d to %s\n", bl->payloadSize, bl->targetAddr, fn);
|
||||||
write(fd, bl->data, bl->payloadSize);
|
write(fd, bl->data, bl->payloadSize);
|
||||||
close(fd);
|
close(fd);
|
||||||
|
|
||||||
@@ -774,7 +773,6 @@ void write_block(uint32_t block_no, uint8_t *data) {
|
|||||||
// logval("incr", state->numWritten);
|
// logval("incr", state->numWritten);
|
||||||
state->writtenMask[pos] |= mask;
|
state->writtenMask[pos] |= mask;
|
||||||
state->numWritten++;
|
state->numWritten++;
|
||||||
DBG("write %d/%d #%d", state->numWritten, state->numBlocks, bl->blockNo);
|
|
||||||
}
|
}
|
||||||
if (state->numWritten >= state->numBlocks) {
|
if (state->numWritten >= state->numBlocks) {
|
||||||
restartProgram();
|
restartProgram();
|
||||||
|
@@ -16,38 +16,27 @@
|
|||||||
#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"
|
||||||
|
|
||||||
#define NUM_BLOCKS NUM_FAT_BLOCKS
|
#define NUM_BLOCKS NUM_FAT_BLOCKS
|
||||||
|
|
||||||
uint64_t ntohll(uint64_t a) {
|
#define FAIL(args...) \
|
||||||
return ((uint64_t)ntohl(a & 0xffffffff) << 32) | ntohl(a >> 32);
|
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); }
|
||||||
#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);
|
||||||
@@ -93,8 +82,9 @@ 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);
|
// fprintf(stderr, "read @%d len=%d\n", off, len);
|
||||||
reply.error = 0; // htonl(EPERM);
|
// htonl(EPERM);
|
||||||
|
reply.error = 0;
|
||||||
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) {
|
||||||
read_block(off + i, buf);
|
read_block(off + i, buf);
|
||||||
@@ -104,7 +94,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);
|
// fprintf(stderr, "write @%d len=%d\n", 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);
|
||||||
@@ -143,7 +133,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,7 +25,8 @@ 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) 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[];
|
extern const char infoUf2File[];
|
||||||
|
|
||||||
@@ -33,14 +34,4 @@ 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...) \
|
|
||||||
do { \
|
|
||||||
mylog(args); \
|
|
||||||
exit(1); \
|
|
||||||
} while (0)
|
|
||||||
|
|
||||||
#define LOG mylog
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Reference in New Issue
Block a user