Skip to content

spacemit: add CPU scaling for OrangePi R2S - #3

Closed
21hertz wants to merge 9 commits into
dhewg:spacemitfrom
21hertz:r2s-cpu-scaling
Closed

spacemit: add CPU scaling for OrangePi R2S#3
21hertz wants to merge 9 commits into
dhewg:spacemitfrom
21hertz:r2s-cpu-scaling

Conversation

@21hertz

@21hertz 21hertz commented Jul 15, 2026

Copy link
Copy Markdown

Adds CPU frequency scaling for the OrangePi R2S, mirroring the existing RV2 support: includes k1-opp.dtsi and wires the eight CPU cores to the P1 PMIC's buck1 rail (buck1_0v9).
Tested on real R2S hardware — the OPP steps appear and frequencies scale under load:

# cat /sys/devices/system/cpu/cpufreq/policy0/scaling_available_frequencies
614400 819000 1000000 1228800 1600000

Note: Upstream carries the R2S board and its PMIC, but the shared k1-opp.dtsi / cpufreq enablement isn't in mainline yet.

dhewg and others added 9 commits July 2, 2026 09:11
This introduces the `-m name:dtb` switch, which adds the given $dtb and
creates an according config-$name with a compatible set to $name.

The switch can be used multiple times, which allows to create a single
image/kernel with more than one device tree.

Usage:
DEVICE_DTS_MULTI := model-a.dtb:vendor,model-a model-b.dtb:vendor,model-b

uboot can then either boot a specific configuration with e.g.:
`bootm ${loadaddr}#config-vendor,model-a`
or let it choose itself using CONFIG_FIT_BEST_MATCH.

Using -m sets no default configuration on purpose.

Signed-off-by: Andre Heider <a.heider@gmail.com>
The rootfs may be in another partition.

Signed-off-by: Andre Heider <a.heider@gmail.com>
Make it accessible for platform_check_image() so platforms can make
smarter decisions.

E.g.: it may be unable to save the partitons if the ones from the
sysupgrade image changed compared to the active ones.

Signed-off-by: Andre Heider <a.heider@gmail.com>
mkimage requires dtc if the uboot build itself uses FIT files.
Set the path for the external one if so configured.

Signed-off-by: Andre Heider <a.heider@gmail.com>
Prepare for SpacemiT.

Move from MAKE_VARS to MAKE_FLAGS in order to pass OPENSBI_VERSION_GIT.
While at it, set REPRODUCIBLE and respect OPENWRT_VERBOSE.

Signed-off-by: Andre Heider <a.heider@gmail.com>
This is required for the SpacemiT boot process.

Signed-off-by: Andre Heider <a.heider@gmail.com>
Mainline uboot isn't ready yet, so let's use the vendor fork for now.

The patches clean up the typically non-standard env of vendors and add
some fdt compatibles so we're able to use mainline OpenSBI, see [0].

Contrary to the vendor setup, OpenSBI will be part of the u-boot.itb and
not the 'opensbi' partition, as that one is too small to hold a
mainline OpenSBI build.

u-boot-spacemit_k1.tar.gz will be created in the bin/ folder, which includes
a script to easily bootstrap a board with just fastboot.

This is also a target installable package with /sbin/update-bootloader.sh to
install u-boot to NOR and/or the eMMC boot partition.

[0] https://blog.aurel32.net/upstream-opensbi-spacemit-k1.html

Signed-off-by: Andre Heider <a.heider@gmail.com>
SoC:
* RISC-V SpacemiT X60 Dual-Cluster Octa-core processors
* RISC-V 64GCVB architecture and RVA22 standard
* LPDDR4/LPDDR4x SDRAM (×2) for a total of up to 16GB of RAM
* USB (×3), USB 2.0 OTG, USB 2.0 Host, USB 3.0 (combo PCIE PortA)
* PCIE (×3), PCIE PortA Gen2x1, PCIE PortB Gen2x2, PCIE PortC Gen2x2
* GMAC (×2), 10/100/1000 Mbps, RGMII
* SDIO (×1 for WIFI)
* SD (×1 for TF card)
* eMMC (×1), compatible for 8bit eMMC5.1, up to HS400 (200MHz)

Supported Boards:
* Banana Pi BPI-F3
* Milk-V Jupiter
* SpacemiT MusePi Pro
* OrangePi R2S
* OrangePi RV2

The generated 'generic' images support all of the above mentioned boards using
a multi-dtb FIT file.

SD card installation
--------------------
* Simply write the built sdcard.img to an SD card and boot from it, the board
  will use the bootloader from that card:
  zcat openwrt-spacemit-k1-generic-erofs-sdcard.img.gz | dd of=/dev/<SD_DEVICE> conv=fsync

eMMC/NVMe/USB storage installation
----------------------------------
For this to work the bootloader stored in NOR and/or the eMMC boot0
partition need to be updated with the OpenWrt build. When using the SD
card installation described above you can simply run the included
update-bootloader.sh

Alternatively you can use a USB connection and fastboot:
* Power off the board
* Hold the board's FDL (Firmware Download) button
* Connect a USB cable (the board's port may be called "USB Device" or "OTG")
  to power it on
* You should see some debug messages over serial, release the FDL button
* Extract u-boot-spacemit_k1.tar.gz from the target's bin/ folder
* Pass the built initramfs.itb as argument to the included script:
  ./u-boot-spacemit_k1/bootstrap.sh openwrt-spacemit-k1-generic-initramfs.itb
* This will run the various boot loader stages and eventually give you a
  login shell
* Run the included update-bootloader.sh script
* Finally, setup network, scp the according image file over, and write it to
  eMMC (emmc.img) or NVMe/USB (other.img)

Signed-off-by: Andre Heider <a.heider@gmail.com>
Signed-off-by: jhl <jonatanh@hotmail.com>
@21hertz
21hertz marked this pull request as ready for review July 15, 2026 15:46
@21hertz

21hertz commented Jul 16, 2026

Copy link
Copy Markdown
Author

@dhewg : here's a patch for the R2S. It's my first pull request, let me know if I didn't follow guidelines or best practices correctly.

@dhewg

dhewg commented Jul 18, 2026 via email

Copy link
Copy Markdown
Owner

@21hertz

21hertz commented Jul 19, 2026

Copy link
Copy Markdown
Author

Nice! All those *.dts patches are rather trivial, writing them isn't the problem, maintaining them long term is. So this needs to go upstream, and then there's no issue with openwrt carrying the patch. So can you send this to the linux spacemit mailing list? Or do you want me to do that, as I need to send v2 of the same musepipro patch anyway? (to fix the include order, which I could fix for your patch too). But in that case I'll need to cc you and you may need to reply to r2s specific feedback

Ok, thanks! I still have a lot of catching up to do to get my head around everything and don't want to mess things up, so it's better if you can do it.

If there's anything else I can test or contribute with just let me know.

@dhewg
dhewg force-pushed the spacemit branch 2 times, most recently from 7cc8393 to a1b6efc Compare August 4, 2026 13:04
@dhewg

dhewg commented Aug 4, 2026

Copy link
Copy Markdown
Owner

@dhewg dhewg closed this Aug 4, 2026
dhewg pushed a commit that referenced this pull request Aug 13, 2026
f6c2fcfa539d client: cap cumulative header count and bytes per request
4f307a2156f3 client: verify chunk data is followed by CRLF before resyncing
628a073fef44 listen: set IP_FREEBIND so binding to a not-yet-present address works
0910904b75a3 client: reject empty chunk size lines in chunked transfer parsing
893fed8577d7 client: use strict chunk size parsing to fix issue #3
8867514f51fa client: fix parse_chunksize() return type and stale comment
daa5078b959b client: reject invalid header names to prevent request smuggling
69f9cabd0d7d http: use chartypes table consistently, drop ctype.h
003cd188b8f9 http: further consolidate character classification and header parsing
f682ccabee9e client: parse and discard chunked trailer sections, use enum chunked_state
e76736e5676f ubus: guard params type in uh_ubus_send_request()
42e30caa704e ubus: set d->free unconditionally to fix url_path leak
d6205aad6176 client: move unread-body guard into uh_request_done()
3c48b9e17d20 ubus: release client refcount on successful /ubus/subscribe
d0b89eb7c70b utils: strip trailing whitespace from header field-values
067466662368 file: dereference symlinks when looking up MIME type
c54ba119cf54 lua, ucode: use buffered stdio for script output
60f64bec40c8 tls: add SNI-based redirect support

This closes five published security advisories, three of them rated
high: an unauthenticated header-accumulation memory-exhaustion DoS,
an out-of-bounds write via ubus params type confusion, a url_path
leak, a CL.0 request smuggling desync and a leaked client refcount
that wedges the listener.

Fixes: openwrt/uhttpd#3
Fixes: openwrt/uhttpd#5
Fixes: openwrt/uhttpd#10
Fixes: openwrt/uhttpd#11
Fixes: openwrt/uhttpd#14
Fixes: openwrt/uhttpd#17
Closes: openwrt/uhttpd#19
Link: GHSA-vhx4-3p5q-m59q
Link: GHSA-2mpg-6wp5-435p
Link: GHSA-83vv-qrc6-h3hx
Link: GHSA-c2wg-hcff-hqrm
Link: GHSA-wvgh-cm54-q6f6
Link: openwrt#24680
Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants