* [PATCH v2 1/4] bbu: Add barebox_update search by device @ 2016-02-17 11:28 Markus Pargmann 2016-02-17 11:28 ` [PATCH v2 2/4] bbu: Add function to check if an update handler exists Markus Pargmann ` (2 more replies) 0 siblings, 3 replies; 7+ messages in thread From: Markus Pargmann @ 2016-02-17 11:28 UTC (permalink / raw) To: barebox bbu_data includes a devicefile information. Add the possibility to make an update based on the given devicefile. This is in addition to the normal search for a barebox update handler by its name. Signed-off-by: Markus Pargmann <mpa@pengutronix.de> --- common/bbu.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/common/bbu.c b/common/bbu.c index 4d71fa4a87cb..bf3790d13fff 100644 --- a/common/bbu.c +++ b/common/bbu.c @@ -97,6 +97,20 @@ static struct bbu_handler *bbu_find_handler(const char *name) return NULL; } +static struct bbu_handler *bbu_find_handler_by_device(const char *devicepath) +{ + struct bbu_handler *handler; + + if (!devicepath) + return NULL; + + list_for_each_entry(handler, &bbu_image_handlers, list) + if (!strcmp(handler->devicefile, devicepath)) + return handler; + + return NULL; +} + /* * do a barebox update with data from *data */ @@ -105,7 +119,11 @@ int barebox_update(struct bbu_data *data) struct bbu_handler *handler; int ret; - handler = bbu_find_handler(data->handler_name); + handler = bbu_find_handler_by_device(data->devicefile); + + if (!handler) + handler = bbu_find_handler(data->handler_name); + if (!handler) return -ENODEV; -- 2.7.0 _______________________________________________ barebox mailing list barebox@lists.infradead.org http://lists.infradead.org/mailman/listinfo/barebox ^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH v2 2/4] bbu: Add function to check if an update handler exists 2016-02-17 11:28 [PATCH v2 1/4] bbu: Add barebox_update search by device Markus Pargmann @ 2016-02-17 11:28 ` Markus Pargmann 2016-02-17 11:28 ` [PATCH v2 3/4] fastboot: Fix usage of ubiformat for UBI image transfers Markus Pargmann 2016-02-17 11:28 ` [PATCH v2 4/4] fastboot: Add a ARM Barebox filetype handler Markus Pargmann 2 siblings, 0 replies; 7+ messages in thread From: Markus Pargmann @ 2016-02-17 11:28 UTC (permalink / raw) To: barebox This adds a function to check for the existence of an update handler based on the supplied bbu_data. Signed-off-by: Markus Pargmann <mpa@pengutronix.de> --- common/bbu.c | 14 ++++++++++++++ include/bbu.h | 2 ++ 2 files changed, 16 insertions(+) diff --git a/common/bbu.c b/common/bbu.c index bf3790d13fff..a7f6b4b851ee 100644 --- a/common/bbu.c +++ b/common/bbu.c @@ -111,6 +111,20 @@ static struct bbu_handler *bbu_find_handler_by_device(const char *devicepath) return NULL; } +bool barebox_update_handler_exists(struct bbu_data *data) +{ + struct bbu_handler *handler; + + handler = bbu_find_handler_by_device(data->devicefile); + if (handler) + return true; + + if (!data->handler_name) + return false; + + return !bbu_find_handler(data->handler_name); +} + /* * do a barebox update with data from *data */ diff --git a/include/bbu.h b/include/bbu.h index 727791171858..0fe7a1a9bcdb 100644 --- a/include/bbu.h +++ b/include/bbu.h @@ -36,6 +36,8 @@ int bbu_confirm(struct bbu_data *); int barebox_update(struct bbu_data *); +bool barebox_update_handler_exists(struct bbu_data *); + void bbu_handlers_list(void); #ifdef CONFIG_BAREBOX_UPDATE -- 2.7.0 _______________________________________________ barebox mailing list barebox@lists.infradead.org http://lists.infradead.org/mailman/listinfo/barebox ^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH v2 3/4] fastboot: Fix usage of ubiformat for UBI image transfers 2016-02-17 11:28 [PATCH v2 1/4] bbu: Add barebox_update search by device Markus Pargmann 2016-02-17 11:28 ` [PATCH v2 2/4] bbu: Add function to check if an update handler exists Markus Pargmann @ 2016-02-17 11:28 ` Markus Pargmann 2016-02-17 11:28 ` [PATCH v2 4/4] fastboot: Add a ARM Barebox filetype handler Markus Pargmann 2 siblings, 0 replies; 7+ messages in thread From: Markus Pargmann @ 2016-02-17 11:28 UTC (permalink / raw) To: barebox Currently all fastboot flash commands with UBI images are handled by a final call to 'ubiformat'. This only makes sense for flash commands where the target file is a mtd device. If we just want to transfer a UBI image we would expect a simple copy to the correct location. This patch checks if the destination file is a MTD device by opening it and calling an ioctl MEMGETINFO. Only for MTD devices, ubiformat is called. Signed-off-by: Markus Pargmann <mpa@pengutronix.de> --- drivers/usb/gadget/f_fastboot.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/drivers/usb/gadget/f_fastboot.c b/drivers/usb/gadget/f_fastboot.c index bf28f7c22aaa..bc06c58d8dcb 100644 --- a/drivers/usb/gadget/f_fastboot.c +++ b/drivers/usb/gadget/f_fastboot.c @@ -686,7 +686,21 @@ static void cb_flash(struct usb_ep *ep, struct usb_request *req, const char *cmd } if (filetype == filetype_ubi) { - char *cmd = asprintf("ubiformat -y -f %s %s", FASTBOOT_TMPFILE, filename); + char *cmd; + int fd; + struct mtd_info_user meminfo; + + fd = open(filename, O_RDONLY); + if (fd < 0) + goto copy; + + ret = ioctl(fd, MEMGETINFO, &meminfo); + close(fd); + /* Not a MTD device, ubiformat is not a valid operation */ + if (ret) + goto copy; + + cmd = asprintf("ubiformat -y -f %s %s", FASTBOOT_TMPFILE, filename); fastboot_tx_print(f_fb, "INFOThis is an UBI image..."); @@ -702,6 +716,7 @@ static void cb_flash(struct usb_ep *ep, struct usb_request *req, const char *cmd goto out; } +copy: ret = copy_file(FASTBOOT_TMPFILE, filename, 1); if (ret) { fastboot_tx_print(f_fb, "FAILwrite partition: %s", strerror(-ret)); -- 2.7.0 _______________________________________________ barebox mailing list barebox@lists.infradead.org http://lists.infradead.org/mailman/listinfo/barebox ^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH v2 4/4] fastboot: Add a ARM Barebox filetype handler 2016-02-17 11:28 [PATCH v2 1/4] bbu: Add barebox_update search by device Markus Pargmann 2016-02-17 11:28 ` [PATCH v2 2/4] bbu: Add function to check if an update handler exists Markus Pargmann 2016-02-17 11:28 ` [PATCH v2 3/4] fastboot: Fix usage of ubiformat for UBI image transfers Markus Pargmann @ 2016-02-17 11:28 ` Markus Pargmann 2016-02-18 8:22 ` Michael Olbrich 2016-03-11 7:07 ` Sascha Hauer 2 siblings, 2 replies; 7+ messages in thread From: Markus Pargmann @ 2016-02-17 11:28 UTC (permalink / raw) To: barebox This will automatically call barebox_update for the transfered file if it is an ARM Barebox image and the destination file is defined by some update handler. Signed-off-by: Markus Pargmann <mpa@pengutronix.de> --- common/filetype.c | 13 +++++++++++++ drivers/usb/gadget/f_fastboot.c | 29 +++++++++++++++++++++++++++++ include/filetype.h | 2 ++ 3 files changed, 44 insertions(+) diff --git a/common/filetype.c b/common/filetype.c index 8cfae88aeb35..74baf514466a 100644 --- a/common/filetype.c +++ b/common/filetype.c @@ -369,3 +369,16 @@ err_out: cdev_close(cdev); return type; } + +bool filetype_is_barebox_image(enum filetype ft) +{ + switch (ft) { + case filetype_arm_barebox: + case filetype_mips_barebox: + case filetype_ch_image: + case filetype_ch_image_be: + return true; + default: + return false; + } +} diff --git a/drivers/usb/gadget/f_fastboot.c b/drivers/usb/gadget/f_fastboot.c index bc06c58d8dcb..9a1058a9670b 100644 --- a/drivers/usb/gadget/f_fastboot.c +++ b/drivers/usb/gadget/f_fastboot.c @@ -23,6 +23,7 @@ #include <clock.h> #include <ioctl.h> #include <libbb.h> +#include <bbu.h> #include <boot.h> #include <dma.h> #include <fs.h> @@ -716,6 +717,34 @@ static void cb_flash(struct usb_ep *ep, struct usb_request *req, const char *cmd goto out; } + if (filetype_is_barebox_image(filetype)) { + struct bbu_data data = { + .devicefile = filename, + .imagefile = FASTBOOT_TMPFILE, + .flags = BBU_FLAG_YES, + }; + + if (!barebox_update_handler_exists(&data)) + goto copy; + + fastboot_tx_print(f_fb, "INFOThis is an ARM Barebox image..."); + + data.image = read_file(data.imagefile, &data.len); + if (!data.image) { + fastboot_tx_print(f_fb, "FAILreading barebox"); + return; + } + + ret = barebox_update(&data); + + if (ret) { + fastboot_tx_print(f_fb, "FAILupdate barebox: %s", strerror(-ret)); + return; + } + + goto out; + } + copy: ret = copy_file(FASTBOOT_TMPFILE, filename, 1); if (ret) { diff --git a/include/filetype.h b/include/filetype.h index cde543e5b061..e87ca174a89d 100644 --- a/include/filetype.h +++ b/include/filetype.h @@ -2,6 +2,7 @@ #define __FILE_TYPE_H #include <linux/string.h> +#include <linux/types.h> /* * List of file types we know @@ -48,6 +49,7 @@ enum filetype file_name_detect_type(const char *filename); enum filetype cdev_detect_type(const char *name); enum filetype is_fat_or_mbr(const unsigned char *sector, unsigned long *bootsec); int is_fat_boot_sector(const void *_buf); +bool filetype_is_barebox_image(enum filetype ft); #define ARM_HEAD_SIZE 0x30 #define ARM_HEAD_MAGICWORD_OFFSET 0x20 -- 2.7.0 _______________________________________________ barebox mailing list barebox@lists.infradead.org http://lists.infradead.org/mailman/listinfo/barebox ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v2 4/4] fastboot: Add a ARM Barebox filetype handler 2016-02-17 11:28 ` [PATCH v2 4/4] fastboot: Add a ARM Barebox filetype handler Markus Pargmann @ 2016-02-18 8:22 ` Michael Olbrich 2016-02-19 7:44 ` Sascha Hauer 2016-03-11 7:07 ` Sascha Hauer 1 sibling, 1 reply; 7+ messages in thread From: Michael Olbrich @ 2016-02-18 8:22 UTC (permalink / raw) To: barebox On Wed, Feb 17, 2016 at 12:28:20PM +0100, Markus Pargmann wrote: > This will automatically call barebox_update for the transfered file if > it is an ARM Barebox image and the destination file is defined by some > update handler. > > Signed-off-by: Markus Pargmann <mpa@pengutronix.de> > --- > common/filetype.c | 13 +++++++++++++ > drivers/usb/gadget/f_fastboot.c | 29 +++++++++++++++++++++++++++++ > include/filetype.h | 2 ++ > 3 files changed, 44 insertions(+) > > diff --git a/common/filetype.c b/common/filetype.c > index 8cfae88aeb35..74baf514466a 100644 > --- a/common/filetype.c > +++ b/common/filetype.c > @@ -369,3 +369,16 @@ err_out: > cdev_close(cdev); > return type; > } > + > +bool filetype_is_barebox_image(enum filetype ft) > +{ > + switch (ft) { > + case filetype_arm_barebox: > + case filetype_mips_barebox: > + case filetype_ch_image: > + case filetype_ch_image_be: > + return true; > + default: > + return false; > + } > +} > diff --git a/drivers/usb/gadget/f_fastboot.c b/drivers/usb/gadget/f_fastboot.c > index bc06c58d8dcb..9a1058a9670b 100644 > --- a/drivers/usb/gadget/f_fastboot.c > +++ b/drivers/usb/gadget/f_fastboot.c > @@ -23,6 +23,7 @@ > #include <clock.h> > #include <ioctl.h> > #include <libbb.h> > +#include <bbu.h> > #include <boot.h> > #include <dma.h> > #include <fs.h> > @@ -716,6 +717,34 @@ static void cb_flash(struct usb_ep *ep, struct usb_request *req, const char *cmd > goto out; > } > > + if (filetype_is_barebox_image(filetype)) { > + struct bbu_data data = { > + .devicefile = filename, > + .imagefile = FASTBOOT_TMPFILE, > + .flags = BBU_FLAG_YES, > + }; > + > + if (!barebox_update_handler_exists(&data)) > + goto copy; > + > + fastboot_tx_print(f_fb, "INFOThis is an ARM Barebox image..."); With the change above, it may not be an _ARM_ image. Michael > + > + data.image = read_file(data.imagefile, &data.len); > + if (!data.image) { > + fastboot_tx_print(f_fb, "FAILreading barebox"); > + return; > + } > + > + ret = barebox_update(&data); > + > + if (ret) { > + fastboot_tx_print(f_fb, "FAILupdate barebox: %s", strerror(-ret)); > + return; > + } > + > + goto out; > + } > + > copy: > ret = copy_file(FASTBOOT_TMPFILE, filename, 1); > if (ret) { > diff --git a/include/filetype.h b/include/filetype.h > index cde543e5b061..e87ca174a89d 100644 > --- a/include/filetype.h > +++ b/include/filetype.h > @@ -2,6 +2,7 @@ > #define __FILE_TYPE_H > > #include <linux/string.h> > +#include <linux/types.h> > > /* > * List of file types we know > @@ -48,6 +49,7 @@ enum filetype file_name_detect_type(const char *filename); > enum filetype cdev_detect_type(const char *name); > enum filetype is_fat_or_mbr(const unsigned char *sector, unsigned long *bootsec); > int is_fat_boot_sector(const void *_buf); > +bool filetype_is_barebox_image(enum filetype ft); > > #define ARM_HEAD_SIZE 0x30 > #define ARM_HEAD_MAGICWORD_OFFSET 0x20 > -- > 2.7.0 > > > _______________________________________________ > barebox mailing list > barebox@lists.infradead.org > http://lists.infradead.org/mailman/listinfo/barebox > -- Pengutronix e.K. | | Industrial Linux Solutions | http://www.pengutronix.de/ | Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 | _______________________________________________ barebox mailing list barebox@lists.infradead.org http://lists.infradead.org/mailman/listinfo/barebox ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v2 4/4] fastboot: Add a ARM Barebox filetype handler 2016-02-18 8:22 ` Michael Olbrich @ 2016-02-19 7:44 ` Sascha Hauer 0 siblings, 0 replies; 7+ messages in thread From: Sascha Hauer @ 2016-02-19 7:44 UTC (permalink / raw) To: barebox On Thu, Feb 18, 2016 at 09:22:54AM +0100, Michael Olbrich wrote: > > + if (filetype_is_barebox_image(filetype)) { > > + struct bbu_data data = { > > + .devicefile = filename, > > + .imagefile = FASTBOOT_TMPFILE, > > + .flags = BBU_FLAG_YES, > > + }; > > + > > + if (!barebox_update_handler_exists(&data)) > > + goto copy; > > + > > + fastboot_tx_print(f_fb, "INFOThis is an ARM Barebox image..."); > > With the change above, it may not be an _ARM_ image. Fixed while applying. Sascha -- Pengutronix e.K. | | Industrial Linux Solutions | http://www.pengutronix.de/ | Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 | _______________________________________________ barebox mailing list barebox@lists.infradead.org http://lists.infradead.org/mailman/listinfo/barebox ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v2 4/4] fastboot: Add a ARM Barebox filetype handler 2016-02-17 11:28 ` [PATCH v2 4/4] fastboot: Add a ARM Barebox filetype handler Markus Pargmann 2016-02-18 8:22 ` Michael Olbrich @ 2016-03-11 7:07 ` Sascha Hauer 1 sibling, 0 replies; 7+ messages in thread From: Sascha Hauer @ 2016-03-11 7:07 UTC (permalink / raw) To: Markus Pargmann; +Cc: barebox On Wed, Feb 17, 2016 at 12:28:20PM +0100, Markus Pargmann wrote: > + if (filetype_is_barebox_image(filetype)) { > + struct bbu_data data = { > + .devicefile = filename, > + .imagefile = FASTBOOT_TMPFILE, > + .flags = BBU_FLAG_YES, > + }; > + > + if (!barebox_update_handler_exists(&data)) > + goto copy; > + > + fastboot_tx_print(f_fb, "INFOThis is an ARM Barebox image..."); > + > + data.image = read_file(data.imagefile, &data.len); > + if (!data.image) { > + fastboot_tx_print(f_fb, "FAILreading barebox"); > + return; > + } > + > + ret = barebox_update(&data); data.image must be freed after use. Added this. Sascha -- Pengutronix e.K. | | Industrial Linux Solutions | http://www.pengutronix.de/ | Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 | _______________________________________________ barebox mailing list barebox@lists.infradead.org http://lists.infradead.org/mailman/listinfo/barebox ^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2016-03-11 7:07 UTC | newest] Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2016-02-17 11:28 [PATCH v2 1/4] bbu: Add barebox_update search by device Markus Pargmann 2016-02-17 11:28 ` [PATCH v2 2/4] bbu: Add function to check if an update handler exists Markus Pargmann 2016-02-17 11:28 ` [PATCH v2 3/4] fastboot: Fix usage of ubiformat for UBI image transfers Markus Pargmann 2016-02-17 11:28 ` [PATCH v2 4/4] fastboot: Add a ARM Barebox filetype handler Markus Pargmann 2016-02-18 8:22 ` Michael Olbrich 2016-02-19 7:44 ` Sascha Hauer 2016-03-11 7:07 ` Sascha Hauer
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox