diff mbox series

[LEDE-DEV,2/3] scripts: add EVA ramboot script

Message ID 20180309191717.19545-2-Valentin.Spreckels@Informatik.Uni-Oldenburg.DE
State Accepted
Delegated to: Mathias Kresin
Headers show
Series [LEDE-DEV,1/3] fritz-tools: add fritz_tffs_nand_read tool | expand

Commit Message

Valentin Spreckels March 9, 2018, 7:17 p.m. UTC
The bootloader on the FRITZ!Box 7412 crashes when flashing images. Thus
the AVM recovery tool uses another approach: It uses the bootloader to
load a small linux system into the ram and boot it from there. This
system will then flash the image.

This script mimics the behavior: It loads an openwrt initramfs image.
After this a sysupgrade can be done to persistently install openwrt.

Signed-off-by: Valentin Spreckels <Valentin.Spreckels@Informatik.Uni-Oldenburg.DE>
---
 scripts/flashing/eva_ramboot.py | 37 +++++++++++++++++++++++++++++++++++++
 1 file changed, 37 insertions(+)
 create mode 100755 scripts/flashing/eva_ramboot.py

Comments

John Crispin March 9, 2018, 7:52 p.m. UTC | #1
On 09/03/18 20:17, Valentin Spreckels wrote:
> The bootloader on the FRITZ!Box 7412 crashes when flashing images. Thus
> the AVM recovery tool uses another approach: It uses the bootloader to
> load a small linux system into the ram and boot it from there. This
> system will then flash the image.
>
> This script mimics the behavior: It loads an openwrt initramfs image.
> After this a sysupgrade can be done to persistently install openwrt.
>
> Signed-off-by: Valentin Spreckels <Valentin.Spreckels@Informatik.Uni-Oldenburg.DE>

I have been using an ugly shell script to do the same for a few years so ...

Acked-by: John Crispin <john@phrozen.org>

> ---
>   scripts/flashing/eva_ramboot.py | 37 +++++++++++++++++++++++++++++++++++++
>   1 file changed, 37 insertions(+)
>   create mode 100755 scripts/flashing/eva_ramboot.py
>
> diff --git a/scripts/flashing/eva_ramboot.py b/scripts/flashing/eva_ramboot.py
> new file mode 100755
> index 0000000000..b825d2768b
> --- /dev/null
> +++ b/scripts/flashing/eva_ramboot.py
> @@ -0,0 +1,37 @@
> +#!/usr/bin/python
> +
> +from ftplib import FTP
> +from sys import argv
> +from os import stat
> +
> +assert len(argv) == 3
> +ip = argv[1]
> +image = argv[2]
> +
> +size = stat(image).st_size
> +# arbitrary size limit, to prevent the address calculations from overflows etc.
> +assert size < 0x2000000
> +
> +# We need to align the address. A page boundary seems to be sufficient on 7362sl
> +# and 7412
> +addr = ((0x8000000 - size) & ~0xfff)
> +haddr = 0x80000000 + addr
> +img = open(image, "rb")
> +
> +ftp = FTP(ip, 'adam2', 'adam2')
> +
> +def adam(cmd):
> +	print("> %s"%(cmd))
> +	resp = ftp.sendcmd(cmd)
> +	print("< %s"%(resp))
> +	assert resp[0:3] == "200"
> +
> +ftp.set_pasv(True)
> +# The following parameters allow booting the avm recovery system with this
> +# script.
> +adam('SETENV memsize 0x%08x'%(addr))
> +adam('SETENV kernel_args_tmp mtdram1=0x%08x,0x88000000'%(haddr))
> +adam('MEDIA SDRAM')
> +ftp.storbinary('STOR 0x%08x 0x88000000'%(haddr), img)
> +img.close()
> +ftp.close()
diff mbox series

Patch

diff --git a/scripts/flashing/eva_ramboot.py b/scripts/flashing/eva_ramboot.py
new file mode 100755
index 0000000000..b825d2768b
--- /dev/null
+++ b/scripts/flashing/eva_ramboot.py
@@ -0,0 +1,37 @@ 
+#!/usr/bin/python
+
+from ftplib import FTP
+from sys import argv
+from os import stat
+
+assert len(argv) == 3
+ip = argv[1]
+image = argv[2]
+
+size = stat(image).st_size
+# arbitrary size limit, to prevent the address calculations from overflows etc.
+assert size < 0x2000000
+
+# We need to align the address. A page boundary seems to be sufficient on 7362sl
+# and 7412
+addr = ((0x8000000 - size) & ~0xfff)
+haddr = 0x80000000 + addr
+img = open(image, "rb")
+
+ftp = FTP(ip, 'adam2', 'adam2')
+
+def adam(cmd):
+	print("> %s"%(cmd))
+	resp = ftp.sendcmd(cmd)
+	print("< %s"%(resp))
+	assert resp[0:3] == "200"
+
+ftp.set_pasv(True)
+# The following parameters allow booting the avm recovery system with this
+# script.
+adam('SETENV memsize 0x%08x'%(addr))
+adam('SETENV kernel_args_tmp mtdram1=0x%08x,0x88000000'%(haddr))
+adam('MEDIA SDRAM')
+ftp.storbinary('STOR 0x%08x 0x88000000'%(haddr), img)
+img.close()
+ftp.close()