All of lore.kernel.org
 help / color / mirror / Atom feed
* [U-Boot] tools: socfpga: image installation script
@ 2017-05-23 12:36 Pavel Machek
  2017-05-23 12:59 ` Marek Vasut
  0 siblings, 1 reply; 2+ messages in thread
From: Pavel Machek @ 2017-05-23 12:36 UTC (permalink / raw)
  To: u-boot

Installing u-boot on socfpga is not trivial. Yes, it can be done with
dd, but it is easy to make a typo and destroy a partition. Introduce a
script that knows how to install all the copies, and actually checks
signatures so that killing data is not trivial.

Signed-of-by: Pavel Machek <pavel@denx.de>

diff --git a/tools/socfpga_install b/tools/socfpga_install
new file mode 100755
index 0000000..d02e73c
--- /dev/null
+++ b/tools/socfpga_install
@@ -0,0 +1,50 @@
+#!/usr/bin/python3
+# Copyright 2015 Pavel Machek, Denx
+# SPDX-License-Identifier:	GPL-2.0+
+#
+# Usage: sudo socfpga_install /dev/sdb3 u-boot-spl.bin u-boot-dts.img
+
+import subprocess
+import sys
+import os
+
+print("install device ", sys.argv[1])
+device = open(sys.argv[1], "r+b")
+
+sig = device.read(0x44)
+if sig[0x40] != 0x41 or sig[0x41] != 0x53 or \
+   sig[0x42] != 0x30 or sig[0x43] != 0x31:
+    print("Do not see AS01 signature, do you have right partition?")
+    sys.exit(1)
+else:
+    print("Have partition with right signature")
+
+spl = sys.argv[2]
+if spl == "_":
+    print("Skipping u-boot-spl installation")
+else:
+    print("u-boot-spl.bin at ", spl)
+
+
+    res = subprocess.check_call(["tools/mkimage", "-T", "socfpgaimage", "-d", spl, "img.tmp"])
+    if res != 0:
+        print("mkimage failed.")
+        sys.exit(1)
+    device.seek(0)
+
+    spl_bin = open("img.tmp", "rb").read()
+    if len(spl_bin) != 65536:
+        print("Preloader image has wrong length.")
+        sys.exit(1)
+ 
+    device.write(spl_bin)
+    device.write(spl_bin)
+    device.write(spl_bin)
+    device.write(spl_bin)
+
+print("u-boot.img at ", sys.argv[3])
+uboot_bin = open(sys.argv[3], "rb").read()
+print("Have u-boot, %d bytes" % len(uboot_bin))
+device.seek(65536*4)
+device.write(uboot_bin)
+print("All done.")


-- 
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20170523/83cb9a5d/attachment.sig>

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* [U-Boot] tools: socfpga: image installation script
  2017-05-23 12:36 [U-Boot] tools: socfpga: image installation script Pavel Machek
@ 2017-05-23 12:59 ` Marek Vasut
  0 siblings, 0 replies; 2+ messages in thread
From: Marek Vasut @ 2017-05-23 12:59 UTC (permalink / raw)
  To: u-boot

On 05/23/2017 02:36 PM, Pavel Machek wrote:
> Installing u-boot on socfpga is not trivial. Yes, it can be done with
> dd, but it is easy to make a typo and destroy a partition. Introduce a
> script that knows how to install all the copies, and actually checks
> signatures so that killing data is not trivial.
> 
> Signed-of-by: Pavel Machek <pavel@denx.de>
> 
> diff --git a/tools/socfpga_install b/tools/socfpga_install
> new file mode 100755
> index 0000000..d02e73c
> --- /dev/null
> +++ b/tools/socfpga_install
> @@ -0,0 +1,50 @@
> +#!/usr/bin/python3
> +# Copyright 2015 Pavel Machek, Denx
> +# SPDX-License-Identifier:	GPL-2.0+
> +#
> +# Usage: sudo socfpga_install /dev/sdb3 u-boot-spl.bin u-boot-dts.img

This u-boot-spl.img and u-boot-dts.img is superseded by
u-boot-with-spl.sfp for a long time. You can just dd that to partition
0xa2 and be done with it, no need to manually do what U-Boot buildsystem
does for you.

> +import subprocess
> +import sys
> +import os
> +
> +print("install device ", sys.argv[1])
> +device = open(sys.argv[1], "r+b")
> +
> +sig = device.read(0x44)
> +if sig[0x40] != 0x41 or sig[0x41] != 0x53 or \
> +   sig[0x42] != 0x30 or sig[0x43] != 0x31:
> +    print("Do not see AS01 signature, do you have right partition?")
> +    sys.exit(1)
> +else:
> +    print("Have partition with right signature")
> +
> +spl = sys.argv[2]
> +if spl == "_":
> +    print("Skipping u-boot-spl installation")
> +else:
> +    print("u-boot-spl.bin at ", spl)
> +
> +
> +    res = subprocess.check_call(["tools/mkimage", "-T", "socfpgaimage", "-d", spl, "img.tmp"])
> +    if res != 0:
> +        print("mkimage failed.")
> +        sys.exit(1)
> +    device.seek(0)
> +
> +    spl_bin = open("img.tmp", "rb").read()
> +    if len(spl_bin) != 65536:
> +        print("Preloader image has wrong length.")
> +        sys.exit(1)
> + 
> +    device.write(spl_bin)
> +    device.write(spl_bin)
> +    device.write(spl_bin)
> +    device.write(spl_bin)
> +
> +print("u-boot.img at ", sys.argv[3])
> +uboot_bin = open(sys.argv[3], "rb").read()
> +print("Have u-boot, %d bytes" % len(uboot_bin))
> +device.seek(65536*4)
> +device.write(uboot_bin)
> +print("All done.")
> 
> 


-- 
Best regards,
Marek Vasut

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2017-05-23 12:59 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-05-23 12:36 [U-Boot] tools: socfpga: image installation script Pavel Machek
2017-05-23 12:59 ` Marek Vasut

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.