Skip to contentSkip to conversation

cmd: add clone command

PATCH Superseded John Chau 2 participants 5 messages Jun 27, 2020 – Aug 5, 2020

lore
Share & tools
lore

John Chau

author
#0 lore raw

PATCH 1/1 cmd: add clone command

From: John Chau <[email protected]>

This patch adds a feature for block device cloning similar to dd command, this should be useful for boot-strapping a device where usb gadget or networking is not available. For instance one can clone a factory image into a blank emmc from an external sd card.

---
 cmd/Kconfig  |   9 +++++
 cmd/Makefile |   1 +
 cmd/clone.c  | 112 +++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 122 insertions(+)
 create mode 100644 cmd/clone.c
cmd/Kconfig +9 -0
index 6403bc45a5..44f96dedcd 100644
@@ -1067,6 +1067,15 @@ config CMD_MMC_SWRITE
 	  Enable support for the "mmc swrite" command to write Android sparse
 	  images to eMMC.
 
+config CMD_CLONE
+	bool "clone"
+	depends on BLK
+	select CLONE
+	help
+	  Enable storage cloning over block devices, useful for 
+	  initial flashing by external block device without network
+	  or usb gadget support.
+	  
 config CMD_MTD
 	bool "mtd"
 	depends on MTD
cmd/Makefile +1 -0
index f1dd513a4b..02663a1c73 100644
@@ -95,6 +95,7 @@ obj-$(CONFIG_CMD_MMC) += mmc.o
 obj-$(CONFIG_MP) += mp.o
 obj-$(CONFIG_CMD_MTD) += mtd.o
 obj-$(CONFIG_CMD_MTDPARTS) += mtdparts.o
+obj-$(CONFIG_CMD_CLONE) += clone.o
 ifneq ($(CONFIG_CMD_NAND)$(CONFIG_CMD_SF),)
 obj-y += legacy-mtd-utils.o
 endif
cmd/clone.c new file +112 -0

112 lines not on this page · raw message

Signature · 1 line
2.25.1
#1 lore raw

PATCH 1/1 cmd: add clone command

Quoted 8 lines · John Chau

From: John Chau <[email protected]>

This patch adds a feature for block device cloning similar to dd command, this should be useful for boot-strapping a device where usb gadget or networking is not available. For instance one can clone a factory image into a blank emmc from an external sd card.

In general, checkpatch.pl complains a lot and those need to be fixed.

[snip]

cmd/Kconfig config CMD_MMC_SWRITE · line 1073

Quoted 4 lines
cmd/Kconfig +4 -0
+config CMD_CLONE
+	bool "clone"
+	depends on BLK
+	select CLONE

There's no "config CLONE" so we don't need this line.

[snip]

cmd/clone.c line 14

Quoted 2 lines
cmd/clone.c new file +2 -0
+//FIXME: we assume blk size of both devices can be divided by 1M, which should be normal
+#define BUFSIZE (1 * 1024 * 1024)

Can we do some run-time checks of the block sizes of each device and confirm this assumption and fail if it's not true?

Finally, we should also enable this on sandbox so that it's build-tested and put through coverity. Thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 659 bytes
Desc: not available
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20200629/febaeda1/attachment.sig>
author
#2 lore raw

PATCH v2 1/1 cmd: add clone command

From: John Chau <[email protected]>

This patch adds a feature for block device cloning similar to dd command, this should be useful for boot-strapping a device where usb gadget or networking is not available. For instance one can clone a factory image into a blank emmc from an external sd card.

---
Changes for v2:
- Coding styles cleanup
- removed useless "select CLONE" line from cmd/Kconfig
- added buffer size check against block size of both devices
- enabled this by default on sandbox in arch/Kconfig

 arch/Kconfig |   1 +
 cmd/Kconfig  |   8 ++++
 cmd/Makefile |   1 +
 cmd/clone.c  | 125 +++++++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 135 insertions(+)
 create mode 100644 cmd/clone.c
arch/Kconfig +1 -0
index ae9c93ed7b..4d7415d426 100644
@@ -136,6 +136,7 @@ config SANDBOX
 	imply ACPI_PMC
 	imply ACPI_PMC_SANDBOX
 	imply CMD_PMC
+	imply CMD_CLONE
 
 config SH
 	bool "SuperH architecture"
cmd/Kconfig +8 -0
index 6403bc45a5..1e95de249f 100644
@@ -1067,6 +1067,14 @@ config CMD_MMC_SWRITE
 	  Enable support for the "mmc swrite" command to write Android sparse
 	  images to eMMC.
 
+config CMD_CLONE
+	bool "clone"
+	depends on BLK
+	help
+	  Enable storage cloning over block devices, useful for
+	  initial flashing by external block device without network
+	  or usb support.
+
 config CMD_MTD
 	bool "mtd"
 	depends on MTD
cmd/Makefile +1 -0
index f1dd513a4b..02663a1c73 100644
@@ -95,6 +95,7 @@ obj-$(CONFIG_CMD_MMC) += mmc.o
 obj-$(CONFIG_MP) += mp.o
 obj-$(CONFIG_CMD_MTD) += mtd.o
 obj-$(CONFIG_CMD_MTDPARTS) += mtdparts.o
+obj-$(CONFIG_CMD_CLONE) += clone.o
 ifneq ($(CONFIG_CMD_NAND)$(CONFIG_CMD_SF),)
 obj-y += legacy-mtd-utils.o
 endif
cmd/clone.c new file +125 -0

125 lines not on this page · raw message

Signature · 1 line
2.25.1
author
#3 lore raw

PATCH v3 1/1 cmd: add clone command

In reply to Tom Rini

From: John Chau <[email protected]>

This patch adds a feature for block device cloning similar to dd command, this should be useful for boot-strapping a device where usb gadget or networking is not available. For instance one can clone a factory image into a blank emmc from an external sd card.

---
Changes for v2:
- Coding styles cleanup
- removed useless "select CLONE" line from cmd/Kconfig
- added buffer size check against block size of both devices
- enabled this by default on sandbox in arch/Kconfig
Changes for v3:
- fixed buffer size check (condition inverted)

 arch/Kconfig |   1 +
 cmd/Kconfig  |   8 ++++
 cmd/Makefile |   1 +
 cmd/clone.c  | 125 +++++++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 135 insertions(+)
 create mode 100644 cmd/clone.c
arch/Kconfig +1 -0
index ae9c93ed7b..4d7415d426 100644
@@ -136,6 +136,7 @@ config SANDBOX
 	imply ACPI_PMC
 	imply ACPI_PMC_SANDBOX
 	imply CMD_PMC
+	imply CMD_CLONE
 
 config SH
 	bool "SuperH architecture"
cmd/Kconfig +8 -0
index 6403bc45a5..1e95de249f 100644
@@ -1067,6 +1067,14 @@ config CMD_MMC_SWRITE
 	  Enable support for the "mmc swrite" command to write Android sparse
 	  images to eMMC.
 
+config CMD_CLONE
+	bool "clone"
+	depends on BLK
+	help
+	  Enable storage cloning over block devices, useful for
+	  initial flashing by external block device without network
+	  or usb support.
+
 config CMD_MTD
 	bool "mtd"
 	depends on MTD
cmd/Makefile +1 -0
index f1dd513a4b..02663a1c73 100644
@@ -95,6 +95,7 @@ obj-$(CONFIG_CMD_MMC) += mmc.o
 obj-$(CONFIG_MP) += mp.o
 obj-$(CONFIG_CMD_MTD) += mtd.o
 obj-$(CONFIG_CMD_MTDPARTS) += mtdparts.o
+obj-$(CONFIG_CMD_CLONE) += clone.o
 ifneq ($(CONFIG_CMD_NAND)$(CONFIG_CMD_SF),)
 obj-y += legacy-mtd-utils.o
 endif
cmd/clone.c new file +125 -0

125 lines not on this page · raw message

Signature · 1 line
2.25.1
#4 lore raw

PATCH v3 1/1 cmd: add clone command

Quoted 8 lines · John Chau

From: John Chau <[email protected]>

This patch adds a feature for block device cloning similar to dd command, this should be useful for boot-strapping a device where usb gadget or networking is not available. For instance one can clone a factory image into a blank emmc from an external sd card.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 659 bytes
Desc: not available
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20200805/290587e6/attachment.sig>