Skip to contentSkip to conversation

Implement "fastboot flash" for eMMC

PATCH Superseded Steve Rae 5 participants 32 messages Aug 6, 2014 – Aug 10, 2014 USB

v4 of 6 Superseded Latest is v6 →

lore
Share & tools
lore

Steve Rae

author
#0 lore raw

v4 cover Implement "fastboot flash" for eMMC

This series implements the "fastboot flash" command for eMMC devices. It supports both raw and sparse images.

NOTES:
- the support for the "fastboot flash" command is enabled with CONFIG_FASTBOOT_FLASH
- the support for eMMC is enabled with CONFIG_FASTBOOT_FLASH_MMC_DEV
- (future) the support for NAND would be enabled with CONFIG_FASTBOOT_FLASH_NAND(???)

This has been tested on ARMv7.

----
While we are struggling with the "sparse_format" copyright and licensing issues, can we accept the first three patches?
Thanks, Steve

Changes in v4:
- rearranged this patchset so that "sparse_format.h" can be dropped (if we cannot resolve the copyright/licensing issues)
- update mmc_get_dev(...) to get_dev("mmc",....)
- update printf() to puts() where applicable
- update debug string as per feedback
- rearranged "sparse format" support in this patchset, in order to isolate...

Changes in v3:
- remove most references to 'mmc',
which leaves only one mmc specific function: mmc_get_dev()

Changes in v2:
- split large function into three
- improved handling of response messages
- additional partition size checking when writing sparse image
- update README.android-fastboot file
- new in v2

Steve Rae (5):
usb/gadget: fastboot: add eMMC support for flash command usb/gadget: fastboot: add support for flash command usb/gadget: fastboot: minor cleanup
usb/gadget: fastboot: add sparse image definitions usb/gadget: fastboot: implement sparse format

 README                          |  10 +++
 common/Makefile                 |   5 ++
 common/cmd_fastboot.c           |   7 +-
 common/fb_mmc.c                 | 191 ++++++++++++++++++++++++++++++++++++++++
 doc/README.android-fastboot     |   5 +-
 drivers/usb/gadget/f_fastboot.c |  44 ++++++++-
 include/fb_mmc.h                |   8 ++
 include/sparse_format.h         |  58 ++++++++++++
 8 files changed, 319 insertions(+), 9 deletions(-)
 create mode 100644 common/fb_mmc.c
 create mode 100644 include/fb_mmc.h
 create mode 100644 include/sparse_format.h
Signature · 1 line
1.8.5
author
#1 lore raw

PATCH v4 1/5 usb/gadget: fastboot: add eMMC support for flash command

- add support for 'fastboot flash' command for eMMC devices

---

Changes in v4:
- rearranged this patchset so that "sparse_format.h" can be dropped (if we cannot resolve the copyright/licensing issues)
- update mmc_get_dev(...) to get_dev("mmc",....)
- update printf() to puts() where applicable

Changes in v3:
- remove most references to 'mmc',
which leaves only one mmc specific function: mmc_get_dev()

Changes in v2:
- split large function into three
- improved handling of response messages
- additional partition size checking when writing sparse image

 common/Makefile  |  5 ++++
 common/fb_mmc.c  | 82 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 include/fb_mmc.h |  8 ++++++
 3 files changed, 95 insertions(+)
 create mode 100644 common/fb_mmc.c
 create mode 100644 include/fb_mmc.h
common/Makefile +5 -0
index de5cce8..daebe39 100644
@@ -266,4 +266,9 @@ obj-$(CONFIG_IO_TRACE) += iotrace.o
 obj-y += memsize.o
 obj-y += stdio.o
 
+# This option is not just y/n - it can have a numeric value
+ifdef CONFIG_FASTBOOT_FLASH_MMC_DEV
+obj-y += fb_mmc.o
+endif
+
 CFLAGS_env_embedded.o := -Wa,--no-warn -DENV_CRC=$(shell tools/envcrc 2>/dev/null)
common/fb_mmc.c new file +82 -0

82 lines not on this page · raw message

include/fb_mmc.h new file +8 -0
new file mode 100644
index 0000000..1ad1d13
@@ -0,0 +1,8 @@
+/*
+ * Copyright 2014 Broadcom Corporation.
+ *
+ * SPDX-License-Identifier:	GPL-2.0+
+ */
+
+void fb_mmc_flash_write(const char *cmd, void *download_buffer,
+			unsigned int download_bytes, char *response);
Signature · 1 line
1.8.5
author
#2 lore raw

PATCH v4 2/5 usb/gadget: fastboot: add support for flash command

In reply to Steve Rae

- implement 'fastboot flash' for eMMC devices

---

Changes in v4: None
Changes in v3: None
Changes in v2:
- update README.android-fastboot file

 README                          | 10 ++++++++++
 doc/README.android-fastboot     |  5 +++--
 drivers/usb/gadget/f_fastboot.c | 31 +++++++++++++++++++++++++++++++
 3 files changed, 44 insertions(+), 2 deletions(-)
README +10 -0
index 1d71359..ed26884 100644
@@ -1623,6 +1623,16 @@ The following options need to be configured:
 		downloads. This buffer should be as large as possible for a
 		platform. Define this to the size available RAM for fastboot.
 
+		CONFIG_FASTBOOT_FLASH
+		The fastboot protocol includes a "flash" command for writing
+		the downloaded image to a non-volatile storage device. Define
+		this to enable the "fastboot flash" command.
+
+		CONFIG_FASTBOOT_FLASH_MMC_DEV
+		The fastboot "flash" command requires addition information
+		regarding the non-volatile storage device. Define this to
+		the eMMC device that fastboot should use to store the image.
+
 - Journaling Flash filesystem support:
 		CONFIG_JFFS2_NAND, CONFIG_JFFS2_NAND_OFF, CONFIG_JFFS2_NAND_SIZE,
 		CONFIG_JFFS2_NAND_DEV
doc/README.android-fastboot +3 -2
index f1d128c..430e29c 100644
@@ -6,8 +6,9 @@ Overview
 The protocol that is used over USB is described in
 README.android-fastboot-protocol in same directory.
 
-The current implementation does not yet support the flash and erase
-commands.
+The current implementation does not yet support the erase command or the
+"oem format" command, and there is minimal support for the flash command;
+it only supports eMMC devices.
 
 Client installation
 ===================
drivers/usb/gadget/f_fastboot.c +31 -0
index 7a1acb9..e2659fa 100644
@@ -19,6 +19,9 @@
 #include <linux/compiler.h>
 #include <version.h>
 #include <g_dnl.h>
+#ifdef CONFIG_FASTBOOT_FLASH_MMC_DEV
+#include <fb_mmc.h>
+#endif
 
 #define FASTBOOT_VERSION		"0.4"
 
@@ -469,6 +472,28 @@ static void cb_boot(struct usb_ep *ep, struct usb_request *req)
 	fastboot_tx_write_str("OKAY");
 }
 
+#ifdef CONFIG_FASTBOOT_FLASH
+static void cb_flash(struct usb_ep *ep, struct usb_request *req)
+{
+	char *cmd = req->buf;
+	char response[RESPONSE_LEN];
+
+	strsep(&cmd, ":");
+	if (!cmd) {
+		printf("%s: missing partition name\n", __func__);
+		fastboot_tx_write_str("FAILmissing partition name");
+		return;
+	}
+
+	strcpy(response, "FAILno flash device defined");
+#ifdef CONFIG_FASTBOOT_FLASH_MMC_DEV
+	fb_mmc_flash_write(cmd, (void *)CONFIG_USB_FASTBOOT_BUF_ADDR,
+			   download_bytes, response);
+#endif
+	fastboot_tx_write_str(response);
+}
+#endif
+
 struct cmd_dispatch_info {
 	char *cmd;
 	void (*cb)(struct usb_ep *ep, struct usb_request *req);
@@ -488,6 +513,12 @@ static const struct cmd_dispatch_info cmd_dispatch_info[] = {
 		.cmd = "boot",
 		.cb = cb_boot,
 	},
+#ifdef CONFIG_FASTBOOT_FLASH
+	{
+		.cmd = "flash",
+		.cb = cb_flash,
+	},
+#endif
 };
 
 static void rx_handler_command(struct usb_ep *ep, struct usb_request *req)
Signature · 1 line
1.8.5
author
#3 lore raw

PATCH v4 3/5 usb/gadget: fastboot: minor cleanup

In reply to Steve Rae

- update static function
- additional debugging statements
- update "fastboot command" information
- add missing include file
- update spelling

---

Changes in v4:
- update debug string as per feedback

Changes in v3: None
Changes in v2:
- new in v2

 common/cmd_fastboot.c           |  7 ++++---
 drivers/usb/gadget/f_fastboot.c | 13 +++++++++----
 2 files changed, 13 insertions(+), 7 deletions(-)
common/cmd_fastboot.c +4 -3
index 83fa7bd..909616d 100644
@@ -30,7 +30,8 @@ static int do_fastboot(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
 }
 
 U_BOOT_CMD(
-	fastboot,	1,	1,	do_fastboot,
-	"fastboot - enter USB Fastboot protocol",
-	""
+	fastboot,	1,	0,	do_fastboot,
+	"use USB Fastboot protocol",
+	"\n"
+	"    - run as a fastboot usb device"
 );
drivers/usb/gadget/f_fastboot.c +9 -4
index e2659fa..3b588a9 100644
@@ -10,6 +10,7 @@
  *
  * SPDX-License-Identifier:	GPL-2.0+
  */
+#include <config.h>
 #include <common.h>
 #include <errno.h>
 #include <malloc.h>
@@ -41,7 +42,7 @@
 struct f_fastboot {
 	struct usb_function usb_function;
 
-	/* IN/OUT EP's and correspoinding requests */
+	/* IN/OUT EP's and corresponding requests */
 	struct usb_ep *in_ep, *out_ep;
 	struct usb_request *in_req, *out_req;
 };
@@ -293,7 +294,7 @@ static int fastboot_add(struct usb_configuration *c)
 }
 DECLARE_GADGET_BIND_CALLBACK(usb_dnl_fastboot, fastboot_add);
 
-int fastboot_tx_write(const char *buffer, unsigned int buffer_size)
+static int fastboot_tx_write(const char *buffer, unsigned int buffer_size)
 {
 	struct usb_request *in_req = fastboot_func->in_req;
 	int ret;
@@ -341,6 +342,7 @@ static void cb_getvar(struct usb_ep *ep, struct usb_request *req)
 
 	strsep(&cmd, ":");
 	if (!cmd) {
+		printf("%s: missing variable\n", __func__);
 		fastboot_tx_write_str("FAILmissing var");
 		return;
 	}
@@ -361,6 +363,7 @@ static void cb_getvar(struct usb_ep *ep, struct usb_request *req)
 		else
 			strcpy(response, "FAILValue not set");
 	} else {
+		printf("%s: unknown variable: %s\n", __func__, cmd);
 		strcpy(response, "FAILVariable not implemented");
 	}
 	fastboot_tx_write_str(response);
@@ -534,10 +537,12 @@ static void rx_handler_command(struct usb_ep *ep, struct usb_request *req)
 		}
 	}
 
-	if (!func_cb)
+	if (!func_cb) {
+		printf("%s: unknown command: %s\n", __func__, cmdbuf);
 		fastboot_tx_write_str("FAILunknown command");
-	else
+	} else {
 		func_cb(ep, req);
+	}
 
 	if (req->status == 0) {
 		*cmdbuf = '\0';
Signature · 1 line
1.8.5
author
#4 lore raw

PATCH v4 4/5 usb/gadget: fastboot: add sparse image definitions

In reply to Steve Rae

- to prepare for the support of fastboot sparse images

---
This file is ASIS from:
https://raw.githubusercontent.com/AOSB/android_system_core/master/libsparse/sparse_format.h
(commit 28fa5bc347390480fe190294c6c385b6a9f0d68b)
except for the __UBOOT__ conditional include.

Changes in v4: None
Changes in v3: None
Changes in v2: None

 include/sparse_format.h | 58 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 58 insertions(+)
 create mode 100644 include/sparse_format.h
include/sparse_format.h new file +58 -0
new file mode 100644
index 0000000..21fbd05
@@ -0,0 +1,58 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef _LIBSPARSE_SPARSE_FORMAT_H_
+#define _LIBSPARSE_SPARSE_FORMAT_H_
+#define __UBOOT__
+#ifndef __UBOOT__
+#include "sparse_defs.h"
+#endif
+
+typedef struct sparse_header {
+  __le32	magic;		/* 0xed26ff3a */
+  __le16	major_version;	/* (0x1) - reject images with higher major versions */
+  __le16	minor_version;	/* (0x0) - allow images with higer minor versions */
+  __le16	file_hdr_sz;	/* 28 bytes for first revision of the file format */
+  __le16	chunk_hdr_sz;	/* 12 bytes for first revision of the file format */
+  __le32	blk_sz;		/* block size in bytes, must be a multiple of 4 (4096) */
+  __le32	total_blks;	/* total blocks in the non-sparse output image */
+  __le32	total_chunks;	/* total chunks in the sparse input image */
+  __le32	image_checksum; /* CRC32 checksum of the original data, counting "don't care" */
+				/* as 0. Standard 802.3 polynomial, use a Public Domain */
+				/* table implementation */
+} sparse_header_t;
+
+#define SPARSE_HEADER_MAGIC	0xed26ff3a
+
+#define CHUNK_TYPE_RAW		0xCAC1
+#define CHUNK_TYPE_FILL		0xCAC2
+#define CHUNK_TYPE_DONT_CARE	0xCAC3
+#define CHUNK_TYPE_CRC32    0xCAC4
+
+typedef struct chunk_header {
+  __le16	chunk_type;	/* 0xCAC1 -> raw; 0xCAC2 -> fill; 0xCAC3 -> don't care */
+  __le16	reserved1;
+  __le32	chunk_sz;	/* in blocks in output image */
+  __le32	total_sz;	/* in bytes of chunk input file including chunk header and data */
+} chunk_header_t;
+
+/* Following a Raw or Fill or CRC32 chunk is data.
+ *  For a Raw chunk, it's the data in chunk_sz * blk_sz.
+ *  For a Fill chunk, it's 4 bytes of the fill data.
+ *  For a CRC32 chunk, it's 4 bytes of CRC32
+ */
+
+#endif
Signature · 1 line
1.8.5
#5 lore raw

PATCH v4 4/5 usb/gadget: fastboot: add sparse image definitions

Quoted 4 lines · Steve Rae

- to prepare for the support of fastboot sparse images

---

Are we discussing the licensing issues here still ? Tom ?

Best regards,
Marek Vasut

author
#6 lore raw

PATCH v4 4/5 usb/gadget: fastboot: add sparse image definitions

Quoted 11 lines · Marek Vasut
Quoted 4 lines · Steve Rae

- to prepare for the support of fastboot sparse images

---

Are we discussing the licensing issues here still ? Tom ?

Best regards,
Marek Vasut

I hope so -- and I'm hoping that someone can help resolve this!!!! Thanks in advance, Steve

#7 lore raw

PATCH v4 4/5 usb/gadget: fastboot: add sparse image definitions

Quoted 7 lines · Steve Rae
Quoted 6 lines · Marek Vasut
Quoted 4 lines · Steve Rae

- to prepare for the support of fastboot sparse images

---

Quoted 7 lines
Quoted 4 lines

Are we discussing the licensing issues here still ? Tom ?

Best regards,
Marek Vasut

I hope so -- and I'm hoping that someone can help resolve this!!!! Thanks in advance, Steve

Someone should ask the legal dept ...

Best regards,
Marek Vasut

#8 lore raw

PATCH v4 4/5 usb/gadget: fastboot: add sparse image definitions

In reply to Marek Vasut

Dear Marek,

Quoted 2 lines · In message <[email protected]> you wrote:

Are we discussing the licensing issues here still ? Tom ?

Well, of course? We cannot add code that comes under an incompatible license. And we use SPDX ids.

Best regards,

Wolfgang Denk

Signature · 4 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
I still miss my ex-wife, but my aim is getting better.
#9 lore raw

PATCH v4 4/5 usb/gadget: fastboot: add sparse image definitions

Quoted 7 lines · Wolfgang Denk

Dear Marek,

Quoted 1 line · In message <[email protected]> you wrote:

Are we discussing the licensing issues here still ? Tom ?

Well, of course? We cannot add code that comes under an incompatible license. And we use SPDX ids.

Well I agree Apache license is not compatible, but how can we proceed here for the good for U-Boot project and happiness of all involved parties here ? Aka. what do we do now to make the best of the contribution ?

Best regards,
Marek Vasut

#10 lore raw

PATCH v4 4/5 usb/gadget: fastboot: add sparse image definitions

In reply to Steve Rae

Dear Steve Rae,

Quoted 8 lines · In message <[email protected]> you wrote:

- to prepare for the support of fastboot sparse images

---
This file is ASIS from:
https://raw.githubusercontent.com/AOSB/android_system_core/master/libsparse/sparse_format.h
(commit 28fa5bc347390480fe190294c6c385b6a9f0d68b)
except for the __UBOOT__ conditional include.

Please make sure this origin documentation becomes part of the commit message - here in the comment section it gets lost. Please fix for all your patches.

Quoted 6 lines

+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *

Quoted 8 lines

+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */

Please always use SPDX license tags only.

Please note that this license is not compatible with GPL version 2, because it has some requirements that are not in that GPL version. An U-Boot is covered by GPLv2 ...

Best regards,

Wolfgang Denk

Signature · 4 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
The greatest threat towards future is indifference.
#11 lore raw

PATCH v4 4/5 usb/gadget: fastboot: add sparse image definitions

Quoted 33 lines · Wolfgang Denk

Dear Steve Rae,

Quoted 10 lines · In message <[email protected]> you wrote:

- to prepare for the support of fastboot sparse images

---

This file is ASIS from:
https://raw.githubusercontent.com/AOSB/android_system_core/master/libsp
arse/sparse_format.h (commit 28fa5bc347390480fe190294c6c385b6a9f0d68b)

except for the __UBOOT__ conditional include.

Please make sure this origin documentation becomes part of the commit message - here in the comment section it gets lost. Please fix for all your patches.

Quoted 6 lines

+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *

Quoted 8 lines

+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License.
+ */

Quoted 5 lines

Please always use SPDX license tags only.

Please note that this license is not compatible with GPL version 2, because it has some requirements that are not in that GPL version. An U-Boot is covered by GPLv2 ...

I think we should start considering getting some kind of a legal conseling here, or do we actually have one already ?

Best regards,
Marek Vasut

#12 lore raw

PATCH v4 4/5 usb/gadget: fastboot: add sparse image definitions

Quoted 9 lines · Marek Vasut
Quoted 6 lines
Quoted 3 lines

+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");

Please note that this license is not compatible with GPL version 2, because it has some requirements that are not in that GPL version. An U-Boot is covered by GPLv2 ...

I think we should start considering getting some kind of a legal conseling here, or do we actually have one already ?

I used the gnu page back then. Apache2 is compatible with GPLv3 but not with GPLv2 [0]. Some parts of the code I played around (the android image header file for instance) was under the Apache2 license and in another git tree under the two-clause BSD license which was compatible with GPLv2 [1].
So the argument about incompatible licenses is valid here. Should u-boot switch to GPLv3 you need to hunt down that file again and this time with the apache2 license :)

[0] https://www.gnu.org/licenses/license-list.html#apache2
[1] https://www.gnu.org/licenses/license-list.html#FreeBSD

Quoted 4 lines

Best regards,
Marek Vasut

Sebastian

#13 lore raw

PATCH v4 4/5 usb/gadget: fastboot: add sparse image definitions

Quoted 12 lines · Sebastian Andrzej Siewior
Quoted 10 lines · Marek Vasut
Quoted 7 lines
Quoted 3 lines

+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");

Please note that this license is not compatible with GPL version 2, because it has some requirements that are not in that GPL version. An U-Boot is covered by GPLv2 ...

I think we should start considering getting some kind of a legal conseling here, or do we actually have one already ?

Quoted 8 lines

I used the gnu page back then. Apache2 is compatible with GPLv3 but not with GPLv2 [0]. Some parts of the code I played around (the android image header file for instance) was under the Apache2 license and in another git tree under the two-clause BSD license which was compatible with GPLv2 [1].
So the argument about incompatible licenses is valid here. Should u-boot switch to GPLv3 you need to hunt down that file again and this time with the apache2 license :)

I agree. Is there a version of this file with BSD license on it ? Then that'd be a problem solved, right ? The other option would be to ask Google to release it under BSD license, but I don't know how easy that would be.

Best regards,
Marek Vasut

#14 lore raw

PATCH v4 4/5 usb/gadget: fastboot: add sparse image definitions

Quoted 2 lines · Marek Vasut

I agree. Is there a version of this file with BSD license on it ? Then that'd be a problem solved, right ?

Right. I don't recall the locations of the second tree but if Steve is going to search it, he should find it.

Quoted 4 lines

Best regards,
Marek Vasut

Sebastian

#15 lore raw

PATCH v4 4/5 usb/gadget: fastboot: add sparse image definitions

Quoted 6 lines · Sebastian Andrzej Siewior
Quoted 2 lines · Marek Vasut

I agree. Is there a version of this file with BSD license on it ? Then that'd be a problem solved, right ?

Right. I don't recall the locations of the second tree but if Steve is going to search it, he should find it.

Then we're good here, thanks for pointing this out !

Best regards,
Marek Vasut

author
#16 lore raw

PATCH v4 4/5 usb/gadget: fastboot: add sparse image definitions

In reply to Sebastian Andrzej Siewior
Quoted 6 lines · Sebastian Andrzej Siewior
Quoted 2 lines · Marek Vasut

I agree. Is there a version of this file with BSD license on it ? Then that'd be a problem solved, right ?

Right. I don't recall the locations of the second tree but if Steve is going to search it, he should find it.

I have not found anything other than the Apache 2 license (yet). If anyone can find anything, please let me know! Thanks in advance, Steve

Quoted 8 lines
Quoted 5 lines

Best regards,
Marek Vasut

Sebastian

#17 lore raw

PATCH v4 4/5 usb/gadget: fastboot: add sparse image definitions

In reply to Sebastian Andrzej Siewior

Dear Sebastian,

Quoted 9 lines · In message <[email protected]> you wrote:
Quoted 3 lines

I think we should start considering getting some kind of a legal conseling here, or do we actually have one already ?

I used the gnu page back then. Apache2 is compatible with GPLv3 but not with GPLv2 [0]. Some parts of the code I played around (the android image header file for instance) was under the Apache2 license and in another git tree under the two-clause BSD license which was compatible with GPLv2 [1].

We definitely need GPLv2 compatibility.

Quoted 2 lines

So the argument about incompatible licenses is valid here. Should u-boot switch to GPLv3 you need to hunt down that file again and this

You would have to rewrite the major part of U-Boot or to cripple it to uselessness if you try to release it under GPLv3. I cannot see anybody investing any efforts in that direction; all these threads about a potential GPLv3 switch are just a hollow scarecrow.

It seems clear to me that GPLv3 is not an acceptable solution for developers, vendors, and end users simultanously. When I ask for GPLv2+ I hope that some later version of GPL may find better general support.

Best regards,

Wolfgang Denk

Signature · 5 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
"This is a test of the Emergency Broadcast System. If this had been an
actual emergency, do you really think we'd stick around to tell you?"
#18 lore raw

PATCH v4 4/5 usb/gadget: fastboot: add sparse image definitions

Quoted 4 lines · Wolfgang Denk

<snip>

Quoted 2 lines

So the argument about incompatible licenses is valid here. Should u-boot switch to GPLv3 you need to hunt down that file again and this

You would have to rewrite the major part of U-Boot or to cripple it

noise ^ not

Quoted 8 lines

to uselessness if you try to release it under GPLv3. I cannot see anybody investing any efforts in that direction; all these threads about a potential GPLv3 switch are just a hollow scarecrow.

It seems clear to me that GPLv3 is not an acceptable solution for developers, vendors, and end users simultanously. When I ask for GPLv2+ I hope that some later version of GPL may find better general support.

Regards,
Jeroen

#19 lore raw

PATCH v4 4/5 usb/gadget: fastboot: add sparse image definitions

Dear Jeroen,

Quoted 10 lines · In message <[email protected]> you wrote:
Quoted 4 lines · Wolfgang Denk

<snip>

Quoted 2 lines

So the argument about incompatible licenses is valid here. Should u-boot switch to GPLv3 you need to hunt down that file again and this

You would have to rewrite the major part of U-Boot or to cripple it

noise ^ not

Quoted 3 lines

to uselessness if you try to release it under GPLv3. I cannot see anybody investing any efforts in that direction; all these threads about a potential GPLv3 switch are just a hollow scarecrow.

sorry, can't parse that.

Best regards,

Wolfgang Denk

Signature · 7 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
In the pitiful, multipage, connection-boxed form to which  the  flow-
chart  has  today  been  elaborated, it has proved to be useless as a
design tool -- programmers draw flowcharts after, not before, writing
the programs they describe.                        - Fred Brooks, Jr.
#20 lore raw

PATCH v4 4/5 usb/gadget: fastboot: add sparse image definitions

Quoted 5 lines · Wolfgang Denk

Dear Jeroen,

Quoted 2 lines · In message <[email protected]> you wrote:
Quoted 1 line · Wolfgang Denk

<snip>

Quoted 8 lines
Quoted 7 lines
Quoted 3 lines
Quoted 2 lines

So the argument about incompatible licenses is valid here. Should u-boot switch to GPLv3 you need to hunt down that file again and this

You would have to rewrite the major part of U-Boot or to cripple it

noise ^ not

Quoted 3 lines

to uselessness if you try to release it under GPLv3. I cannot see anybody investing any efforts in that direction; all these threads about a potential GPLv3 switch are just a hollow scarecrow.

sorry, can't parse that.

no, this was nicely formatted in my mail editor. Just wanted to point out you forgot a "not". You mentioned "to cripple it" you more then like ment "to _not_ cripple it". But the whitespace got lost along the way.

Regards,
Jeroen

#21 lore raw

PATCH v4 4/5 usb/gadget: fastboot: add sparse image definitions

Quoted 11 lines · Jeroen Hofstee
Quoted 9 lines · Wolfgang Denk

Dear Jeroen,

Quoted 6 lines · In message <[email protected]> you wrote:
Quoted 4 lines · Wolfgang Denk

<snip>

Quoted 2 lines

So the argument about incompatible licenses is valid here. Should u-boot switch to GPLv3 you need to hunt down that file again and this

You would have to rewrite the major part of U-Boot or to cripple it

noise ^ not

Quoted 8 lines
Quoted 4 lines
Quoted 3 lines
Quoted 3 lines

to uselessness if you try to release it under GPLv3. I cannot see anybody investing any efforts in that direction; all these threads about a potential GPLv3 switch are just a hollow scarecrow.

sorry, can't parse that.

no, this was nicely formatted in my mail editor. Just wanted to point out you forgot a "not". You mentioned "to cripple it" you more then like ment "to _not_ cripple it". But the whitespace got lost along the way.

ah, and the noise: part is that most readers would have figured that out without me mentioning it.

Regards,
Jeroen

#22 lore raw

PATCH v4 4/5 usb/gadget: fastboot: add sparse image definitions

In reply to Jeroen Hofstee

Dear Jeroen,

Quoted 5 lines · In message <[email protected]> you wrote:
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
Quoted 3 lines

So the argument about incompatible licenses is valid here. Should u-boot switch to GPLv3 you need to hunt down that file again and this

You would have to rewrite the major part of U-Boot or to cripple it

noise ^ not

Quoted 8 lines
Quoted 4 lines
Quoted 3 lines
Quoted 3 lines

to uselessness if you try to release it under GPLv3. I cannot see anybody investing any efforts in that direction; all these threads about a potential GPLv3 switch are just a hollow scarecrow.

sorry, can't parse that.

no, this was nicely formatted in my mail editor. Just wanted to point out you forgot a "not". You mentioned "to cripple it" you more then like ment "to _not_ cripple it". But the whitespace got lost along the way.

No, I did NOT forget a "not".

There is an awful lot of GPLv2 (V2 only) code in U-Boot. Many of the most interesting features thaty have been imported from the Linux kernel are GPLv2 only. Either you have to rewrite all this code. I don't see any volunteers for that in the community, and neither I see any commercial interest for that. So alternatively you would have to remove resp. disable in the configuration all such code - which would cripple U-Boot, as it would remove a lot of really useful functionali- ty, rendering it more or less useless for many practical use cases.

All people claiming "U-Boot will go GPLv3 tomorrow" are just spreading FUD.

Best regards,

Wolfgang Denk

Signature · 4 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
He who hesitates is not only lost, but miles from the next exit.
#23 lore raw

PATCH v4 4/5 usb/gadget: fastboot: add sparse image definitions

Quoted 17 lines · Wolfgang Denk

Dear Jeroen,

Quoted 14 lines · In message <[email protected]> you wrote:
Quoted 13 lines
Quoted 11 lines
Quoted 5 lines
Quoted 3 lines

So the argument about incompatible licenses is valid here. Should u-boot switch to GPLv3 you need to hunt down that file again and this

You would have to rewrite the major part of U-Boot or to cripple it

noise ^ not

Quoted 3 lines

to uselessness if you try to release it under GPLv3. I cannot see anybody investing any efforts in that direction; all these threads about a potential GPLv3 switch are just a hollow scarecrow.

sorry, can't parse that.

Quoted 7 lines
Quoted 3 lines

no, this was nicely formatted in my mail editor. Just wanted to point out you forgot a "not". You mentioned "to cripple it" you more then like ment "to _not_ cripple it". But the whitespace got lost along the way.

No, I did NOT forget a "not".

There is an awful lot of GPLv2 (V2 only) code in U-Boot.

OK, so we need a GPLv2-compatible header file. That's the conclusion.

Can we get one or how shall we proceed in the opposite case please?

Best regards,
Marek Vasut

#24 lore raw

PATCH v4 4/5 usb/gadget: fastboot: add sparse image definitions

Dear Marek,

Quoted 2 lines · In message <[email protected]> you wrote:

OK, so we need a GPLv2-compatible header file. That's the conclusion.

Well, GPLv2 compatible might be acceptable, but GPLv2+ compatible woould be best.

Best regards,

Wolfgang Denk

Signature · 4 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
Human beings were created by water to transport it uphill.
#25 lore raw

PATCH v4 4/5 usb/gadget: fastboot: add sparse image definitions

Quoted 7 lines · Wolfgang Denk

Dear Marek,

Quoted 1 line · In message <[email protected]> you wrote:

OK, so we need a GPLv2-compatible header file. That's the conclusion.

Well, GPLv2 compatible might be acceptable, but GPLv2+ compatible woould be best.

I was talking to Hans about this yesterday (and who was dropped from the CC for some reason) and it turns out the easy way out here is to just reimplement the header. I would like him to take a look and express his opinion properly though.

Best regards,
Marek Vasut

author
#26 lore raw

PATCH v4 4/5 usb/gadget: fastboot: add sparse image definitions

( Google agreed to submit a patch with BSD3 license.... stay tuned!!! )

Quoted 16 lines · Marek Vasut
Quoted 7 lines · Wolfgang Denk

Dear Marek,

Quoted 1 line · In message <[email protected]> you wrote:

OK, so we need a GPLv2-compatible header file. That's the conclusion.

Well, GPLv2 compatible might be acceptable, but GPLv2+ compatible woould be best.

I was talking to Hans about this yesterday (and who was dropped from the CC for some reason) and it turns out the easy way out here is to just reimplement the header. I would like him to take a look and express his opinion properly though.

Best regards,
Marek Vasut

#27 lore raw

PATCH v4 4/5 usb/gadget: fastboot: add sparse image definitions

Quoted 1 line · Steve Rae

( Google agreed to submit a patch with BSD3 license.... stay tuned!!! )

Thank you for your work and perseverance, really !

Best regards,
Marek Vasut

#28 lore raw

PATCH v4 4/5 usb/gadget: fastboot: add sparse image definitions

In reply to Jeroen Hofstee
Quoted 18 lines · Jeroen Hofstee
Quoted 17 lines · Wolfgang Denk

Dear Jeroen,

Quoted 13 lines · In message <[email protected]> you wrote:
Quoted 6 lines · Wolfgang Denk

<snip>

Quoted 2 lines

So the argument about incompatible licenses is valid here. Should u-boot switch to GPLv3 you need to hunt down that file again and this

You would have to rewrite the major part of U-Boot or to cripple it

noise ^ not

Quoted 3 lines

to uselessness if you try to release it under GPLv3. I cannot see anybody investing any efforts in that direction; all these threads about a potential GPLv3 switch are just a hollow scarecrow.

Quoted 5 lines
Quoted 1 line

sorry, can't parse that.

no, this was nicely formatted in my mail editor. Just wanted to point out you forgot a "not". You mentioned "to cripple it" you more then like ment "to _not_ cripple it". But the whitespace got lost along the way.

Please be more explicit next time, really. It can be difficult to find the balance between keeping the mail short and being explicit, but usually it's sufficient to read the mail after a few minutes and see if you'd understand the message yourself if you got one as such.

Thanks!

Best regards,
Marek Vasut

author
#29 lore raw

PATCH v4 5/5 usb/gadget: fastboot: implement sparse format

In reply to Steve Rae

- add capability to "fastboot flash" with sparse format images

---
I suspect that the "sparse image" handling (ie. the "while (remaining_chunks)" loop) has been implemented elsewhere -- I need help finding the original code to determine any licensing issues....
Thanks, Steve

Changes in v4:
- rearranged "sparse format" support in this patchset, in order to isolate...

Changes in v3: None
Changes in v2: None

 common/fb_mmc.c | 115 ++++++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 112 insertions(+), 3 deletions(-)
common/fb_mmc.c +112 -3
index f42a115..306c102 100644
@@ -1,5 +1,6 @@
 /*
- * Copyright 2014 Broadcom Corporation.
+ * Copyright TODO
+ * Portions Copyright 2014 Broadcom Corporation.
  *
  * SPDX-License-Identifier:	GPL-2.0+
  */
@@ -7,6 +8,7 @@
 #include <common.h>
 #include <fb_mmc.h>
 #include <part.h>
+#include <sparse_format.h>
 
 /* The 64 defined bytes plus \0 */
 #define RESPONSE_LEN	(64 + 1)
@@ -19,6 +21,108 @@ static void fastboot_resp(const char *s)
 	response_str[RESPONSE_LEN - 1] = '\0';
 }
 
+static int is_sparse_image(void *buf)
+{
+	sparse_header_t *s_header = (sparse_header_t *)buf;
+
+	if ((le32_to_cpu(s_header->magic) == SPARSE_HEADER_MAGIC) &&
+	    (le16_to_cpu(s_header->major_version) == 1))
+		return 1;
+
+	return 0;
+}
+
+static void write_sparse_image(block_dev_desc_t *dev_desc,
+		disk_partition_t *info, const char *part_name,
+		void *buffer, unsigned int download_bytes)
+{
+	lbaint_t blk;
+	lbaint_t blkcnt;
+	lbaint_t blks;
+	sparse_header_t *s_header = (sparse_header_t *)buffer;
+	chunk_header_t *c_header;
+	void *buf;
+	uint32_t blk_sz;
+	uint32_t remaining_chunks;
+	uint32_t bytes_written = 0;
+
+	blk_sz = le32_to_cpu(s_header->blk_sz);
+
+	/* verify s_header->blk_sz is exact multiple of info->blksz */
+	if (blk_sz != (blk_sz & ~(info->blksz - 1))) {
+		printf("%s: Sparse image block size issue [%u]\n",
+		       __func__, blk_sz);
+		fastboot_resp("FAILsparse image block size issue");
+		return;
+	}
+
+	if ((le32_to_cpu(s_header->total_blks) * blk_sz) >
+	    (info->size * info->blksz)) {
+		printf("%s: Sparse image is too large for the partition\n",
+		       __func__);
+		fastboot_resp("FAILsparse image is too large");
+		return;
+	}
+
+	puts("Flashing Sparse Image\n");
+
+	remaining_chunks = le32_to_cpu(s_header->total_chunks);
+	c_header = (chunk_header_t *)(buffer +
+	    le16_to_cpu(s_header->file_hdr_sz));
+	blk = info->start;
+	while (remaining_chunks) {
+		blkcnt =
+		    (le32_to_cpu(c_header->chunk_sz) * blk_sz) / info->blksz;
+
+		switch (le16_to_cpu(c_header->chunk_type)) {
+		case CHUNK_TYPE_RAW:
+			buf = (void *)c_header +
+			    le16_to_cpu(s_header->chunk_hdr_sz);
+
+			if (blk + blkcnt > info->start + info->size) {
+				printf(
+				    "%s: Request would exceed partition size!\n",
+				    __func__);
+				fastboot_resp(
+				    "FAILRequest would exceed partition size!");
+				return;
+			}
+
+			blks = dev_desc->block_write(dev_desc->dev, blk, blkcnt,
+						    buf);
+			if (blks != blkcnt) {
+				printf("%s: Write failed " LBAFU "\n",
+				       __func__, blks);
+				fastboot_resp("FAILwrite failure");
+				return;
+			}
+
+			bytes_written += blkcnt * info->blksz;
+			break;
+
+		case CHUNK_TYPE_FILL:
+		case CHUNK_TYPE_DONT_CARE:
+		case CHUNK_TYPE_CRC32:
+			/* do nothing */
+			break;
+
+		default:
+			/* error */
+			printf("%s: Unknown chunk type\n", __func__);
+			fastboot_resp("FAILunknown chunk type in sparse image");
+			return;
+		}
+
+		blk += blkcnt;
+		c_header = (chunk_header_t *)((void *)c_header +
+		    le32_to_cpu(c_header->total_sz));
+		remaining_chunks--;
+	}
+
+	printf("........ wrote %u bytes to '%s'\n", bytes_written, part_name);
+	fastboot_resp("OKAY");
+}
+
 static void write_raw_image(block_dev_desc_t *dev_desc, disk_partition_t *info,
 		const char *part_name, void *buffer,
 		unsigned int download_bytes)
@@ -77,6 +181,11 @@ void fb_mmc_flash_write(const char *cmd, void *download_buffer,
 		return;
 	}
 
-	write_raw_image(dev_desc, &info, cmd, download_buffer,
-			download_bytes);
+	if (is_sparse_image(download_buffer)) {
+		write_sparse_image(dev_desc, &info, cmd, download_buffer,
+				   download_bytes);
+	} else {
+		write_raw_image(dev_desc, &info, cmd, download_buffer,
+				download_bytes);
+	}
 }
Signature · 1 line
1.8.5
#30 lore raw

v4 cover Implement "fastboot flash" for eMMC

In reply to Steve Rae
Quoted 10 lines · Steve Rae

This series implements the "fastboot flash" command for eMMC devices. It supports both raw and sparse images.

NOTES:
- the support for the "fastboot flash" command is enabled with CONFIG_FASTBOOT_FLASH - the support for eMMC is enabled with CONFIG_FASTBOOT_FLASH_MMC_DEV - (future) the support for NAND would be enabled with CONFIG_FASTBOOT_FLASH_NAND(???)

This has been tested on ARMv7.

I'll just wait for Tom's comments on 4/5 and 5/5 and will see then. The 1-3/5 look OK.

Best regards,
Marek Vasut

author
#31 lore raw

v4 cover Implement "fastboot flash" for eMMC

Quoted 10 lines · Marek Vasut
Quoted 9 lines · Steve Rae

This series implements the "fastboot flash" command for eMMC devices. It supports both raw and sparse images.

NOTES:
- the support for the "fastboot flash" command is enabled with CONFIG_FASTBOOT_FLASH - the support for eMMC is enabled with CONFIG_FASTBOOT_FLASH_MMC_DEV - (future) the support for NAND would be enabled with CONFIG_FASTBOOT_FLASH_NAND(???)

Quoted 8 lines
Quoted 1 line

This has been tested on ARMv7.

I'll just wait for Tom's comments on 4/5 and 5/5 and will see then. The 1-3/5 look OK.

Best regards,
Marek Vasut

THANKS!
Steve