Raspberry pi 4 - with custom GUI interface and fast boot speed

Viewed 9122

I'm trying to achieve this on a Raspberry Pi 4:

  • Less then 10 seconds boot time
  • Custom UI ( build with python/Gtk for example )

I already tried editing the /boot/config.txt with

# Disable the rainbow splash screen
disable_splash=1
# Disable bluetooth
dtoverlay=pi3-disable-bt
#Disable Wifi
dtoverlay=pi3-disable-wifi
dtoverlay=sdtweak,overclock_50=100
# Set the bootloader delay to 0 seconds. The default is 1s if not specified.
boot_delay=0
# Overclock the raspberry pi. This voids its warranty. Make sure you have a good power supply.
force_turbo=1

Also I have an A2 class 10 SdCard and I have disabled almost every service that I don't need.

My best results are 14 seconds boot time until my app started, but I need to make it faster....

I would like to achieve something like this in terms of speed, but using GTK, not QT: https://www.youtube.com/watch?v=TTcP3xeLrEY

3 Answers

I am also currently trying to reach fast boot time with my Raspberry Pi 4, but I cannot breach the wall of 10s without radical solutions such as buildroot or unikernel.

What do you need on your system ? On Raspbian you can use those two commands to verify what is slowing down the boot process :

systemd-analyze critical-chain

and

 systemd-analyze blame

Critical chain will show in red the services blocking the boot. On my setup I could desactivate all those services :

 hciuart #GPIOs
 nmbd    
 smbd
 wpa_supplicant
 systemd-timesyncd
 rpi-eeprom-update.service
 raspi-config.service
 networking

Just use sudo systemctl disable SERVICE , I guess there are others that are not critical for your application. Also, in the cmdline.txt file in /boot you can add quiet fastboot , it will decrease boot time further

GTK is a toolkit coded in C and callable from C code.

In practice, Python can be 10x slower than equivalent C code.

Did you consider starting Xorg with a minimal window manager and a single client coded in C? Without a single line of Python? Of course, read more about X windows systems protocols and architecture then about EWMH.

So, remove the Python interpreter on your RaspBerryPi (probably /usr/bin/python) and replace every old Python script by an equivalent ELF executable coded in C or in C++ and compiled with optimizations (so gcc -O3 with GCC). See also linuxfromscratch.org for inspiration and guidance.

I would like to achieve something like this in terms of speed, but using GTK

Of course, you want to use a GCC cross-compiler.

If that still does not work (after weeks of effort), replace your hardware by something more powerful.

It would be easier for you to install a Linux distribution such as Debian on your development laptop or desktop. Because most of what you would learn on your development computer (e.g. Advanced Linux Programming) can be applied to the RaspBerrry Pi. And cross-building on a Debian laptop for a Raspbian RaspBerryPi is really easy. Focus on learning low-level things starting from their C code. E.g. code your GUI directly with Xlib (no GTK, no Qt) in C. The same C code is very likely to be easily portable -if you write it carefully- from x86/Debian to your Raspberry Pi.

You could read the From powerup to to bash prompt howto; most of that document is relevant for a RaspBerryPi running RaspBian.

You could even avoid starting any Xorg or other display server (e.g. WayLand) on your RaspBerryPi. That certainly would make it boot faster.

You could replace your /sbin/init program by your own one coded in C entirely. That process starts within less than a second, and forks all other processes. Your custom GUI could be just Xorg with your single X11 client coded in C.

Observe that you could have the source code (millions of source lines) of all the code running on RaspBian. Then download it, study it, and optimize it. Of course this could take decades.

First, this is a poorly formed question. You've provided no details on what your boot process is or what OS/configuration you're running with for people to help.

Regardless, you appear primarily focused on a short boot time. So since your question is generic... here is a generic answer: there is nothing magical about the boot process. There is no config file with a fast_boot=1 option that gets you up in 0 seconds instead of 15. You want to boot faster? Do less.

  1. Throw out slow crap like Python
  2. Remove unnecessary application loading from your init system (sysvinit/systemd/whatever)
  3. Remove unnecessary driver loading from the kernel startup. Start by trimming down your device tree to only the hardware you really need to initialize.
  4. Optimize your bootloader (u-boot?) to only initialize the hardware you really need (obviously turn off any prompt and timer it may implement)

That's how you boot faster.

Related