summaryrefslogtreecommitdiffstats
path: root/include/fastboot.h
diff options
context:
space:
mode:
authorEdmund Henniges <eh@emlix.com>2020-05-14 20:21:54 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2020-05-20 15:43:59 +0200
commit2879373370eb3685cd6622f5d800e9f72ec81df1 (patch)
treed57b9103755336b550b7e8397dfeb586e728ef02 /include/fastboot.h
parent754f2e0d106d44dc89fdb4edbb54641d9525e62c (diff)
downloadbarebox-2879373370eb3685cd6622f5d800e9f72ec81df1.tar.gz
barebox-2879373370eb3685cd6622f5d800e9f72ec81df1.tar.xz
fastboot: split generic code from USB gadget
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. Signed-off-by: Edmund Henniges <eh@emlix.com> Signed-off-by: Daniel Glöckner <dg@emlix.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'include/fastboot.h')
-rw-r--r--include/fastboot.h66
1 files changed, 66 insertions, 0 deletions
diff --git a/include/fastboot.h b/include/fastboot.h
new file mode 100644
index 0000000000..3b6cae8a58
--- /dev/null
+++ b/include/fastboot.h
@@ -0,0 +1,66 @@
+#ifndef __FASTBOOT__
+#define __FASTBOOT__
+
+#include <common.h>
+#include <file-list.h>
+#include <net.h>
+
+/*
+ * 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
+
+struct fastboot {
+ int (*write)(struct fastboot *fb, const char *buf, unsigned int n);
+ void (*start_download)(struct fastboot *fb);
+
+ struct file_list *files;
+ int (*cmd_exec)(struct fastboot *fb, const char *cmd);
+ int (*cmd_flash)(struct fastboot *fb, struct file_list_entry *entry,
+ const char *filename, const void *buf, size_t len);
+ int download_fd;
+ void *buf;
+
+ bool active;
+
+ size_t download_bytes;
+ size_t download_size;
+ struct list_head variables;
+};
+
+/**
+ * struct fastboot_opts - options to configure fastboot
+ * @files: A file_list containing the files (partitions) to export via fastboot
+ * @export_bbu: Automatically include the partitions provided by barebox update (bbu)
+ */
+struct fastboot_opts {
+ struct file_list *files;
+ bool export_bbu;
+ int (*cmd_exec)(struct fastboot *fb, const char *cmd);
+ int (*cmd_flash)(struct fastboot *fb, struct file_list_entry *entry,
+ const char *filename, const void *buf, size_t len);
+};
+
+enum fastboot_msg_type {
+ FASTBOOT_MSG_OKAY,
+ FASTBOOT_MSG_FAIL,
+ FASTBOOT_MSG_INFO,
+ FASTBOOT_MSG_DATA,
+};
+
+int fastboot_generic_init(struct fastboot *fb, bool export_bbu);
+void fastboot_generic_close(struct fastboot *fb);
+void fastboot_generic_free(struct fastboot *fb);
+int fastboot_handle_download_data(struct fastboot *fb, const void *buffer,
+ unsigned int len);
+int fastboot_tx_print(struct fastboot *fb, enum fastboot_msg_type type,
+ const char *fmt, ...);
+void fastboot_start_download_generic(struct fastboot *fb);
+void fastboot_download_finished(struct fastboot *fb);
+void fastboot_exec_cmd(struct fastboot *fb, const char *cmdbuf);
+#endif