Setting the clock to 1.2 GHz for Ubuntu 21.04

The processor clock can be increased to 1.2 GHz for Ubuntu 21.04 by building and flashing an updated U-Boot. The recipe was mostly taken from:

These commands are run on the Unmatched.

git clone https://github.com/sifive/meta-sifive.git

git clone https://github.com/riscv/opensbi.git
cd opensbi
git checkout v0.9 -b tmp
for f in ../meta-sifive/recipes-bsp/opensbi/files/*.patch; do echo $f;patch -p1 < $f;done
for f in ../meta-sifive/recipes-bsp/opensbi/files/unmatched/*.patch; do echo $f;patch -p1 < $f;done
make PLATFORM=generic
export OPENSBI=`realpath build/platform/generic/firmware/fw_dynamic.bin`
cd ..

git clone https://github.com/u-boot/u-boot.git
cd u-boot
git checkout v2021.01 -b tmp
for f in ../meta-sifive/recipes-bsp/u-boot/files/unmatched/*.patch; do echo $f;patch -p1 < $f;done
***********************************************************************
manually edit the file include/configs/sifive-hifive-unmatched-fu740.h
add the line:
"fdtfile=sifive/hifive-unmatched-a00.dtb\0" \
to the CONFIG_EXTRA_ENV_SETTINGS #define
***********************************************************************
make sifive_hifive_unmatched_fu740_defconfig
make -j4
sudo dd if=u-boot.itb of=/dev/mmcblk0p14 bs=4k oflag=direct
cd spl
sudo dd if=u-boot-spl.bin of=/dev/mmcblk0p13 bs=4k oflag=direct

reboot

The board will now be running at 1.2 GHz. As an added bonus, a bright blue LED is lit to help you find your way in the night.

7 Likes

For the adventurous, you can try other CPU clock rates by changing the line:

assigned-clock-rates = <1200000000>;

in the file u-boot/arch/riscv/dts/fu740-c000-u-boot.dtsi

1 Like

These instructions are immensely helpful — thanks!

Do the dd of= partitions remain the same if you are running from SSD? (because bootstrap is still from SD)

1 Like

Yes.

You can tone down the brightness of that blue LED by editing this line in u-boot/include/configs/sifive-hifive-unmatched-fu740.h

From:

	"setled_blue=mw.l 0x10020024 0x0000ffff; mw.l 0x10020028 0x0000ffff; mw.l 0x1002002c 0x0\0" \

to:

	"setled_blue=mw.l 0x10020024 0x0000ffff; mw.l 0x10020028 0x0000ffff; mw.l 0x1002002c 0xf000\0" \

For the artistic, you can create any color by adjusting the three values. The order is GRB. The values are 0x0 for full brightness to 0xffff for off. In the above example, setting the blue LED to 0xf000 would be about 1/16 brightness.

1 Like

I finally decided to take the plunge and follow this recipe.

Everything was golden until the last 2 makes. Following error messages I had to install bison and flex before the sifive hifive make would complete…no big deal.

The warning messages I received on the make -j4 are a little more concerning, and I’d appreciate if anyone can let me know if this spells trouble before I do the dds, or if others have ignored these too with no ill side effects :slight_smile:

  UPD     include/config/uboot.release
./"arch/riscv/lib/mkimage_fit_opensbi.sh" \
arch/riscv/dts/hifive-unmatched-a00.dtb > u-boot.its
===================== WARNING ======================
This board uses CONFIG_SPL_FIT_GENERATOR. Please migrate
to binman instead, to avoid the proliferation of 
arch-specific scripts with no tests.
====================================================

then a little later some warnings

tools/imx8image.c: In function ‘copy_file.constprop’:
tools/imx8image.c:414:7: warning: ‘write’ reading 5 bytes from a region of size 4 [-Wstringop-overflow=]
  414 |   if (write(ifd, (char *)&zero, 4 - tail) != 4 - tail) {
      |       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from ./tools/imagetool.h:21,
                 from include/imx8image.h:13,
                 from tools/imx8image.c:8:
/usr/include/unistd.h:367:16: note: in a call to function ‘write’ declared with attribute ‘read_only (2, 3)’
  367 | extern ssize_t write (int __fd, const void *__buf, size_t __n) __wur
      |                ^~~~~
tools/imx8mimage.c: In function ‘copy_file.constprop’:
tools/imx8mimage.c:291:7: warning: ‘write’ reading 5 bytes from a region of size 4 [-Wstringop-overflow=]
  291 |   if (write(ifd, (char *)&zero, 4 - tail) != 4 - tail) {
      |       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from tools/imagetool.h:21,
                 from tools/imx8mimage.c:9:
/usr/include/unistd.h:367:16: note: in a call to function ‘write’ declared with attribute ‘read_only (2, 3)’
  367 | extern ssize_t write (int __fd, const void *__buf, size_t __n) __wur
      |                ^~~~~

Although potential overflow above sounds a bit alarming, it’s these last 2 errors that really concern me

MKIMAGE u-boot-dtb.img
MKIMAGE u-boot.itb
sh: 1: dtc: not found
./tools/mkimage: Cant open u-boot.itb.tmp: No such file or directory
make: *** [Makefile:1453: u-boot.itb] Error 255
make: *** Waiting for unfinished jobs....
COPY    spl/u-boot-spl.dtb
CC      spl/common/spl/spl.o
board/sifive/hifive_unmatched_fu740/spl.c: In function ‘spl_board_init_f’:
board/sifive/hifive_unmatched_fu740/spl.c:116:2: warning: implicit declaration of function ‘pwm_device_init’ [-Wimplicit-function-declaration]
  116 |  pwm_device_init();
      |  ^~~~~~~~~~~~~~~

All those warnings are fine. Your problem is that you’re missing the device tree compiler, dtc. You can install that with:

sudo apt-get install device-tree-compiler

I’ve also posted pre-built binaries in another thread. See this post:

Thanks!

Since I was trying to do the make -j4 step when I hit a problem, do I need to go back and repeat any previous steps after I install dtc?

Or can I just install the dtc, then repeat the make -j4 ?

Yes, just repeat the make -j4.

1 Like

Thanks again, although now I am tempted to grab your 1.4GHz binary since people are saying that speed is rock solid :slight_smile:

I’ve been running the board at 1.5 GHz for weeks now, and it’s stable. You can adjust the clock rate by editing this line in u-boot/arch/riscv/dts/fu740-c000-u-boot.dtsi

from:

assigned-clock-rates = <1200000000>;

to:

assigned-clock-rates = <1500000000>;

Or 1400000000 if you prefer.

1 Like

i found a bug. i run: “sensors” again and again. computer went into crash.

Mine is rock solid at 1.5. Gets into an infinite error loop in early boot at 1.6.

Chips do vary. Some probably only work at 1.4, and some might work faster.

Is it dangerous to change CPU frequency? Can it permanently damage hardware?

It’s been a good evening at 1.4 so far. Between that and finally getting the graphics switched from radeon to amdgpu drivers, KDE seems a little peppier. Gnome web(epiphany) is slightly less intolerable. Kate editor is doing really well now, and that was what will make the most impact for me.

Quality of Life has improved more than I feared, but less than I hoped :stuck_out_tongue:

I think the only thing I recall having an anecdotal metric for is something I’m not really using. Before tonight…Spyder Python IDE took 53 seconds from click to being able to type in an open editor window. Tonight I opened it and clocked it at 39 seconds. Sadly, I still type incredibly faster than the editor displays the new characters in the window. I was hoping it had become usable, but not quite.

Only if the chip overheats. With the stock fan, it doesn’t even go above 50C here at 1.5 GHz and 27C ambient.

hello,
you did not specify the branch tag -or date- to use for checking out the meta-sifive git repo, and trying these steps only today leads me to patching errors at the uboot patching step for the …/meta-sifive/recipes-bsp/u-boot/files/0001-drivers-clk-sifive-fu740-prci-replace-pciaux-with-pc.patch (patch 1/13 in date of 28 June).

I’ll try to use the meta-sifive commit around that post date (8 June) and see if this works like this. Anyway, thanks for all these steps and procedure.

u-boot pacthing succeeding using 2021.05.00 tag of meta-sifive repo :wink:

The current default branch and tag of meta-sifive (2021.08.00) is targeted at u-boot v2021.07 tag.

Full instructions are here:

The uboot-patch-extraenv.diff is crucial. U-boot will fail without it.

1 Like