Quick boot on Raspberry for embedded application - Page 1
Forum section: electronics / general

author: luiHS
author_rank: Frequent Contributor
timestamp: May 23, 2021, 09:12:16 am
content: HiI need to noticeably reduce the boot time on a Raspberry for an embedded application.Everything I have found seems to require compiling scaled-down linux versions, buildroot, yocto, void linux, OpenWRT, Poky.Anyone with experience in the field?I just need Wifi and the UART. If there was an .img file to create the SD, all the better, because it is complex for me to have to compile and it can take hours before it does not work.

author: SiliconWizard
author_rank: Super Contributor
timestamp: May 23, 2021, 11:42:02 pm
content: Quote from: luiHS on May 23, 2021, 09:12:16 amWhat would be the maximum boot time allowed?

author: DiTBho
author_rank: Super Contributor
timestamp: May 24, 2021, 10:15:37 am
content: Quote from: luiHS on May 23, 2021, 09:12:16 amAll you need is to edit the file which describes the services to be launched.Less services, less time to boot. Easy job.Wifi requires more stuff than the simple Ethernet.

author: luiHS
author_rank: Frequent Contributor
timestamp: May 25, 2021, 10:01:13 am
content: Quote from: SiliconWizard on May 23, 2021, 11:42:02 pm10 seconds.

author: kripton2035
author_rank: Super Contributor
timestamp: May 25, 2021, 10:19:30 am
content: out of curiosity, what does the Pi exactly between wifi and uart ?

author: luiHS
author_rank: Frequent Contributor
timestamp: May 25, 2021, 11:49:09 am
content: Quote from: kripton2035 on May 25, 2021, 10:19:30 amWIFI, I use it to connect from PC with SmarTTY and WinSCP to configure and update files. I do not like to use wired Ethernet, I find it more comfortable to do it over WIFI. And in the future I also want to develop an Android App so that the user can configure the product and upload firmware updates from the mobile phone.UART, to communicate with an RT1064 microcontroller that sends commands to the Raspberry to play videos.

author: ralphrmartin
author_rank: Frequent Contributor
timestamp: May 25, 2021, 03:57:14 pm
content: Why not just boot directly from a USB 3 SSD? Wouldn't this be quick enough? It may not be the cheapest solution, but might be the easiest.As noted above, you could also turn off unwanted services for extra speed: e.g.systemctl disable bluetoothsystemctl stop bluetooth

author: DiTBho
author_rank: Super Contributor
timestamp: May 25, 2021, 04:21:49 pm
content: Even a USB-stick should be faster than an SD card.Except those gold-ones used for digital video recording.So-1- turn off unwanted services for extra speed-2- try USB-stick for other extra I/O speed

author: SiliconWizard
author_rank: Super Contributor
timestamp: May 25, 2021, 05:14:28 pm
content: Quote from: luiHS on May 25, 2021, 10:01:13 am10 seconds is definitely no problem.I managed about 5 seconds with a RPi3 (and 4). For that to happen, you need to install a very minimal Linux distro with no desktop environment and the minimum amount of services enabled. (Also of course, use a decent fast SD card.)I personally use ArchLinuxARM for this. The base install is pretty minimal and comes with no desktop env. After installing it, you can fine-tune by disabling services you don't need, but under 10s with the base install should be no problem already.RPi3:https://archlinuxarm.org/platforms/armv8/broadcom/raspberry-pi-3RPi4:https://archlinuxarm.org/platforms/armv8/broadcom/raspberry-pi-4Works a treat for me.

author: kripton2035
author_rank: Super Contributor
timestamp: May 25, 2021, 05:40:14 pm
content: not sure you can play videos on the Pi with this minimal linux distro ?

author: luiHS
author_rank: Frequent Contributor
timestamp: May 25, 2021, 06:50:04 pm
content: Quote from: SiliconWizard on May 25, 2021, 05:14:28 pmTo install ArchLinux it can only be done from a Linux computer, it cannot be done from Widows, there is no .img file already ready to create the SD ??.Where can I get information on how and what services can I disable?I only use WIFI and the UART. I already have Bluetooth disabled to be able to use the serial port. I could do without keyboard and mouse, although for the near future I will need USB for a data pendrive.

author: SiliconWizard
author_rank: Super Contributor
timestamp: May 25, 2021, 11:03:39 pm
content: Well you have a number of ways of doing that. A small virtual machine with Linux (you only need the command line), or just do it from a RPi with Raspbian or similar!That said, if you don't want to use ArchLinux ARM, you should be able to tailor Raspbian for the same thing. You just need to disable the desktop environment and a few services. I haven't tested, but a minimal Raspbian config should boot in only a couple seconds as well.

author: luiHS
author_rank: Frequent Contributor
timestamp: May 25, 2021, 11:38:57 pm
content: I have a CM4 with 8Gb flash, I will try to do it with it, although if I have to compile I suppose it will be very slow.I have already checked how to see running services withservice --status-alland how to disable them withsystemctl disable <service>. I don't know yet which services to disable, I have tried disablingavahi-daemonandtriggerhappy. I needsshto connect by WIFI, I do not know if need networkingI have also run thesystemd-analyze blameandsystemd-analyze critical-chaincommand, but RPY always responds with "Bootup not finished yet."

author: PlainName
author_rank: Super Contributor
timestamp: May 26, 2021, 12:01:40 am
content: QuoteIf you're building from sources you can compile and do whatever is needed on Windows. Takes a bit of effort to set up the cross-compiler and environment, but it's doable (and you'll end up knowing exactly how the thing gets built and from what).But if you just want to get going quickly, as SiliconWizard suggests: install Linux in a VM to do the biz. VirtualBox is free and easy to set up.

author: luiHS
author_rank: Frequent Contributor
timestamp: May 26, 2021, 05:19:18 am
content: I have already installed VirtualBox on my Windows computer.What is the best version of Linux to install and work with this issue in VirtualBox? I am going to create Buildroot for Raspberry 3 and 4.

author: luiHS
author_rank: Frequent Contributor
timestamp: May 26, 2021, 07:54:25 am
content: Thank you all for the information and advice.Finally I have decided to create a custom linux with buildroot, but I am doing it from a Raspberry pi 4 with a 64Gb SD card.I have followed the instructions that I found in this tutorial.https://ubanov.wordpress.com/2020/04/21/sistema-embebido-sobre-raspberry-pi-con-buildroot/If the system boots in less than 10 seconds for a Raspberry pi 1, as indicated in that tutorial, which will be even less for an RPY 3 or 4, and WIFI and UART work, I'm already happy.What I have seen is that there are a lot of parameters. Buildroot has some configurations ready for Raspberry pi 3 and 4, even so I have reviewed them all and I have remembered that wpa_supplicant may be necessary for the WIFI, the rest or they were already selected or indicated in that tutorial as open_ssh. I have also activated and configured the password for root.iptables I do not need it, I understand that it is a firewall and in my application it is not necessary.Now I have left it processing in my Raspberry pi4 with the make so that the .img file for the SD card is created. I suppose it will take a long time, and that if I had process it from Virtualbox on my PC, it would compile much faster, but there's no rush. If I see that it takes more than 5 hours, I will cancel it and do it on the PC.

author: luiHS
author_rank: Frequent Contributor
timestamp: May 26, 2021, 08:11:05 am
content: Compilation failed, and no idea why. Here it gives five ERROR messages,for the selected processor it does not support mls, r1, r2, r8, r11 in ARM mode. Luckily it failed soon and not after hours of compiling.

author: PlainName
author_rank: Super Contributor
timestamp: May 26, 2021, 11:51:47 am
content: QuoteSorry, I can't help with buildroot - when I did this I wrote a custom build script, partly because with the likes of buildroot (and, especially, crosstool) if you hit a strange problem it can often take more effort to sort it out than to have done your own from the start.Having said that, a quick google suggests that this page may be of use:https://jenda.hrach.eu/w/rpi-gcc

author: luiHS
author_rank: Frequent Contributor
timestamp: May 26, 2021, 04:41:46 pm
content: Quote from: dunkemhigh on May 26, 2021, 11:51:47 amI had already read about the compiler, an old version is kept in Raspbian for compatibility with Raspberry pi 1, but I was not convinced by the solution.So I tried again with VirtualBox, and again problems, it installed well, also without problems to configure everything, but when trying to Start it gave me an error, I tried to solve it, but it could not be. I already activated virtualization in the BIOS because before it did not allow me to install 64bit versions, only 32bit and with problems.So I looked for a Debian version for ARM, not Raspbian, there is a Debian ARM that does have the GCC compiler updated to the latest version. It has also been somewhat complicated because there are enough differences with Raspbian to configure the IP, SSH and WIFI, but finally I managed to start it, and again I started to compile buildroot in the Raspberry pi4.And there is now the Raspberry pi 4 with Debian compiling buildroot, to see if there is luck and it does not give errors.The truth is that it is a nightmare, I found three options, and two of them gave me an error, and the third was being very complicated:1.- PC with Virtualbox and Linux Debian2.- Raspberry pi 4 with Raspbian3.- Raspberry pi 4 with Debian 10.If all fail, then I will order a new SSD disk for my PC to install a Linux version.

author: SiliconWizard
author_rank: Super Contributor
timestamp: May 27, 2021, 12:01:09 am
content: Quote from: luiHS on May 25, 2021, 11:38:57 pmCompile what?

author: artag
author_rank: Super Contributor
timestamp: May 27, 2021, 01:09:25 am
content: There are a couple of Pi distributions intended specifically for a media player.Wouldn't they be a good starting point ?

author: luiHS
author_rank: Frequent Contributor
timestamp: May 27, 2021, 05:48:23 am
content: Three tries and I had to cancel it because it was stuck during the compilation process.Now I am following these instructions, they are similar but downloading the latest stable version of buildroot, and the compilation process is launched before configuring to add wifi, ssh and others.https://armphibian.wordpress.com/2019/10/01/how-to-build-raspberry-pi-zero-w-buildroot-image/If it fails me too, I'll buy an SSD for the PC, install Linux and do it again.

author: luiHS
author_rank: Frequent Contributor
timestamp: May 27, 2021, 05:49:17 am
content: Quote from: artag on May 27, 2021, 01:09:25 amProblem is only the boot time. I prefer build a custom version with only the essential for fast boot.

author: luiHS
author_rank: Frequent Contributor
timestamp: May 27, 2021, 05:50:24 am
content: Quote from: SiliconWizard on May 27, 2021, 12:01:09 ambuildroot

author: luiHS
author_rank: Frequent Contributor
timestamp: May 27, 2021, 06:57:13 am
content: Fourth and last attempt, and the same thing happens again, there comes a time that it becomes locked and no longer continues. In htop I see four compilation processes (I suppose) in state D. All this on a Raspberry pi4 with Debian 10 (not Raspbian).I have ordered an SSD to install a Linux on my PC and try again.

author: PlainName
author_rank: Super Contributor
timestamp: May 27, 2021, 08:28:41 am
content: QuoteI'm a bit confused with this - I thought you were building in a VM on a PC, but this suggests you're running it on an actual Pi?

author: paf
author_rank: Regular Contributor
timestamp: May 27, 2021, 11:06:09 am
content: A good light Linux distribution for Raspberry is Diet Pi:https://dietpi.comYou want fast boot times and WifI?Wifi takes some time to connect.

author: PlainName
author_rank: Super Contributor
timestamp: May 27, 2021, 11:35:36 am
content: QuoteBut booting doesn't have to wait for that to complete. Or even start.

author: paf
author_rank: Regular Contributor
timestamp: May 27, 2021, 03:00:32 pm
content: Quote from: dunkemhigh on May 27, 2021, 11:35:36 amYes, you are right. But he wants to use the system through the Wifi network, so while Wifi is connecting the system has already booted, but he cannot use it...

author: SiliconWizard
author_rank: Super Contributor
timestamp: May 27, 2021, 05:52:13 pm
content: As I've said and others have said, just use an existing, ready-to-use distro, and uninstall whatever you don't need. As I already said, the thing that will matter most is X and the desktop environment. By disabling both just to have a command line when it boots should get you boot times within a few seconds.I don't know exactly what you're going to do with this, but even if you need a GUI, you don't need a desktop environment. You may not even need X.You can take a look at this for instance:https://jmeosbn.github.io/blog/minimal-raspbian-pi/

author: luiHS
author_rank: Frequent Contributor
timestamp: May 28, 2021, 04:02:17 pm
content: Today I received the Samsung EVO 870 SSD hard disk that I ordered, and on Monday I will receive a Windows 10 that I ordered from the Microsoft Store.I will take the opportunity to change my current Windows 7, for a Windows 10, and install both Linux Ubuntu and Windows 10 on the same SSD. I don't have the Windows 10 yet, so I'll install Ubuntu now and rerun the whole buildroot compilation process for Raspberry pi3 and 4.All of the above (VirtualBox in W7 with Linux, buildroot compiled in Raspberry pi4) I already tried it and it did not work, also when I enabled virtualization in the BIOS to be able to create a 64bit Linux in VirtualBox it disabled the Windows7 license, and it did not work either VirtualBox, it gave me an error. I no longer waste time with those things, now I will work directly on Linux.I have insisted on working with buildroot, because I have read of people who have achieved versions that boots even in less than 2 seconds, perfect for embedded applications. And from what I was seeing in the buildroot configuration menu there are a lot of options that allow you to create a custom linux only with what you need for the Raspberry. There are preconfigured configuration files for Raspberry 3 and 4, 32 and 64 bit, pretty much the only thing I modified was to include ssh and wifi then run the compilation with make, very easy.

author: luiHS
author_rank: Frequent Contributor
timestamp: May 28, 2021, 06:51:36 pm
content: Withsystem-analyzeI have been looking at the time it takes to start each service, and I see thatdhcpcdtakes a long time in relation to the others, just over17 seconds.Does anyone know if I can remove that service or optimize it so it doesn't take that long?. I have a static IP configured in/etc/dhcpcd.confAnother thing I do not know is if my application does not start until all services have started. My application is for auto start in/etc/rc.localand does not need WIFI to work, I only put WIFI to access the system to upload files instead of doing it with an Ethernet cable.

author: SiliconWizard
author_rank: Super Contributor
timestamp: May 28, 2021, 09:38:54 pm
content: Quote from: luiHS on May 28, 2021, 04:02:17 pmI see, and I admit I don't know what buildroot does exactly on RPi's.On stock RPi's, the initial "boot" process is handled by the Video Core, and it is closed source. It does what is required to initialize the hardware, load a boot sequence from the SD card and hand it over to the main processor. That part itself takes about 2 seconds on average, even before any OS starts to boot. Does buildroot replace that? Is it even possible on RPi to replace the original bootloader executed on the Video Core?

author: luiHS
author_rank: Frequent Contributor
timestamp: May 29, 2021, 04:14:06 pm
content: Quote from: SiliconWizard on May 28, 2021, 09:38:54 pmI do not know it, my knowledge about Linux is quite scarce, a few commands from when I managed a dedicated server that I had years ago, and some basic things in Raspberry.I just googled the way to boot a Raspberry as fast as possible, and the buildroot seems to be the fastest of all.On the other hand, the configuration is simple and very complete, select one of the presets that are already defined (raspberrry, 3, 4, zero, 32 or 64 bit), run the menuconfig program, select what we want to add and compile with make, I just added ssh and wifi.

author: SiliconWizard
author_rank: Super Contributor
timestamp: May 29, 2021, 08:59:54 pm
content: OK, I think the bootloader on RPis can't be bypassed, and as I said, it lasts about 2 seconds from power on to the OS booting. You'll see that if a display is connected - it displays some kind of rainbow image, and the OS then starts to boot when the image disappears.So, the overall boot time (from power on) will always be over 2 seconds. In my experience 3 to 5 is achievable. Less than this, I don't think so. Just so you know what to expect.

author: eti
author_rank: Super Contributor
timestamp: June 03, 2021, 03:45:00 am
content: Quote from: ralphrmartin on May 25, 2021, 03:57:14 pmYep. I timed my Pi 400 booting from a "Leven" JS-600 SSD in a USB 3 caddy, to be around 15 seconds from cold.

author: eti
author_rank: Super Contributor
timestamp: June 03, 2021, 03:47:51 am
content: Quote from: kripton2035 on May 25, 2021, 05:40:14 pm"omxplayer" can play videos without a window a window manager, that's if you can stop it crashing.

author: Monkeh
author_rank: Super Contributor
timestamp: June 03, 2021, 03:56:00 am
content: Quote from: SiliconWizard on May 28, 2021, 09:38:54 pmThe same thing it does on everything else. It's a suite of tools for (cross)compiling a kernel and userspace for embedded applications. It has nothing to do with the bootloader or the hardware of a Pi.Quote from: luiHS on May 27, 2021, 06:57:13 amYou appear to have essentially deadlocked it by running catastrophically out of RAM.This is what happens when you try and use an embedded system as a workstation.

author: girishv
author_rank: Regular Contributor
timestamp: June 05, 2021, 06:44:43 am
content: Quote from: luiHS on May 23, 2021, 09:12:16 amThe OpenWRT build system is pretty straight forward. But, you need a working linux system with development libraries installed. As you pointed out it takes few hours to get the build system up and running.Send a personal message if you want an image.

author: DiTBho
author_rank: Super Contributor
timestamp: June 05, 2021, 09:31:38 am
content: Quote from: SiliconWizard on May 29, 2021, 08:59:54 pmThere are some experimental attempts. Guys trying to crack the binary code.It still doesn't work and I think it won't be added to any official repository for a long time.