Skip to content

Commit f2d01e5

Browse files
committed
snagrecover: Add rockchip support
Add support for booting a rockchip bin file, made with boot_merger. It can be: - a file containing the rockchip miniloader, but in this case, it's not useful, as rockusb is not implemented - a file containing uboot tpl and spl. In this case, if u-boot is configured for SPL DFU, the snagrecover configuration file may specify an u-boot FIT image to load into the first DFU slot. This will allow booting u-boot proper and then to fastboot/ums/dfu/... to flash. Signed-off-by: Arnaud Patard <[email protected]>
1 parent bf88b8a commit f2d01e5

File tree

10 files changed

+285
-1
lines changed

10 files changed

+285
-1
lines changed

docs/fw_binaries.md

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,3 +289,142 @@ extract the FSBL and PMUFW from the complete boot image.
289289
configuration:
290290
* path
291291

292+
## For Rockchip devices
293+
294+
Current implementation of support for the Rockchip SoCs, RAMboot and
295+
SPL DFU are supported.
296+
297+
As there's no implementation for Rockchip USB protocol support, it is
298+
possible to push the DDR init files and SPL files from Rockchip but the next
299+
step will fail.
300+
301+
Mainline u-boot does not support boot from RAM and boot from SPL DFU,
302+
it has to be patched.
303+
304+
The patches have been sent to the u-boot mailing list by their authors
305+
and not yet merged. The patches can all be found inside this
306+
[merge request](https://gitlab.collabora.com/hardware-enablement/rockchip-3588/u-boot/-/merge_requests/7).
307+
308+
### Using binary generated by Rockchip's ``boot_merger``
309+
310+
[example](../src/snagrecover/templates/rockchip-merger.yaml)
311+
312+
Snagboot can upload the ``CODE471_OPTION`` and ``CODE472_OPTION`` of a binary
313+
generated with the ``boot_merger`` tool and configuration files from
314+
[Rockchip rkbin](https://github.com/radxa/rkbin/tree/develop-v2024.03/).
315+
316+
In case of u-boot, this would mean to upload the TPL, SPL and then use SPL DFU
317+
to boot u-boot proper (see later section for SPL DFU).
318+
319+
An example configuration for rk3399 would be:
320+
```
321+
[CHIP_NAME]
322+
NAME=RK330C
323+
[VERSION]
324+
MAJOR=1
325+
MINOR=123
326+
[CODE471_OPTION]
327+
NUM=1
328+
Path1=tpl/u-boot-tpl-dtb.bin
329+
Sleep=1
330+
[CODE472_OPTION]
331+
NUM=1
332+
Path1=spl/u-boot-spl-dtb.bin
333+
Sleep=3000
334+
[LOADER_OPTION]
335+
NUM=2
336+
LOADER1=FlashData
337+
LOADER2=FlashBoot
338+
FlashData=spl/u-boot-spl-dtb.bin
339+
FlashBoot=u-boot.itb
340+
[OUTPUT]
341+
PATH=rk3399_uboot.bin
342+
[FLAG]
343+
471_RC4_OFF=false
344+
```
345+
346+
The ``tpl/u-boot-tpl-dtb.bin``, ``spl/u-boot-spl-dtb.bin``, ``u-boot.itb``
347+
files are generated during u-boot's build. Please note has the ``LOADER_OPTION``
348+
is not handled by snagboot.
349+
350+
The configuration parameters are:
351+
352+
**xpl:** Binary blob generated with bootmerger. For instance, here, ``rk3399_uboot.bin``.
353+
* path: path to the blob
354+
355+
**u-boot-fit:** U-boot FIT image.
356+
* path: Path to the FIT image. Typically, ``u-boot.itb``
357+
358+
359+
### Boot from Ram
360+
361+
[example](../src/snagrecover/templates/rockchip-ramboot.yaml)
362+
363+
When building u-boot with the previously mentioned patches, u-boot will generate two files:
364+
365+
- ``u-boot-rockchip-usb471.bin``
366+
- ``u-boot-rockchip-usb472.bin``
367+
368+
These are the files needed to boot from RAM.
369+
370+
The configuration parameters are:
371+
372+
**code471:** File to use for maskrom code 0x471.
373+
374+
configuration:
375+
* path: Path to the ``u-boot-rockchip-usb471.bin`` file
376+
* delay: Optional delay in milliseconds before loading next binary
377+
378+
**code472:** File to use for maskrom code 0x472.
379+
380+
configuration:
381+
* path: Path to the ``u-boot-rockchip-usb472.bin`` file
382+
383+
384+
### Boot from SPL DFU
385+
386+
[example](../src/snagrecover/templates/rockchip-spl-dfu.yaml)
387+
388+
To enable u-boot with SPL DFU support in the u-boot configuration, ensure that the
389+
following options are enabled:
390+
391+
```
392+
CONFIG_SPL_DM_USB_GADGET=y
393+
CONFIG_SPL_USB_GADGET=y
394+
CONFIG_SPL_DFU=y
395+
```
396+
397+
On some systems, rebooting the system won't reset the memory content. This means that
398+
booting over DFU after having done a boot from RAM will result in u-boot loading the
399+
u-boot version from the boot from RAM boot and won't try to load u-boot over DFU.
400+
401+
To solve this, disable boot from RAM with:
402+
403+
```
404+
# CONFIG_SPL_RAM_DEVICE is not set
405+
```
406+
407+
The (SPL) USB gadget driver needs to be enabled too.
408+
409+
At the end of the build, the following files will be needed:
410+
411+
- ``mkimage-in-simple-bin.mkimage-u-boot-tpl`` or ``mkimage-in-simple-bin.mkimage-rockchip-tpl``
412+
- ``mkimage-in-simple-bin.mkimage-u-boot-spl``
413+
- ``u-boot.itb``
414+
415+
The configuration parameters are:
416+
417+
**code471:** File to use for maskrom code 0x471.
418+
419+
configuration:
420+
* path: Path to the TPL file. For instance, ``mkimage-in-simple-bin.mkimage-rockchip-tpl``.
421+
* delay: Optional delay in milliseconds before loading next binary
422+
423+
**code472:** File to use for maskrom code 0x472.
424+
425+
configuration:
426+
* path: Path to the SPL. For instance, ``mkimage-in-simple-bin.mkimage-u-boot-spl``.
427+
* delay: Optional delay in milliseconds before loading next binary
428+
429+
**u-boot-fit:** U-boot FIT image.
430+
* path: Path to the FIT image. Typically, ``u-boot.itb``

src/snagrecover/50-snagboot.rules

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,3 +76,21 @@ SUBSYSTEM=="usb", ATTRS{idVendor}=="0451", ATTRS{idProduct}=="d022", MODE="0660"
7676

7777
#Xilinx rules
7878
SUBSYSTEM=="usb", ATTRS{idVendor}=="03fd", ATTRS{idProduct}=="0050", MODE="0660", TAG+="uaccess"
79+
80+
#Rockchip systems
81+
SUBSYSTEM=="usb", ATTRS{idVendor}=="2207", ATTRS{idProduct}=="2207", MODE="0660", TAG+="uaccess"
82+
SUBSYSTEM=="usb", ATTRS{idVendor}=="2207", ATTRS{idProduct}=="110a", MODE="0660", TAG+="uaccess"
83+
SUBSYSTEM=="usb", ATTRS{idVendor}=="2207", ATTRS{idProduct}=="110b", MODE="0660", TAG+="uaccess"
84+
SUBSYSTEM=="usb", ATTRS{idVendor}=="2207", ATTRS{idProduct}=="300a", MODE="0660", TAG+="uaccess"
85+
SUBSYSTEM=="usb", ATTRS{idVendor}=="2207", ATTRS{idProduct}=="301a", MODE="0660", TAG+="uaccess"
86+
SUBSYSTEM=="usb", ATTRS{idVendor}=="2207", ATTRS{idProduct}=="310b", MODE="0660", TAG+="uaccess"
87+
SUBSYSTEM=="usb", ATTRS{idVendor}=="2207", ATTRS{idProduct}=="310c", MODE="0660", TAG+="uaccess"
88+
SUBSYSTEM=="usb", ATTRS{idVendor}=="2207", ATTRS{idProduct}=="320a", MODE="0660", TAG+="uaccess"
89+
SUBSYSTEM=="usb", ATTRS{idVendor}=="2207", ATTRS{idProduct}=="320b", MODE="0660", TAG+="uaccess"
90+
SUBSYSTEM=="usb", ATTRS{idVendor}=="2207", ATTRS{idProduct}=="320c", MODE="0660", TAG+="uaccess"
91+
SUBSYSTEM=="usb", ATTRS{idVendor}=="2207", ATTRS{idProduct}=="330a", MODE="0660", TAG+="uaccess"
92+
SUBSYSTEM=="usb", ATTRS{idVendor}=="2207", ATTRS{idProduct}=="330c", MODE="0660", TAG+="uaccess"
93+
SUBSYSTEM=="usb", ATTRS{idVendor}=="2207", ATTRS{idProduct}=="330d", MODE="0660", TAG+="uaccess"
94+
SUBSYSTEM=="usb", ATTRS{idVendor}=="2207", ATTRS{idProduct}=="330e", MODE="0660", TAG+="uaccess"
95+
SUBSYSTEM=="usb", ATTRS{idVendor}=="2207", ATTRS{idProduct}=="350a", MODE="0660", TAG+="uaccess"
96+
SUBSYSTEM=="usb", ATTRS{idVendor}=="2207", ATTRS{idProduct}=="350b", MODE="0660", TAG+="uaccess"

src/snagrecover/config.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,23 @@
5252
"imx8mm": "1fc9:0134",
5353
"imx8mq": "1fc9:012b",
5454
"imx53" : "15a2:004e",
55+
},
56+
"rockchip": {
57+
"rv1108": "2207:110a",
58+
"rv1126": "2207:110b",
59+
"rk3066": "2207:300a",
60+
"rk3036": "2207:301a",
61+
"rk3188": "2207:310b",
62+
"rk3128": "2207:310c",
63+
"rk3288": "2207:320a",
64+
"rk322x": "2207:320b",
65+
"rk3328": "2207:320c",
66+
"rk3368": "2207:330a",
67+
"rk3399": "2207:330c",
68+
"px30": "2207:330d",
69+
"rk3308": "2207:330e",
70+
"rk3568": "2207:350a",
71+
"rk3588": "2207:350b"
5572
}
5673
}
5774

@@ -80,6 +97,8 @@ def init_config(args: list):
8097
if args.usb_path is None:
8198
if soc_family == "imx":
8299
usb_ids = default_usb_ids["imx"][soc_model]
100+
elif soc_family == "rockchip":
101+
usb_ids = default_usb_ids["rockchip"][soc_model]
83102
else:
84103
usb_ids = default_usb_ids[soc_family]
85104

src/snagrecover/firmware/firmware.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,9 @@ def run_firmware(port, fw_name: str, subfw_name: str = ""):
146146
elif soc_family == "zynqmp":
147147
from snagrecover.firmware.zynqmp_fw import zynqmp_run
148148
zynqmp_run(port, fw_name, fw_blob, subfw_name)
149+
elif soc_family == "rockchip":
150+
from snagrecover.firmware.rk_fw import rockchip_run
151+
rockchip_run(port, fw_name, fw_blob)
149152
else:
150153
raise Exception(f"Unsupported SoC family {soc_family}")
151154
logger.info(f"Done installing firmware {fw_name}")
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import usb
2+
import logging
3+
logger = logging.getLogger("snagrecover")
4+
from snagrecover.firmware.firmware import run_firmware
5+
from snagrecover.utils import get_usb
6+
from snagrecover.utils import cli_error
7+
from snagrecover.config import recovery_config
8+
import time
9+
10+
11+
def main():
12+
usb_addr = recovery_config["usb_path"]
13+
dev = get_usb(usb_addr)
14+
15+
# Blob made with boot_merger
16+
if "xpl" in recovery_config["firmware"]:
17+
try:
18+
run_firmware(dev, "xpl")
19+
usb.util.dispose_resources(dev)
20+
except Exception as e:
21+
cli_error(f"Failed to run firmware: {e}")
22+
23+
# u-boot binaries.
24+
elif "code471" in recovery_config["firmware"] and "code472" in recovery_config["firmware"]:
25+
try:
26+
run_firmware(dev, "code471")
27+
usb.util.dispose_resources(dev)
28+
except Exception as e:
29+
cli_error(f"Failed to run code471 firmware: {e}")
30+
if "delay" in recovery_config["firmware"]["code471"]:
31+
delay = recovery_config["firmware"]["code471"]["delay"]
32+
logger.info(f"Sleeping {delay}ms")
33+
time.sleep(delay / 1000)
34+
try:
35+
run_firmware(dev, "code472")
36+
usb.util.dispose_resources(dev)
37+
except Exception as e:
38+
cli_error(f"Failed to run code472 firmware: {e}")
39+
if "delay" in recovery_config["firmware"]["code472"]:
40+
delay = recovery_config["firmware"]["code472"]["delay"]
41+
logger.info(f"Sleeping {delay}ms")
42+
time.sleep(delay / 1000)
43+
else:
44+
cli_error(("Missing xpl or "
45+
"code471 (*_ddr_*.bin' or 'mkimage-in-simple-bin.mkimage-u-boot-tpl') / "
46+
"code472 ('*_usbplug_*.bin' or 'mkimage-in-simple-bin.mkimage-u-boot-spl')"
47+
"binary configuration."))
48+
49+
if "u-boot-fit" in recovery_config["firmware"]:
50+
try:
51+
dev = get_usb(usb_addr)
52+
run_firmware(dev, "u-boot-fit")
53+
except Exception as e:
54+
cli_error(f"Failed to load u-boot.itb: {e}")

src/snagrecover/supported_socs.yaml

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ tested:
5757
family: stm32mp
5858
zynqmp:
5959
family: zynqmp
60+
rk3399:
61+
family: rockchip
62+
rk3588:
63+
family: rockchip
6064
untested:
6165
a10:
6266
family: sunxi
@@ -144,4 +148,29 @@ untested:
144148
family: sunxi
145149
v853:
146150
family: sunxi
147-
151+
rv1108:
152+
family: rockchip
153+
rv1126:
154+
family: rockchip
155+
rk3066:
156+
family: rockchip
157+
rk3036:
158+
family: rockchip
159+
rk3188:
160+
family: rockchip
161+
rk3128:
162+
family: rockchip
163+
rk3288:
164+
family: rockchip
165+
rk322x:
166+
family: rockchip
167+
rk3328:
168+
family: rockchip
169+
rk3368:
170+
family: rockchip
171+
px30:
172+
family: rockchip
173+
rk3308:
174+
family: rockchip
175+
rk3568:
176+
family: rockchip
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
xpl:
2+
# u-boot TPL+SPL with SPL configured for DFU boot
3+
path: rk3399_uboot.bin
4+
u-boot-fit:
5+
# proper u-boot
6+
path: u-boot.itb
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
code471:
2+
path: u-boot-rockchip-usb471.bin
3+
delay: 1
4+
code472:
5+
path: u-boot-rockchip-usb472.bin
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
code471:
2+
path: mkimage-in-simple-bin.mkimage-u-boot-tpl
3+
delay: 1
4+
code472:
5+
path: mkimage-in-simple-bin.mkimage-u-boot-spl
6+
delay: 10000
7+
u-boot-fit:
8+
path: u-boot.itb

src/snagrecover/utils.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,9 @@ def get_recovery(soc_family: str):
191191
elif soc_family == "zynqmp":
192192
from snagrecover.recoveries.zynqmp import main as zynqmp_recovery
193193
return zynqmp_recovery
194+
elif soc_family == "rockchip":
195+
from snagrecover.recoveries.rockchip import main as rockchip_recovery
196+
return rockchip_recovery
194197
else:
195198
cli_error(f"unsupported board family {soc_family}")
196199

0 commit comments

Comments
 (0)