Skip to content

Commit 9a5548c

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 48d22f6 commit 9a5548c

File tree

9 files changed

+135
-1
lines changed

9 files changed

+135
-1
lines changed

src/snagrecover/50-snagboot.rules

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,3 +76,14 @@ 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}=="301a", MODE="0660", TAG+="uaccess"
82+
SUBSYSTEM=="usb", ATTRS{idVendor}=="2207", ATTRS{idProduct}=="310c", MODE="0660", TAG+="uaccess"
83+
SUBSYSTEM=="usb", ATTRS{idVendor}=="2207", ATTRS{idProduct}=="320b", MODE="0660", TAG+="uaccess"
84+
SUBSYSTEM=="usb", ATTRS{idVendor}=="2207", ATTRS{idProduct}=="320a", MODE="0660", TAG+="uaccess"
85+
SUBSYSTEM=="usb", ATTRS{idVendor}=="2207", ATTRS{idProduct}=="320c", MODE="0660", TAG+="uaccess"
86+
SUBSYSTEM=="usb", ATTRS{idVendor}=="2207", ATTRS{idProduct}=="330a", MODE="0660", TAG+="uaccess"
87+
SUBSYSTEM=="usb", ATTRS{idVendor}=="2207", ATTRS{idProduct}=="330c", MODE="0660", TAG+="uaccess"
88+
SUBSYSTEM=="usb", ATTRS{idVendor}=="2207", ATTRS{idProduct}=="350a", MODE="0660", TAG+="uaccess"
89+
SUBSYSTEM=="usb", ATTRS{idVendor}=="2207", ATTRS{idProduct}=="350b", MODE="0660", TAG+="uaccess"

src/snagrecover/config.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,17 @@
5151
"imx8mm": "1fc9:0134",
5252
"imx8mq": "1fc9:012b",
5353
"imx53" : "15a2:004e",
54+
},
55+
"rockchip": {
56+
"rk3036": "2207:310a",
57+
"rk3128": "2207:310c",
58+
"rk3229": "2207:320b",
59+
"rk3288": "2207:320a",
60+
"rk3328": "2207:320c",
61+
"rk3368": "2207:330a",
62+
"rk3399": "2207:330c",
63+
"rk3566": "2207:350a",
64+
"rk3588": "2207:350b"
5465
}
5566
}
5667

@@ -79,6 +90,8 @@ def init_config(args: list):
7990
if args.usb_path is None:
8091
if soc_family == "imx":
8192
usb_ids = default_usb_ids["imx"][soc_model]
93+
elif soc_family == "rockchip":
94+
usb_ids = default_usb_ids["rockchip"][soc_model]
8295
else:
8396
usb_ids = default_usb_ids[soc_family]
8497

src/snagrecover/firmware/firmware.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,11 @@ def run_firmware(port, fw_name: str, subfw_name: str = ""):
122122
elif soc_family == "zynqmp":
123123
from snagrecover.firmware.zynqmp_fw import zynqmp_run
124124
zynqmp_run(port, fw_name, fw_blob, subfw_name)
125+
elif soc_family == "rockchip":
126+
from snagrecover.firmware.rk_fw import rockchip_run, NEWIDB_LIST
127+
if recovery_config["soc_model"] in NEWIDB_LIST and fw_name.startswith("code47"):
128+
raise Exception("Only files generated with boot_merger are supported for this SoC")
129+
rockchip_run(port, fw_name, fw_blob)
125130
else:
126131
raise Exception(f"Unsupported SoC family {soc_family}")
127132
logger.info(f"Done installing firmware {fw_name}")

src/snagrecover/firmware/rk_fw.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
logger = logging.getLogger("snagrecover")
2020
from snagrecover.protocols import rockchip
2121

22+
# List generated with a grep on rkbin repository
23+
NEWIDB_LIST = [ "rk3506", "rk3506b", "rk3528", "rk3562", "rk3566", "rk3568", "rk3576", "rk3583", "rk3588", "rv1103b", "rv1106" ]
24+
2225
BOOTTAG = b"BOOT"
2326
LDRTAG = b"LDR "
2427
TAG_LIST = [ BOOTTAG, LDRTAG ]
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
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.config import recovery_config
7+
from snagrecover.protocols import dfu
8+
import sys
9+
import time
10+
11+
def main():
12+
usb_addr = recovery_config["usb_path"]
13+
dev = get_usb(usb_addr)
14+
15+
logger.debug(f"Rockchip usb dev {usb_addr}")
16+
17+
# Blob made with boot_merger
18+
if "xpl" in recovery_config["firmware"]:
19+
try:
20+
run_firmware(dev, "xpl")
21+
usb.util.dispose_resources(dev)
22+
except Exception as e:
23+
logger.error(f"Failed to run firmware: {e}")
24+
sys.exit(-1)
25+
# u-boot binaries.
26+
elif "code471" in recovery_config["firmware"] and "code472" in recovery_config["firmware"]:
27+
try:
28+
run_firmware(dev, "code471")
29+
usb.util.dispose_resources(dev)
30+
except Exception as e:
31+
logger.error(f"Failed to run code471 firmware: {e}")
32+
sys.exit(-1)
33+
if "delay" in recovery_config["firmware"]["code471"]:
34+
delay = recovery_config["firmware"]["code471"]["delay"]
35+
logger.info(f"Sleeping {delay}ms")
36+
time.sleep(delay / 1000)
37+
try:
38+
run_firmware(dev, "code472")
39+
usb.util.dispose_resources(dev)
40+
except Exception as e:
41+
logger.error(f"Failed to run code472 firmware: {e}")
42+
sys.exit(-1)
43+
if "delay" in recovery_config["firmware"]["code472"]:
44+
delay = recovery_config["firmware"]["code472"]["delay"]
45+
logger.info(f"Sleeping {delay}ms")
46+
time.sleep(delay / 1000)
47+
else:
48+
logger.error("Missing code471/code472 binary configuration")
49+
sys.exit(-1)
50+
51+
52+
if "u-boot-fit" in recovery_config["firmware"]:
53+
dev = get_usb(usb_addr)
54+
id = dfu.search_partid(dev, "u-boot.itb")
55+
if id is None:
56+
logger.error("Missing u-boot.itb DFU partition")
57+
dfu_cmd = dfu.DFU(dev, stm32=False)
58+
dfu_cmd.get_status()
59+
with open(recovery_config["firmware"]["u-boot-fit"]["path"], "rb") as fd:
60+
blob = fd.read()
61+
try:
62+
dfu_cmd.download_and_run(blob, id, 0, len(blob))
63+
dfu_cmd.get_status()
64+
dfu_cmd.detach(id)
65+
except Exception as e:
66+
logger.error(f"Failed to load u-boot.itb: {e}")
67+
sys.exit(-1)

src/snagrecover/supported_socs.yaml

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ tested:
5555
family: stm32mp
5656
zynqmp:
5757
family: zynqmp
58+
rk3399:
59+
family: rockchip
5860
untested:
5961
a10:
6062
family: sunxi
@@ -142,4 +144,19 @@ untested:
142144
family: sunxi
143145
v853:
144146
family: sunxi
145-
147+
rk3036:
148+
family: rockchip
149+
rk3128:
150+
family: rockchip
151+
rk3229:
152+
family: rockchip
153+
rk3288:
154+
family: rockchip
155+
rk3328:
156+
family: rockchip
157+
rk3368:
158+
family: rockchip
159+
rk3566:
160+
family: rockchip
161+
rk3588:
162+
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 in SPL DFU mode
3+
path: rk3399_uboot.bin
4+
u-boot-fit:
5+
# proper u-boot
6+
path: u-boot.itb
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Doesn't work on all rockchip SoCs
2+
code471:
3+
path: u-boot-tpl-dtb.bin
4+
delay: 1
5+
code472:
6+
path: u-boot-spl-dtb.bin
7+
delay: 1
8+
u-boot-fit:
9+
path: u-boot.itb

src/snagrecover/utils.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,9 @@ def get_recovery(soc_family: str):
186186
elif soc_family == "zynqmp":
187187
from snagrecover.recoveries.zynqmp import main as zynqmp_recovery
188188
return zynqmp_recovery
189+
elif soc_family == "rockchip":
190+
from snagrecover.recoveries.rockchip import main as rockchip_recovery
191+
return rockchip_recovery
189192
else:
190193
cli_error(f"unsupported board family {soc_family}")
191194

0 commit comments

Comments
 (0)