Skip to contentSkip to conversation

Support for Fastboot over UDP

PATCH In review Daniel Glöckner 2 participants 17 messages May 14, 2020 – May 20, 2020

Subsystems (10)
lore
Share & tools
lore
#1 lore raw

PATCH v2 1/10 Remove CONFIG_SLICE

In reply to Daniel Glöckner

Since we are unconditionally compiling and linking the slice code, it does not make sense to have a config option that depends on CONFIG_POLLER. The CONFIG_SLICE option was also broken because it was missing the "bool" line to denote its type.

---
 commands/Kconfig | 1 -
 common/Kconfig   | 4 ----
 2 files changed, 5 deletions(-)
commands/Kconfig +0 -1
index 5ff645442..33bc4743b 100644
@@ -272,7 +272,6 @@ config CMD_POLLER
 config CMD_SLICE
 	tristate
 	prompt "slice"
-	depends on SLICE
 	help
 	  slices are a way to protect resources from being accessed by pollers. The slice
 	  command can be used to print informations about slices and also to manipulate
common/Kconfig +0 -4
index bd2aebac7..400c0553c 100644
@@ -913,10 +913,6 @@ config BAREBOXCRC32_TARGET
 config POLLER
 	bool "generic polling infrastructure"
 
-config SLICE
-	depends on POLLER
-	default y
-
 config STATE
 	bool "generic state infrastructure"
 	select CRC32
Signature · 7 lines
2.17.1


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#2 lore raw

PATCH v2 2/10 net: fixed-link phys are never acquired

In reply to Daniel Glöckner

Fixed-link phys have their bus field set to NULL. This causes a crash when phy_acquired tries to check the slice of the bus.

---
 include/linux/phy.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/phy.h +1 -1
index e93f6a01f..3f0f31b35 100644
@@ -370,7 +370,7 @@ void phy_write_mmd_indirect(struct phy_device *phydev, int prtad, int devad,
 
 static inline bool phy_acquired(struct phy_device *phydev)
 {
-	return phydev && slice_acquired(&phydev->bus->slice);
+	return phydev && phydev->bus && slice_acquired(&phydev->bus->slice);
 }
 
 #ifdef CONFIG_PHYLIB
Signature · 7 lines
2.17.1


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#0 lore raw

v2 cover Support for Fastboot over UDP

This v2 of the Fastboot over UDP code is based on the slice patch series posted on April 22. Strictly necessary for Fastboot over UDP are only the patches 4, 6, 8, and 9. The others touch related code but can be omitted if desired.

Changes since v1:
- Add idle slice to execute commands when barebox is idle
- Use second poller to send keep-alive messages
- Share all settings in global variables with USB gadget and move them to a protocol agnostic variable namespace
- Use eth_open function added recently
- Minor cleanups

Daniel Glöckner (8):
Remove CONFIG_SLICE
net: fixed-link phys are never acquired
poller: adapt remaining users to API change Introduce idle slice
ratp: use poller to run ratp commands
defconfigs: update renamed fastboot options
fastboot: rename usbgadget.fastboot_* variables to fastboot.*
fastboot: don't close fd 0 when downloading to ram

Edmund Henniges (2):
fastboot: split generic code from USB gadget
fastboot net: implement fastboot over UDP

 Documentation/user/usb.rst               |   4 +-
 arch/arm/boards/mioa701/gpio0_poweroff.c |   2 +-
 arch/arm/boards/sama5d3xek/init.c        |   2 +-
 arch/arm/configs/imx23_defconfig         |   2 +-
 arch/arm/configs/imx28_defconfig         |   2 +-
 arch/arm/configs/imx_v7_defconfig        |   2 +-
 arch/arm/configs/imx_v8_defconfig        |   2 +-
 arch/arm/configs/kindle-mx50_defconfig   |   2 +-
 arch/arm/configs/omap_defconfig          |   2 +-
 arch/arm/configs/zii_vf610_dev_defconfig |   2 +-
 commands/Kconfig                         |   1 -
 commands/usbgadget.c                     |   2 +-
 common/Kconfig                           |  46 +-
 common/Makefile                          |   1 +
 common/binfmt.c                          |   3 +
 common/command.c                         |   3 +
 common/console_countdown.c               |   3 +
 common/fastboot.c                        | 972 +++++++++++++++++++++++
 common/poller.c                          |   2 +
 common/ratp/ratp.c                       |  12 +-
 common/slice.c                           |  24 +
 common/usbgadget.c                       |  16 +-
 drivers/net/usb/ax88179_178a.c           |   2 +-
 drivers/usb/gadget/Kconfig               |  36 +-
 drivers/usb/gadget/f_fastboot.c          | 970 +---------------------
 drivers/usb/gadget/multi.c               |   5 +-
 include/fastboot.h                       |  70 ++
 include/fastboot_net.h                   |  12 +
 include/linux/phy.h                      |   2 +-
 include/ratp_bb.h                        |   1 -
 include/slice.h                          |  10 +
 include/usb/fastboot.h                   |  34 +-
 include/usb/gadget-multi.h               |   2 +-
 lib/Kconfig                              |   1 +
 lib/readline.c                           |   9 +-
 net/Kconfig                              |  18 +
 net/Makefile                             |   1 +
 net/fastboot.c                           | 496 ++++++++++++
 38 files changed, 1738 insertions(+), 1038 deletions(-)
 create mode 100644 common/fastboot.c
 create mode 100644 include/fastboot.h
 create mode 100644 include/fastboot_net.h
 create mode 100644 net/fastboot.c
Signature · 7 lines
2.17.1


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#3 lore raw

PATCH v2 3/10 poller: adapt remaining users to API change

poller_register now has a second parameter.

---
 arch/arm/boards/mioa701/gpio0_poweroff.c | 2 +-
 arch/arm/boards/sama5d3xek/init.c        | 2 +-
 drivers/net/usb/ax88179_178a.c           | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)
arch/arm/boards/mioa701/gpio0_poweroff.c +1 -1
index 01a5d0cc6..279da5e0a 100644
@@ -76,7 +76,7 @@ static struct poller_struct gpio0_poller = {
 
 static int gpio0_poweroff_probe(void)
 {
-	return poller_register(&gpio0_poller);
+	return poller_register(&gpio0_poller, "power-button");
 }
 
 device_initcall(gpio0_poweroff_probe);
arch/arm/boards/sama5d3xek/init.c +1 -1
index c768e98d2..d9be4c5f9 100644
@@ -408,7 +408,7 @@ static void ek_add_device_hdmi(void)
 	hdmi_reset_start = get_time_ns();
 	hdmi_poller.func = hdmi_off_poller;
 
-	poller_register(&hdmi_poller);
+	poller_register(&hdmi_poller, "hdmi-reset");
 }
 #else
 static void ek_add_device_hdmi(void)
drivers/net/usb/ax88179_178a.c +1 -1
index 6fea5a7b1..fddb18714 100644
@@ -409,7 +409,7 @@ static int ax88179_bind(struct usbnet *dev)
 
 	priv->last = get_time_ns();
 	priv->poller.func = ax88179_poller;
-	poller_register(&priv->poller);
+	poller_register(&priv->poller, dev_name(&dev->udev->dev));
 
 	return 0;
 }
Signature · 7 lines
2.17.1


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#4 lore raw

PATCH v2 4/10 Introduce idle slice

In reply to Daniel Glöckner

Some code can't foresee which resources will be used by its poller. This is the case especially in pollers that will execute arbitrary commands input by the user. With this commit a special slice is introduced that is released only when Barebox is waiting for console input and only when it is doing that outside of any command. Code that wants to depend on the idle slice must select CONFIG_IDLE_SLICE to make it available.

---
 common/Kconfig             |  4 ++++
 common/binfmt.c            |  3 +++
 common/command.c           |  3 +++
 common/console_countdown.c |  3 +++
 common/poller.c            |  2 ++
 common/slice.c             | 24 ++++++++++++++++++++++++
 include/slice.h            | 10 ++++++++++
 lib/readline.c             |  8 +++++++-
 8 files changed, 56 insertions(+), 1 deletion(-)
common/Kconfig +4 -0
index 400c0553c..2fa9140de 100644
@@ -913,6 +913,10 @@ config BAREBOXCRC32_TARGET
 config POLLER
 	bool "generic polling infrastructure"
 
+config IDLE_SLICE
+	bool
+	default n
+
 config STATE
 	bool "generic state infrastructure"
 	select CRC32
common/binfmt.c +3 -0
index f2ff62458..899f270d4 100644
@@ -10,6 +10,7 @@
 #include <malloc.h>
 #include <command.h>
 #include <errno.h>
+#include <slice.h>
 
 static LIST_HEAD(binfmt_hooks);
 
@@ -23,7 +24,9 @@ static int binfmt_run(char *file, int argc, char **argv)
 		if (b->type != type)
 			continue;
 
+		idle_slice_acquire();
 		ret = b->hook(b, file, argc, argv);
+		idle_slice_release();
 		if (ret != -ERESTARTNOHAND)
 			return ret;
 	}
common/command.c +3 -0
index 49845938a..2b10248f5 100644
@@ -30,6 +30,7 @@
 #include <init.h>
 #include <complete.h>
 #include <getopt.h>
+#include <slice.h>
 
 LIST_HEAD(command_list);
 EXPORT_SYMBOL(command_list);
@@ -72,7 +73,9 @@ int execute_command(int argc, char **argv)
 	/* Look up command in command table */
 	if ((cmdtp = find_cmd(argv[0]))) {
 		/* OK - call function to do the command */
+		idle_slice_acquire();
 		ret = cmdtp->cmd(argc, argv);
+		idle_slice_release();
 		if (ret == COMMAND_ERROR_USAGE) {
 			barebox_cmd_usage(cmdtp);
 			ret = COMMAND_ERROR;
common/console_countdown.c +3 -0
index 8d09894c3..f161cf7df 100644
@@ -22,6 +22,7 @@
 #include <errno.h>
 #include <console_countdown.h>
 #include <stdio.h>
+#include <slice.h>
 
 static bool console_countdown_timeout_abort;
 
@@ -59,6 +60,7 @@ int console_countdown(int timeout_s, unsigned flags, const char *keys,
 	if (!(flags & CONSOLE_COUNTDOWN_SILENT))
 		printf("%4d", countdown--);
 
+	idle_slice_release();
 	do {
 		if (tstc()) {
 			key = getchar();
@@ -91,6 +93,7 @@ int console_countdown(int timeout_s, unsigned flags, const char *keys,
 	ret = 0;
 
  out:
+	idle_slice_acquire();
 	if (!(flags & CONSOLE_COUNTDOWN_SILENT))
 		printf("\n");
 	if (key && out_key)
common/poller.c +2 -0
index cccffcb88..60a3461b2 100644
@@ -116,7 +116,9 @@ void poller_call(void)
 			continue;
 
 		slice_acquire(&poller->slice);
+		idle_slice_acquire();
 		poller->func(poller);
+		idle_slice_release();
 		slice_release(&poller->slice);
 	}
 }
common/slice.c +24 -0
index b4460335d..960bb2ff8 100644
@@ -3,6 +3,7 @@
 #define pr_fmt(fmt) "slice: " fmt
 
 #include <common.h>
+#include <init.h>
 #include <slice.h>
 
 /*
@@ -221,6 +222,29 @@ void slice_init(struct slice *slice, const char *name)
 	list_add_tail(&slice->list, &slices);
 }
 
+#ifdef CONFIG_IDLE_SLICE
+struct slice idle_slice;
+
+void idle_slice_acquire(void)
+{
+	slice_acquire(&idle_slice);
+}
+
+void idle_slice_release(void)
+{
+	slice_release(&idle_slice);
+}
+
+static int idle_slice_init(void)
+{
+	slice_init(&idle_slice, "idle");
+	slice_acquire(&idle_slice);
+	return 0;
+}
+
+pure_initcall(idle_slice_init);
+#endif
+
 #if defined CONFIG_CMD_SLICE
 
 #include <command.h>
include/slice.h +10 -0
index 4874f1afc..068daaa7c 100644
@@ -28,4 +28,14 @@ void slice_init(struct slice *slice, const char *name);
 
 void slice_debug_acquired(struct slice *slice);
 
+#ifdef CONFIG_IDLE_SLICE
+extern struct slice idle_slice;
+
+void idle_slice_acquire(void);
+void idle_slice_release(void);
+#else
+static inline void idle_slice_acquire(void) {}
+static inline void idle_slice_release(void) {}
+#endif
+
 #endif /* __SLICE_H */
lib/readline.c +7 -1
index 3d16c1838..709efb375 100644
@@ -3,6 +3,7 @@
 #include <init.h>
 #include <libbb.h>
 #include <poller.h>
+#include <slice.h>
 #include <ratp_bb.h>
 #include <xfuncs.h>
 #include <complete.h>
@@ -200,11 +201,16 @@ int readline(const char *prompt, char *buf, int len)
 	puts (prompt);
 
 	while (1) {
+		idle_slice_release();
 		while (!tstc()) {
 			poller_call();
-			if (IS_ENABLED(CONFIG_CONSOLE_RATP))
+			if (IS_ENABLED(CONFIG_CONSOLE_RATP)) {
+				idle_slice_acquire();
 				barebox_ratp_command_run();
+				idle_slice_release();
+			}
 		}
+		idle_slice_acquire();
 
 		ichar = read_key();
 
Signature · 7 lines
2.17.1


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#8 lore raw

PATCH v2 7/10 defconfigs: update renamed fastboot options

In reply to Daniel Glöckner

The split of the generic Fastboot code from the Fastboot USB gadget included renaming the CONFIG_USB_GADGET_FASTBOOT_* options to CONFIG_FASTBOOT_*. Update all defconfigs to use the new names.

---
 arch/arm/configs/imx23_defconfig         | 2 +-
 arch/arm/configs/imx28_defconfig         | 2 +-
 arch/arm/configs/imx_v7_defconfig        | 2 +-
 arch/arm/configs/imx_v8_defconfig        | 2 +-
 arch/arm/configs/kindle-mx50_defconfig   | 2 +-
 arch/arm/configs/omap_defconfig          | 2 +-
 arch/arm/configs/zii_vf610_dev_defconfig | 2 +-
 7 files changed, 7 insertions(+), 7 deletions(-)
arch/arm/configs/imx23_defconfig +1 -1
index bff9c08c4..48bf14a39 100644
@@ -22,6 +22,7 @@ CONFIG_BLSPEC=y
 CONFIG_CONSOLE_ALLOW_COLOR=y
 CONFIG_DEFAULT_ENVIRONMENT_GENERIC_NEW=y
 CONFIG_RESET_SOURCE=y
+CONFIG_FASTBOOT_CMD_OEM=y
 CONFIG_CMD_DMESG=y
 CONFIG_LONGHELP=y
 CONFIG_CMD_IOMEM=y
@@ -90,7 +91,6 @@ CONFIG_USB_GADGET=y
 CONFIG_USB_GADGET_DFU=y
 CONFIG_USB_GADGET_SERIAL=y
 CONFIG_USB_GADGET_FASTBOOT=y
-CONFIG_USB_GADGET_FASTBOOT_CMD_OEM=y
 CONFIG_VIDEO=y
 CONFIG_DRIVER_VIDEO_STM=y
 CONFIG_MCI=y
arch/arm/configs/imx28_defconfig +1 -1
index 1acc8dd94..b35694f50 100644
@@ -23,6 +23,7 @@ CONFIG_BLSPEC=y
 CONFIG_CONSOLE_ALLOW_COLOR=y
 CONFIG_DEFAULT_ENVIRONMENT_GENERIC_NEW=y
 CONFIG_RESET_SOURCE=y
+CONFIG_FASTBOOT_CMD_OEM=y
 CONFIG_CMD_DMESG=y
 CONFIG_LONGHELP=y
 CONFIG_CMD_IOMEM=y
@@ -93,7 +94,6 @@ CONFIG_USB_GADGET=y
 CONFIG_USB_GADGET_DFU=y
 CONFIG_USB_GADGET_SERIAL=y
 CONFIG_USB_GADGET_FASTBOOT=y
-CONFIG_USB_GADGET_FASTBOOT_CMD_OEM=y
 CONFIG_VIDEO=y
 CONFIG_DRIVER_VIDEO_STM=y
 CONFIG_MCI=y
arch/arm/configs/imx_v7_defconfig +1 -1
index 5bf908ee8..fb7872434 100644
@@ -66,6 +66,7 @@ CONFIG_CONSOLE_ACTIVATE_NONE=y
 CONFIG_PARTITION_DISK_EFI=y
 CONFIG_DEFAULT_ENVIRONMENT_GENERIC_NEW=y
 CONFIG_RESET_SOURCE=y
+CONFIG_FASTBOOT_CMD_OEM=y
 CONFIG_CMD_DMESG=y
 CONFIG_LONGHELP=y
 CONFIG_CMD_IOMEM=y
@@ -160,7 +161,6 @@ CONFIG_USB_GADGET=y
 CONFIG_USB_GADGET_DFU=y
 CONFIG_USB_GADGET_SERIAL=y
 CONFIG_USB_GADGET_FASTBOOT=y
-CONFIG_USB_GADGET_FASTBOOT_CMD_OEM=y
 CONFIG_VIDEO=y
 CONFIG_DRIVER_VIDEO_IMX_IPUV3=y
 CONFIG_DRIVER_VIDEO_IMX_IPUV3_LVDS=y
arch/arm/configs/imx_v8_defconfig +1 -1
index 06fb40608..b96867ad0 100644
@@ -25,6 +25,7 @@ CONFIG_CONSOLE_RATP=y
 CONFIG_PARTITION_DISK_EFI=y
 CONFIG_DEFAULT_ENVIRONMENT_GENERIC_NEW=y
 CONFIG_RESET_SOURCE=y
+CONFIG_FASTBOOT_SPARSE=y
 CONFIG_CMD_DMESG=y
 CONFIG_LONGHELP=y
 CONFIG_CMD_IOMEM=y
@@ -106,7 +107,6 @@ CONFIG_USB_STORAGE=y
 CONFIG_USB_GADGET=y
 CONFIG_USB_GADGET_SERIAL=y
 CONFIG_USB_GADGET_FASTBOOT=y
-CONFIG_USB_GADGET_FASTBOOT_SPARSE=y
 CONFIG_MCI=y
 CONFIG_MCI_MMC_BOOT_PARTITIONS=y
 CONFIG_MCI_IMX_ESDHC=y
arch/arm/configs/kindle-mx50_defconfig +1 -1
index 855daef71..552b2d6d3 100644
@@ -20,6 +20,7 @@ CONFIG_BOOTM_OFTREE=y
 CONFIG_CONSOLE_ACTIVATE_ALL=y
 CONFIG_CONSOLE_ALLOW_COLOR=y
 CONFIG_DEFAULT_ENVIRONMENT_GENERIC_NEW=y
+CONFIG_FASTBOOT_CMD_OEM=y
 CONFIG_CMD_DMESG=y
 CONFIG_LONGHELP=y
 CONFIG_CMD_MEMINFO=y
@@ -50,7 +51,6 @@ CONFIG_USB_EHCI=y
 CONFIG_USB_GADGET=y
 CONFIG_USB_GADGET_SERIAL=y
 CONFIG_USB_GADGET_FASTBOOT=y
-CONFIG_USB_GADGET_FASTBOOT_CMD_OEM=y
 CONFIG_MCI=y
 CONFIG_MCI_STARTUP=y
 CONFIG_MCI_MMC_BOOT_PARTITIONS=y
arch/arm/configs/omap_defconfig +1 -1
index 9d71d0274..59892cb23 100644
@@ -34,6 +34,7 @@ CONFIG_DEFAULT_ENVIRONMENT_GENERIC_NEW=y
 CONFIG_STATE=y
 CONFIG_BOOTCHOOSER=y
 CONFIG_RESET_SOURCE=y
+CONFIG_FASTBOOT_CMD_OEM=y
 CONFIG_LONGHELP=y
 CONFIG_CMD_IOMEM=y
 CONFIG_CMD_MEMINFO=y
@@ -121,7 +122,6 @@ CONFIG_USB_GADGET=y
 CONFIG_USB_GADGET_DFU=y
 CONFIG_USB_GADGET_SERIAL=y
 CONFIG_USB_GADGET_FASTBOOT=y
-CONFIG_USB_GADGET_FASTBOOT_CMD_OEM=y
 CONFIG_USB_MUSB=y
 CONFIG_USB_MUSB_AM335X=y
 CONFIG_USB_MUSB_HOST=y
arch/arm/configs/zii_vf610_dev_defconfig +1 -1
index 7161d740a..45c24d6df 100644
@@ -22,6 +22,7 @@ CONFIG_CONSOLE_RATP=y
 CONFIG_PARTITION_DISK_EFI=y
 CONFIG_DEFAULT_ENVIRONMENT_GENERIC_NEW=y
 CONFIG_RESET_SOURCE=y
+CONFIG_FASTBOOT_CMD_OEM=y
 CONFIG_CMD_DMESG=y
 CONFIG_LONGHELP=y
 CONFIG_CMD_IOMEM=y
@@ -113,7 +114,6 @@ CONFIG_USB_GADGET=y
 CONFIG_USB_GADGET_DFU=y
 CONFIG_USB_GADGET_SERIAL=y
 CONFIG_USB_GADGET_FASTBOOT=y
-CONFIG_USB_GADGET_FASTBOOT_CMD_OEM=y
 CONFIG_MCI=y
 CONFIG_MCI_MMC_BOOT_PARTITIONS=y
 CONFIG_MCI_IMX_ESDHC=y
Signature · 7 lines
2.17.1


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#6 lore raw

PATCH v2 5/10 ratp: use poller to run ratp commands

In reply to Daniel Glöckner

With the new idle slice there is no longer a need to have a dedicated hook for RATP inside readline. Switch to a poller that depends on the idle slice to execute the commands received over RATP.

---
 common/ratp/ratp.c | 12 +++++++++++-
 include/ratp_bb.h  |  1 -
 lib/Kconfig        |  1 +
 lib/readline.c     |  9 +--------
 4 files changed, 13 insertions(+), 10 deletions(-)
common/ratp/ratp.c +11 -1
index 9625a31b1..9b3ea0f98 100644
@@ -53,6 +53,7 @@ struct ratp_ctx {
 	struct ratp_bb_pkt *fs_rx;
 
 	struct poller_struct poller;
+	struct poller_struct execution_poller;
 };
 
 static int compare_ratp_command(struct list_head *a, struct list_head *b)
@@ -302,7 +303,7 @@ static int ratp_console_register(struct ratp_ctx *ctx)
 	return 0;
 }
 
-void barebox_ratp_command_run(void)
+static void barebox_ratp_command_run(struct poller_struct *poller)
 {
 	int ret;
 
@@ -336,6 +337,7 @@ static void ratp_console_unregister(struct ratp_ctx *ctx)
 	int ret;
 
 	console_set_active(&ctx->ratp_console, 0);
+	poller_unregister(&ctx->execution_poller);
 	poller_unregister(&ctx->poller);
 	ratp_close(&ctx->ratp);
 	console_set_active(ctx->cdev, ctx->old_active);
@@ -436,6 +438,7 @@ int barebox_ratp(struct console_device *cdev)
 		ctx->console_recv_fifo = kfifo_alloc(512);
 		ctx->console_transmit_fifo = kfifo_alloc(SZ_128K);
 		ctx->poller.func = ratp_poller;
+		ctx->execution_poller.func = barebox_ratp_command_run;
 		ratp_console_register(ctx);
 	}
 
@@ -458,11 +461,18 @@ int barebox_ratp(struct console_device *cdev)
 	if (ret)
 		goto out1;
 
+	ret = poller_register(&ctx->execution_poller, "ratp-exec");
+	if (ret)
+		goto out2;
+
+	slice_add(&ctx->execution_poller.slice, &idle_slice);
 	console_set_active(&ctx->ratp_console, CONSOLE_STDOUT | CONSOLE_STDERR |
 			CONSOLE_STDIN);
 
 	return 0;
 
+out2:
+	poller_unregister(&ctx->poller);
 out1:
 	ratp_close(ratp);
 out:
include/ratp_bb.h +0 -1
index a4f28c642..b710f99bf 100644
@@ -41,7 +41,6 @@ struct ratp_bb_pkt {
 };
 
 int  barebox_ratp(struct console_device *cdev);
-void barebox_ratp_command_run(void);
 int  barebox_ratp_fs_call(struct ratp_bb_pkt *tx, struct ratp_bb_pkt **rx);
 int  barebox_ratp_fs_mount(const char *path);
 
lib/Kconfig +1 -0
index 9a8078018..d60c6ce2d 100644
@@ -108,6 +108,7 @@ config RATP
 	select COMPILE_MEMORY
 	select COMMAND_SUPPORT
 	select POLLER
+	select IDLE_SLICE
 	depends on CONSOLE_FULL
 	depends on !SHELL_NONE
 	bool "RATP protocol support"
lib/readline.c +1 -8
index 709efb375..79bac6f42 100644
@@ -4,7 +4,6 @@
 #include <libbb.h>
 #include <poller.h>
 #include <slice.h>
-#include <ratp_bb.h>
 #include <xfuncs.h>
 #include <complete.h>
 #include <linux/ctype.h>
@@ -202,14 +201,8 @@ int readline(const char *prompt, char *buf, int len)
 
 	while (1) {
 		idle_slice_release();
-		while (!tstc()) {
+		while (!tstc())
 			poller_call();
-			if (IS_ENABLED(CONFIG_CONSOLE_RATP)) {
-				idle_slice_acquire();
-				barebox_ratp_command_run();
-				idle_slice_release();
-			}
-		}
 		idle_slice_acquire();
 
 		ichar = read_key();
Signature · 7 lines
2.17.1


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#9 lore raw

PATCH v2 8/10 fastboot: rename usbgadget.fastboot_* variables to fastboot.*

In reply to Daniel Glöckner

There is nothing USB-specific in the defined usbgadget.fastboot_* variables. Rename them to be usable also for the UDP fastboot transport.

The usbgadget.fastboot_function variable is used to define the files and devices accessible with the erase and flash commands. Since "function" is a term from the USB specification and the Fastboot specification uses the term "partition", we rename that variable to "fastboot.partitions".

---
 Documentation/user/usb.rst |  4 ++--
 commands/usbgadget.c       |  2 +-
 common/fastboot.c          | 15 +++++++++++++--
 common/usbgadget.c         | 16 ++--------------
 include/fastboot.h         |  3 +++
 5 files changed, 21 insertions(+), 19 deletions(-)
Documentation/user/usb.rst +2 -2
index 4c1b2925f..ca5f8138d 100644
@@ -266,7 +266,7 @@ USB Gadget autostart Options
   See :ref:`command_usbgadget` -a. (Default 0).
 ``global.usbgadget.dfu_function``
   Function description for DFU. See :ref:`command_usbgadget` -D [desc].
-``global.usbgadget.fastboot_function``
+``global.fastboot.partitions``
   Function description for fastboot. See :ref:`command_usbgadget` -A [desc].
-``global.usbgadget.fastboot_bbu``
+``global.fastboot.bbu``
   Export barebox update handlers. See :ref:`command_usbgadget` -b. (Default 0).
commands/usbgadget.c +1 -1
index e8e1e9ada..4d3810f6f 100644
@@ -71,7 +71,7 @@ BAREBOX_CMD_HELP_TEXT("")
 BAREBOX_CMD_HELP_TEXT("Options:")
 BAREBOX_CMD_HELP_OPT ("-a\t", "Create CDC ACM function")
 BAREBOX_CMD_HELP_OPT ("-A <desc>", "Create Android Fastboot function. If 'desc' is not provided, "
-				   "try to use 'global.usbgadget.fastboot_function' variable.")
+				   "try to use 'global.fastboot.partitions' variable.")
 BAREBOX_CMD_HELP_OPT ("-b\t", "include registered barebox update handlers (fastboot specific)")
 BAREBOX_CMD_HELP_OPT ("-D <desc>", "Create DFU function. If 'desc' is not provided, "
 				   "try to use 'global.usbgadget.dfu_function' variable.")
common/fastboot.c +13 -2
index d58f68f1b..d50f61ff2 100644
@@ -48,6 +48,8 @@
 #define FASTBOOT_TMPFILE		"/.fastboot.img"
 
 static unsigned int fastboot_max_download_size = SZ_8M;
+int fastboot_bbu;
+char *fastboot_partitions;
 
 struct fb_variable {
 	char *name;
@@ -946,12 +948,21 @@ static int fastboot_globalvars_init(void)
 	if (IS_ENABLED(CONFIG_FASTBOOT_SPARSE))
 		globalvar_add_simple_int("usbgadget.fastboot_max_download_size",
 				 &fastboot_max_download_size, "%u");
+	globalvar_add_simple_bool("fastboot.bbu", &fastboot_bbu);
+	globalvar_add_simple_string("fastboot.partitions",
+				    &fastboot_partitions);
 
 	return 0;
 }
 
 device_initcall(fastboot_globalvars_init);
 
-BAREBOX_MAGICVAR_NAMED(global_usbgadget_fastboot_max_download_size,
-		       global.usbgadget.fastboot_max_download_size,
+BAREBOX_MAGICVAR_NAMED(global_fastboot_max_download_size,
+		       global.fastboot.max_download_size,
 		       "Fastboot maximum download size");
+BAREBOX_MAGICVAR_NAMED(global_fastboot_partitions,
+		       global.fastboot.partitions,
+		       "Partitions exported for update via fastboot");
+BAREBOX_MAGICVAR_NAMED(global_fastboot_bbu,
+		       global.fastboot.bbu,
+		       "Export barebox update handlers via fastboot");
common/usbgadget.c +2 -14
index a8f104cf1..25fd99493 100644
@@ -30,8 +30,6 @@
 static int autostart;
 static int acm;
 static char *dfu_function;
-static char *fastboot_function;
-static int fastboot_bbu;
 
 static struct file_list *parse(const char *files)
 {
@@ -56,8 +54,8 @@ int usbgadget_register(bool dfu, const char *dfu_opts,
 		dfu_opts = dfu_function;
 
 	if (fastboot && !fastboot_opts &&
-	    fastboot_function && *fastboot_function)
-		fastboot_opts = fastboot_function;
+	    fastboot_partitions && *fastboot_partitions)
+		fastboot_opts = fastboot_partitions;
 
 	if (!dfu_opts && !fastboot_opts && !acm)
 		return COMMAND_ERROR_USAGE;
@@ -116,12 +114,8 @@ static int usbgadget_globalvars_init(void)
 	if (IS_ENABLED(CONFIG_USB_GADGET_AUTOSTART)) {
 		globalvar_add_simple_bool("usbgadget.autostart", &autostart);
 		globalvar_add_simple_bool("usbgadget.acm", &acm);
-		globalvar_add_simple_bool("usbgadget.fastboot_bbu",
-					  &fastboot_bbu);
 	}
 	globalvar_add_simple_string("usbgadget.dfu_function", &dfu_function);
-	globalvar_add_simple_string("usbgadget.fastboot_function",
-				    &fastboot_function);
 
 	return 0;
 }
@@ -136,9 +130,3 @@ BAREBOX_MAGICVAR_NAMED(global_usbgadget_acm,
 BAREBOX_MAGICVAR_NAMED(global_usbgadget_dfu_function,
 		       global.usbgadget.dfu_function,
 		       "usbgadget: Create DFU function");
-BAREBOX_MAGICVAR_NAMED(global_usbgadget_fastboot_function,
-		       global.usbgadget.fastboot_function,
-		       "usbgadget: Create Android Fastboot function");
-BAREBOX_MAGICVAR_NAMED(global_usbgadget_fastboot_bbu,
-		       global.usbgadget.fastboot_bbu,
-		       "usbgadget: export barebox update handlers via fastboot");
include/fastboot.h +3 -0
index 3b6cae8a5..7df137bb8 100644
@@ -53,6 +53,9 @@ enum fastboot_msg_type {
 	FASTBOOT_MSG_DATA,
 };
 
+extern int fastboot_bbu;
+extern char *fastboot_partitions;
+
 int fastboot_generic_init(struct fastboot *fb, bool export_bbu);
 void fastboot_generic_close(struct fastboot *fb);
 void fastboot_generic_free(struct fastboot *fb);
Signature · 7 lines
2.17.1


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#16 lore raw

PATCH v2 10/10 fastboot: don't close fd 0 when downloading to ram

In reply to Daniel Glöckner

When downloading to a buffer, download_fd is never assigned a valid file descriptor. We should therefore avoid calling close on the value found in that variable.

---
 common/fastboot.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
common/fastboot.c +2 -1
index 706547309..3fcc69f62 100644
@@ -347,7 +347,8 @@ int fastboot_handle_download_data(struct fastboot *fb, const void *buffer,
 
 void fastboot_download_finished(struct fastboot *fb)
 {
-	close(fb->download_fd);
+	if (!fastboot_download_to_buf(fb))
+		close(fb->download_fd);
 
 	printf("\n");
 
Signature · 7 lines
2.17.1


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#7 lore raw

PATCH v2 6/10 fastboot: split generic code from USB gadget

In reply to Daniel Glöckner

From: Edmund Henniges <[email protected]>

The fastboot specification describes other protocols beyond USB. Allow these to reuse the generic parts of the existing fastboot code when they are implemented.

Most of the changes in common/fastboot.c are due to the renaming of struct f_fastboot *f_fb to struct fastboot *fb.

---
 common/Kconfig                  |  40 ++
 common/Makefile                 |   1 +
 common/fastboot.c               | 957 +++++++++++++++++++++++++++++++
 drivers/usb/gadget/Kconfig      |  36 +-
 drivers/usb/gadget/f_fastboot.c | 970 ++------------------------------
 drivers/usb/gadget/multi.c      |   5 +-
 include/fastboot.h              |  66 +++
 include/usb/fastboot.h          |  34 +-
 include/usb/gadget-multi.h      |   2 +-
 9 files changed, 1112 insertions(+), 999 deletions(-)
 create mode 100644 common/fastboot.c
 create mode 100644 include/fastboot.h
common/Kconfig +40 -0
index 2fa9140de..5388030be 100644
@@ -114,6 +114,9 @@ config USBGADGET_START
 config BOOT
 	bool
 
+config FASTBOOT_BASE
+	bool
+
 menu "General Settings"
 
 config LOCALVERSION
@@ -1017,6 +1020,43 @@ config PBL_OPTEE
 
 endmenu
 
+if FASTBOOT_BASE
+
+menu "Android Fastboot"
+
+config FASTBOOT_SPARSE
+	bool
+	select IMAGE_SPARSE
+	prompt "Enable Fastboot sparse image support"
+	help
+	  Sparse images are a way for the fastboot protocol to write
+	  images that are bigger than the available memory. If unsure,
+	  say yes here.
+
+config FASTBOOT_BUF
+	bool
+	prompt "Download files to temporary buffer instead of file"
+	help
+	  With this option enabled the fastboot code will download files to a
+	  temporary buffer instead of a temporary file. Normally you want to
+	  use a file as this also works when your memory is fragmented. However,
+	  in some special cases, when the file consumer also better copes with
+	  a buffer, then using a buffer might be better.
+
+	  Say no here unless you know what you are doing.
+
+config FASTBOOT_CMD_OEM
+	bool
+	prompt "Enable OEM commands"
+	help
+	  This option enables the fastboot "oem" group of commands. They allow to
+	  executing arbitrary barebox commands and may be disabled in secure
+	  environments.
+
+endmenu
+
+endif
+
 endmenu
 
 menu "Debugging"
common/Makefile +1 -0
index 16f14db41..f7834c6a5 100644
@@ -70,6 +70,7 @@ obj-$(CONFIG_SERIAL_DEV_BUS)	+= serdev.o
 obj-$(CONFIG_USBGADGET_START)	+= usbgadget.o
 pbl-$(CONFIG_PBL_OPTEE)		+= optee.o
 obj-$(CONFIG_BOOTM_OPTEE)	+= optee.o
+obj-$(CONFIG_FASTBOOT_BASE)	+= fastboot.o
 
 ifdef CONFIG_PASSWORD
 
common/fastboot.c new file +957 -0

957 lines not on this page · raw message

drivers/usb/gadget/Kconfig +2 -34
index 6e60c7aee..977f6c0db 100644
@@ -57,38 +57,6 @@ config USB_GADGET_FASTBOOT
 	bool
 	select BANNER
 	select FILE_LIST
-	prompt "Android Fastboot support"
-
-config USB_GADGET_FASTBOOT_SPARSE
-	bool
-	depends on USB_GADGET_FASTBOOT
-	select IMAGE_SPARSE
-	prompt "Enable Fastboot sparse image support"
-	help
-	  Sparse images are a way for the fastboot protocol to write
-	  images that are bigger than the available memory. If unsure,
-	  say yes here.
-
-config USB_GADGET_FASTBOOT_BUF
-	bool
-	depends on USB_GADGET_FASTBOOT
-	prompt "Download files to temporary buffer instead of file"
-	help
-	  With this option enabled the fastboot code will download files to a
-	  temporary buffer instead of a temporary file. Normally you want to
-	  use a file as this also works when your memory is fragmented. However,
-	  in some special cases, when the file consumer also better copes with
-	  a buffer, then using a buffer might be better.
-
-	  Say no here unless you know what you are doing.
-
-config USB_GADGET_FASTBOOT_CMD_OEM
-	bool
-	depends on USB_GADGET_FASTBOOT
-	prompt "Enable OEM commands"
-	help
-	  This option enables the fastboot "oem" group of commands. They allow to
-	  executing arbitrary barebox commands and may be disabled in secure
-	  environments.
-
+	select FASTBOOT_BASE
+	prompt "Android Fastboot USB Gadget"
 endif
drivers/usb/gadget/f_fastboot.c +41 -929

1,106 lines not on this page · raw message

drivers/usb/gadget/multi.c +1 -4
index d6edfb8cf..445cc3242 100644
@@ -127,10 +127,7 @@ static int multi_bind_fastboot(struct usb_composite_dev *cdev)
 	}
 
 	opts = container_of(fi_fastboot, struct f_fastboot_opts, func_inst);
-	opts->files = gadget_multi_opts->fastboot_opts.files;
-	opts->cmd_exec = gadget_multi_opts->fastboot_opts.cmd_exec;
-	opts->cmd_flash = gadget_multi_opts->fastboot_opts.cmd_flash;
-	opts->export_bbu = gadget_multi_opts->fastboot_opts.export_bbu;
+	opts->common = gadget_multi_opts->fastboot_opts;
 
 	f_fastboot = usb_get_function(fi_fastboot);
 	if (IS_ERR(f_fastboot)) {
include/fastboot.h new file +66 -0

66 lines not on this page · raw message

include/usb/fastboot.h +3 -31
index c0775c67d..a3609ba5d 100644
@@ -1,45 +1,17 @@
 #ifndef _USB_FASTBOOT_H
 #define _USB_FASTBOOT_H
 
-#include <linux/types.h>
-#include <file-list.h>
 #include <usb/composite.h>
-
-struct f_fastboot;
+#include <fastboot.h>
 
 /**
  * struct f_fastboot_opts - options to configure the fastboot gadget
+ * @common:	Options common to all fastboot protocol variants
  * @func_inst:	The USB function instance to register on
- * @files:	A file_list containing the files (partitions) to export via fastboot
- * @export_bbu:	Automatically include the partitions provided by barebox update (bbu)
  */
 struct f_fastboot_opts {
+	struct fastboot_opts common;
 	struct usb_function_instance func_inst;
-	struct file_list *files;
-	bool export_bbu;
-	int (*cmd_exec)(struct f_fastboot *, const char *cmd);
-	int (*cmd_flash)(struct f_fastboot *, struct file_list_entry *entry,
-			 const char *filename, const void *buf, size_t len);
-};
-
-/*
- * Return codes for the exec_cmd callback above:
- *
- * FASTBOOT_CMD_FALLTHROUGH - Not handled by the external command dispatcher,
- *                            handle it with internal dispatcher
- * Other than these negative error codes mean errors handling the command and
- * zero means the command has been successfully handled.
- */
-#define FASTBOOT_CMD_FALLTHROUGH	1
-
-enum fastboot_msg_type {
-	FASTBOOT_MSG_OKAY,
-	FASTBOOT_MSG_FAIL,
-	FASTBOOT_MSG_INFO,
-	FASTBOOT_MSG_DATA,
 };
 
-int fastboot_tx_print(struct f_fastboot *f_fb, enum fastboot_msg_type type,
-		      const char *fmt, ...);
-
 #endif /* _USB_FASTBOOT_H */
include/usb/gadget-multi.h +1 -1
index 030e604fe..9bb6c889f 100644
@@ -6,7 +6,7 @@
 #include <usb/usbserial.h>
 
 struct f_multi_opts {
-	struct f_fastboot_opts fastboot_opts;
+	struct fastboot_opts fastboot_opts;
 	struct f_dfu_opts dfu_opts;
 	int create_acm;
 	void (*release)(struct f_multi_opts *opts);
Signature · 7 lines
2.17.1


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#11 lore raw

PATCH v2 9/10 fastboot net: implement fastboot over UDP

In reply to Daniel Glöckner

From: Edmund Henniges <[email protected]>

This implements the UDP variant of the fastboot protocol. The only way to start the service for now is to compile with CONFIG_FASTBOOT_NET_ON_BOOT. The service will bind to the network interface that provides the IPv4 gateway.

Sending an OKAY packet before performing a restart is necessary since contrary to USB the host will not notice when a UDP server disappears.

---
 common/fastboot.c      |   3 +
 include/fastboot.h     |   1 +
 include/fastboot_net.h |  12 +
 net/Kconfig            |  18 ++
 net/Makefile           |   1 +
 net/fastboot.c         | 496 +++++++++++++++++++++++++++++++++++++++++
 6 files changed, 531 insertions(+)
 create mode 100644 include/fastboot_net.h
 create mode 100644 net/fastboot.c
common/fastboot.c +3 -0
index d50f61ff2..706547309 100644
@@ -247,6 +247,7 @@ static char *fastboot_msg[] = {
 	[FASTBOOT_MSG_FAIL] = "FAIL",
 	[FASTBOOT_MSG_INFO] = "INFO",
 	[FASTBOOT_MSG_DATA] = "DATA",
+	[FASTBOOT_MSG_NONE] = "",
 };
 
 int fastboot_tx_print(struct fastboot *fb, enum fastboot_msg_type type,
@@ -275,6 +276,7 @@ int fastboot_tx_print(struct fastboot *fb, enum fastboot_msg_type type,
 	case FASTBOOT_MSG_INFO:
 		pr_info("%pV\n", &vaf);
 		break;
+	case FASTBOOT_MSG_NONE:
 	case FASTBOOT_MSG_DATA:
 		break;
 	}
@@ -289,6 +291,7 @@ int fastboot_tx_print(struct fastboot *fb, enum fastboot_msg_type type,
 
 static void cb_reboot(struct fastboot *fb, const char *cmd)
 {
+	fastboot_tx_print(fb, FASTBOOT_MSG_OKAY, "");
 	restart_machine();
 }
 
include/fastboot.h +1 -0
index 7df137bb8..eb1971209 100644
@@ -51,6 +51,7 @@ enum fastboot_msg_type {
 	FASTBOOT_MSG_FAIL,
 	FASTBOOT_MSG_INFO,
 	FASTBOOT_MSG_DATA,
+	FASTBOOT_MSG_NONE,
 };
 
 extern int fastboot_bbu;
include/fastboot_net.h new file +12 -0
new file mode 100644
index 000000000..e4b9d9809
@@ -0,0 +1,12 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+#ifndef __FASTBOOT_NET__
+#define __FASTBOOT_NET__
+
+#include <fastboot.h>
+
+struct fastboot_net;
+
+struct fastboot_net *fastboot_net_init(struct fastboot_opts *opts);
+void fastboot_net_free(struct fastboot_net *fbn);
+
+#endif
net/Kconfig +18 -0
index 12b6bdb56..4ed5c6de9 100644
@@ -31,4 +31,22 @@ config NET_SNTP
 	bool
 	prompt "sntp support"
 
+config NET_FASTBOOT
+	bool
+	select BANNER
+	select FILE_LIST
+	select FASTBOOT_BASE
+	select IDLE_SLICE
+	prompt "Android Fastboot support"
+	help
+	  This option adds support for the UDP variant of the Fastboot
+	  protocol.
+
+config FASTBOOT_NET_ON_BOOT
+	bool
+	depends on NET_FASTBOOT
+	prompt "Start network fastboot during boot"
+	help
+	  Automatically starts the network and listens for Fastboot packets.
+	  The list of accessible files is taken from global.fastboot.partitions.
 endif
net/Makefile +1 -0
index eb8d43915..962b2dec5 100644
@@ -8,3 +8,4 @@ obj-$(CONFIG_CMD_PING)	+= ping.o
 obj-$(CONFIG_NET_RESOLV)+= dns.o
 obj-$(CONFIG_NET_NETCONSOLE) += netconsole.o
 obj-$(CONFIG_NET_IFUP)	+= ifup.o
+obj-$(CONFIG_NET_FASTBOOT) += fastboot.o
net/fastboot.c new file +496 -0

496 lines not on this page · raw message

Signature · 7 lines
2.17.1


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
maintainer
#10 lore raw

Re: [PATCH v2 08/10] fastboot: rename usbgadget.fastboot_* variables to fastboot.*

In reply to Daniel Glöckner
Quoted 18 lines · Daniel Glöckner

There is nothing USB-specific in the defined usbgadget.fastboot_* variables. Rename them to be usable also for the UDP fastboot transport.

The usbgadget.fastboot_function variable is used to define the files and devices accessible with the erase and flash commands. Since "function" is a term from the USB specification and the Fastboot specification uses the term "partition", we rename that variable to "fastboot.partitions".

---
 Documentation/user/usb.rst |  4 ++--
 commands/usbgadget.c       |  2 +-
 common/fastboot.c          | 15 +++++++++++++--
 common/usbgadget.c         | 16 ++--------------
 include/fastboot.h         |  3 +++
 5 files changed, 21 insertions(+), 19 deletions(-)

Documentation/user/usb.rst

Quoted 7 lines
Documentation/user/usb.rst +2 -2
 device_initcall(fastboot_globalvars_init);
 
-BAREBOX_MAGICVAR_NAMED(global_usbgadget_fastboot_max_download_size,
-		       global.usbgadget.fastboot_max_download_size,
+BAREBOX_MAGICVAR_NAMED(global_fastboot_max_download_size,
+		       global.fastboot.max_download_size,
 		       "Fastboot maximum download size");

This renames the magicvar description for this variable, but not the variable itself.

Sascha

Signature · 9 lines
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
maintainer
#12 lore raw

Re: [PATCH v2 09/10] fastboot net: implement fastboot over UDP

In reply to Daniel Glöckner
Quoted 34 lines · Daniel Glöckner

From: Edmund Henniges <[email protected]>

This implements the UDP variant of the fastboot protocol. The only way to start the service for now is to compile with CONFIG_FASTBOOT_NET_ON_BOOT. The service will bind to the network interface that provides the IPv4 gateway.

Sending an OKAY packet before performing a restart is necessary since contrary to USB the host will not notice when a UDP server disappears.

---
 common/fastboot.c      |   3 +
 include/fastboot.h     |   1 +
 include/fastboot_net.h |  12 +
 net/Kconfig            |  18 ++
 net/Makefile           |   1 +
 net/fastboot.c         | 496 +++++++++++++++++++++++++++++++++++++++++
 6 files changed, 531 insertions(+)
 create mode 100644 include/fastboot_net.h
 create mode 100644 net/fastboot.c
common/fastboot.c +7 -0
index d50f61ff2..706547309 100644
+static int fastboot_write_net(struct fastboot *fb, const char *buf,
+			      unsigned int n)
+{
+	struct fastboot_net *fbn = container_of(fb, struct fastboot_net,
+						fastboot);
+	struct fastboot_header response_header;
+	uchar *packet;

common/fastboot.c

Quoted 10 lines
common/fastboot.c +10 -0
+	uchar *packet_base;
+
+	if (fbn->reinit)
+		return 0;
+
+	while (fbn->may_send == MAY_NOT_SEND) {
+		poller_call();
+		if (fbn->reinit)
+			return 0;
+	}

This is a potentially endless loop I can reproducibly hit here. When I do a "sleep 10" on the command line and at the same time start a fastboot transfer then there's no progress. This is expected because fastboot depends on the idle slice. However, when the "sleep 10" is over then I get a prompt and then we are stuck in this loop.

I replaced this loop with a one second timeout loop. With this we are no longer stuck in the loop, but the current transfer doesn't continue anymore.

Afterwards I dropped everything around fbn->may_send completely and now everything works fluently.

Removing these send restrictions seems the right thing to me. In the end it's UDP, so the remote host shouldn't make any assumptions of how fast and if at all packets arrive there.

Sascha

Signature · 9 lines
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
maintainer
#5 lore raw

Re: [PATCH v2 04/10] Introduce idle slice

In reply to Daniel Glöckner
Quoted 24 lines · Daniel Glöckner

Some code can't foresee which resources will be used by its poller. This is the case especially in pollers that will execute arbitrary commands input by the user. With this commit a special slice is introduced that is released only when Barebox is waiting for console input and only when it is doing that outside of any command. Code that wants to depend on the idle slice must select CONFIG_IDLE_SLICE to make it available.

---
 common/Kconfig             |  4 ++++
 common/binfmt.c            |  3 +++
 common/command.c           |  3 +++
 common/console_countdown.c |  3 +++
 common/poller.c            |  2 ++
 common/slice.c             | 24 ++++++++++++++++++++++++
 include/slice.h            | 10 ++++++++++
 lib/readline.c             |  8 +++++++-
 8 files changed, 56 insertions(+), 1 deletion(-)
common/Kconfig +0 -0
index 400c0553c..2fa9140de 100644

common/Kconfig config BAREBOXCRC32_TARGET · line 918

Quoted 6 lines
common/Kconfig +3 -0
@@ -913,6 +913,10 @@ config BAREBOXCRC32_TARGET
 config POLLER
 	bool "generic polling infrastructure"
 
+config IDLE_SLICE
+	bool
+	default n

We discussed config SLICE away, is there a reason to introduce config IDLE_SLICE?

Quoted 39 lines
common/Kconfig +1 -0
+
 config STATE
 	bool "generic state infrastructure"
 	select CRC32
common/binfmt.c +3 -0
index f2ff62458..899f270d4 100644
@@ -10,6 +10,7 @@
 #include <malloc.h>
 #include <command.h>
 #include <errno.h>
+#include <slice.h>
 
 static LIST_HEAD(binfmt_hooks);
 
@@ -23,7 +24,9 @@ static int binfmt_run(char *file, int argc, char **argv)
 		if (b->type != type)
 			continue;
 
+		idle_slice_acquire();
 		ret = b->hook(b, file, argc, argv);
+		idle_slice_release();
 		if (ret != -ERESTARTNOHAND)
 			return ret;
 	}
common/command.c +1 -0
index 49845938a..2b10248f5 100644
@@ -30,6 +30,7 @@
 #include <init.h>
 #include <complete.h>
 #include <getopt.h>
+#include <slice.h>
 
 LIST_HEAD(command_list);
 EXPORT_SYMBOL(command_list);

common/command.c int execute_command(int argc, char **argv) · line 78

Quoted 6 lines
common/command.c +2 -0
@@ -72,7 +73,9 @@ int execute_command(int argc, char **argv)
 	/* Look up command in command table */
 	if ((cmdtp = find_cmd(argv[0]))) {
 		/* OK - call function to do the command */
+		idle_slice_acquire();
 		ret = cmdtp->cmd(argc, argv);
+		idle_slice_release();

The command could be a shell in which case we would never be able to release the idle slice as long this shell is running.

Quoted 5 lines
common/command.c +1 -0
@@ -200,11 +201,16 @@ int readline(const char *prompt, char *buf, int len)
 	puts (prompt);
 
 	while (1) {
+		idle_slice_release();

common/command.c int readline(const char *prompt, char *buf, int len) · line 213

Quoted 10 lines
common/command.c +5 -1
 		while (!tstc()) {
 			poller_call();
-			if (IS_ENABLED(CONFIG_CONSOLE_RATP))
+			if (IS_ENABLED(CONFIG_CONSOLE_RATP)) {
+				idle_slice_acquire();
 				barebox_ratp_command_run();
+				idle_slice_release();
+			}
 		}
+		idle_slice_acquire();

I am not sure this is the right place to release the idle slice, I would rather do it in the caller. readline() may be called from different places, not all of them seem to be appropriate for releasing the idle slice.

I think the idle slice should be released right before the shell calls into readline and acquired again right afterwards.

Sascha

Signature · 9 lines
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#13 lore raw

Re: [PATCH v2 09/10] fastboot net: implement fastboot over UDP

In reply to Sascha Hauer

Hello Sascha,

Quoted 52 lines · Sascha Hauer
Quoted 34 lines · Daniel Glöckner

From: Edmund Henniges <[email protected]>

This implements the UDP variant of the fastboot protocol. The only way to start the service for now is to compile with CONFIG_FASTBOOT_NET_ON_BOOT. The service will bind to the network interface that provides the IPv4 gateway.

Sending an OKAY packet before performing a restart is necessary since contrary to USB the host will not notice when a UDP server disappears.

---
 common/fastboot.c      |   3 +
 include/fastboot.h     |   1 +
 include/fastboot_net.h |  12 +
 net/Kconfig            |  18 ++
 net/Makefile           |   1 +
 net/fastboot.c         | 496 +++++++++++++++++++++++++++++++++++++++++
 6 files changed, 531 insertions(+)
 create mode 100644 include/fastboot_net.h
 create mode 100644 net/fastboot.c
common/fastboot.c +7 -0
index d50f61ff2..706547309 100644
+static int fastboot_write_net(struct fastboot *fb, const char *buf,
+			      unsigned int n)
+{
+	struct fastboot_net *fbn = container_of(fb, struct fastboot_net,
+						fastboot);
+	struct fastboot_header response_header;
+	uchar *packet;

common/fastboot.c

Quoted 10 lines
common/fastboot.c +10 -0
+	uchar *packet_base;
+
+	if (fbn->reinit)
+		return 0;
+
+	while (fbn->may_send == MAY_NOT_SEND) {
+		poller_call();
+		if (fbn->reinit)
+			return 0;
+	}

This is a potentially endless loop I can reproducibly hit here. When I do a "sleep 10" on the command line and at the same time start a fastboot transfer then there's no progress. This is expected because fastboot depends on the idle slice. However, when the "sleep 10" is over then I get a prompt and then we are stuck in this loop.

Quoted 3 lines

I replaced this loop with a one second timeout loop. With this we are no longer stuck in the loop, but the current transfer doesn't continue anymore.

The official fastboot tool from Google has a 60 second timeout and retransmits packets every 0.5 seconds. A 1 second timeout on the device feels too short. We should also retry for at least 60 seconds.

I would expect that the host retransmits its last packet beyond the 10 second sleep and the transfer to immediately continue when barebox is no longer busy. Also keep in mind that a device will most likely never be used over fastboot and serial console at the same time. A user who interactively started the transfer can always restart fastboot on the host, which will abort this loop by setting reinit.

Quoted 6 lines

Afterwards I dropped everything around fbn->may_send completely and now everything works fluently.

Removing these send restrictions seems the right thing to me. In the end it's UDP, so the remote host shouldn't make any assumptions of how fast and if at all packets arrive there.

I haven't seen your changes, but I fear you have broken something else. Without may_send it may be possible for a message to be sent before the previous message has been acked by the host. Since we can retransmit only the last message, the connection will be stuck until the host times out. In the protocol each side has to wait for reception of a packet with the correct sequence number before it can send the next packet. We can't change that just be cause we think it's the right thing.

Best regards,

Daniel

Signature · 13 lines
Dipl.-Math. Daniel Glöckner, emlix GmbH, http://www.emlix.com
Fon +49 551 30664-0, Fax +49 551 30664-11,
Gothaer Platz 3, 37083 Göttingen, Germany
Sitz der Gesellschaft: Göttingen, Amtsgericht Göttingen HR B 3160
Geschäftsführung: Heike Jordan, Dr. Uwe Kracke
Ust-IdNr.: DE 205 198 055

emlix - your embedded linux partner

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
maintainer
#14 lore raw

Re: [PATCH v2 09/10] fastboot net: implement fastboot over UDP

Hi Daniel,

Quoted 77 lines · Daniel Glöckner

Hello Sascha,

Quoted 52 lines · Sascha Hauer
Quoted 34 lines · Daniel Glöckner

From: Edmund Henniges <[email protected]>

This implements the UDP variant of the fastboot protocol. The only way to start the service for now is to compile with CONFIG_FASTBOOT_NET_ON_BOOT. The service will bind to the network interface that provides the IPv4 gateway.

Sending an OKAY packet before performing a restart is necessary since contrary to USB the host will not notice when a UDP server disappears.

---
 common/fastboot.c      |   3 +
 include/fastboot.h     |   1 +
 include/fastboot_net.h |  12 +
 net/Kconfig            |  18 ++
 net/Makefile           |   1 +
 net/fastboot.c         | 496 +++++++++++++++++++++++++++++++++++++++++
 6 files changed, 531 insertions(+)
 create mode 100644 include/fastboot_net.h
 create mode 100644 net/fastboot.c
common/fastboot.c +7 -0
index d50f61ff2..706547309 100644
+static int fastboot_write_net(struct fastboot *fb, const char *buf,
+			      unsigned int n)
+{
+	struct fastboot_net *fbn = container_of(fb, struct fastboot_net,
+						fastboot);
+	struct fastboot_header response_header;
+	uchar *packet;

common/fastboot.c

Quoted 10 lines
common/fastboot.c +10 -0
+	uchar *packet_base;
+
+	if (fbn->reinit)
+		return 0;
+
+	while (fbn->may_send == MAY_NOT_SEND) {
+		poller_call();
+		if (fbn->reinit)
+			return 0;
+	}

This is a potentially endless loop I can reproducibly hit here. When I do a "sleep 10" on the command line and at the same time start a fastboot transfer then there's no progress. This is expected because fastboot depends on the idle slice. However, when the "sleep 10" is over then I get a prompt and then we are stuck in this loop.

Quoted 3 lines

I replaced this loop with a one second timeout loop. With this we are no longer stuck in the loop, but the current transfer doesn't continue anymore.

The official fastboot tool from Google has a 60 second timeout and retransmits packets every 0.5 seconds. A 1 second timeout on the device feels too short. We should also retry for at least 60 seconds.

I would expect that the host retransmits its last packet beyond the 10 second sleep and the transfer to immediately continue when barebox is no longer busy. Also keep in mind that a device will most likely never be used over fastboot and serial console at the same time. A user who interactively started the transfer can always restart fastboot on the host, which will abort this loop by setting reinit.

Quoted 6 lines

Afterwards I dropped everything around fbn->may_send completely and now everything works fluently.

Removing these send restrictions seems the right thing to me. In the end it's UDP, so the remote host shouldn't make any assumptions of how fast and if at all packets arrive there.

Quoted 5 lines

I haven't seen your changes, but I fear you have broken something else. Without may_send it may be possible for a message to be sent before the previous message has been acked by the host. Since we can retransmit only the last message, the connection will be stuck until the host times out.

We are probably implementing UDP Protocol V1, right?

Here it says:

1. The host drives all communication; the device may only send a packet as a response to a host packet.
2. If the host does not receive a response in 500ms it will re-transmit.

This means the host doesn't ack anything, it just sends the next packet if it received our response or the same packet again if it hasn't. For us this means we don't have to retransmit anything, we only have to respond to the last packet seen.

I am not sure how INFO responses are handled, there seems to be no way for the client to notice that the host hasn't seen them. It looks like these are just lost then and simply won't be displayed on the host.

That said, it's absolutely possible that I have broken something else with my changes ;)

I have quite some changes also in my slice series which I'll post later the day. Maybe we can take this as a base for further discussions.

Sascha

Signature · 9 lines
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
maintainer
#15 lore raw

Re: [PATCH v2 09/10] fastboot net: implement fastboot over UDP

In reply to Daniel Glöckner
Quoted 26 lines · Daniel Glöckner

From: Edmund Henniges <[email protected]>

This implements the UDP variant of the fastboot protocol. The only way to start the service for now is to compile with CONFIG_FASTBOOT_NET_ON_BOOT. The service will bind to the network interface that provides the IPv4 gateway.

Sending an OKAY packet before performing a restart is necessary since contrary to USB the host will not notice when a UDP server disappears.

---

net/fastboot.c new file +13 -0
+
+#ifdef CONFIG_FASTBOOT_NET_ON_BOOT
+static struct fastboot_net *fastboot_net_obj;
+
+static int fastboot_on_boot(void)
+{
+	struct fastboot_net *fbn;
+
+	ifup_all(0);
+	fbn = fastboot_net_init(NULL);
+
+	if (IS_ERR(fbn))
+		return PTR_ERR(fbn);

net/fastboot.c line 492

Quoted 10 lines
net/fastboot.c new file +10 -0
+
+	fastboot_net_obj = fbn;
+	return 0;
+}
+
+static void fastboot_net_exit(void)
+{
+	if (fastboot_net_obj)
+		fastboot_net_free(fastboot_net_obj);
+}

fastboot_net_obj won't be NULL here, the check should be if(!IS_ERR()) instead.

Sascha

Signature · 9 lines
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox