Executing program at the veeery begining

Post Reply
Sebas_Ledesma
Posts: 209
Joined: Thu Jun 08, 2017 2:49 am
languages_spoken: english
ODROIDs: C4, C2, C1+
Has thanked: 38 times
Been thanked: 16 times
Contact:

Executing program at the veeery begining

Post by Sebas_Ledesma »

Hi:

What is the suggested way to execute a 'console' program at the very-very beggining of the boot process?

I'm using ubuntu minimalist:
Linux Mx2200min 4.9.277-75 #1 SMP PREEMPT Sun Aug 8 23:26:32 UTC 2021 aarch64 aarch64 aarch64 GNU/Linux
and I want to show "booting" in a OLED display (I dont use monitor).

Currently my "boot time" it's around 15 seconds (ie, the first image that I shows in the OLED display appears around 15 seconds after powering up) and I'm executing my app from /etc/rc.local.

Thanks in advance,
Sebas

User avatar
rooted
Posts: 8852
Joined: Fri Dec 19, 2014 9:12 am
languages_spoken: english
Location: Gulf of Mexico, US
Has thanked: 743 times
Been thanked: 402 times
Contact:

Re: Executing program at the veeery begining

Post by rooted »

If the driver for the display is a module it can't display anything until this module is loaded, I would try compiling the kernel so the driver is built in.

Sebas_Ledesma
Posts: 209
Joined: Thu Jun 08, 2017 2:49 am
languages_spoken: english
ODROIDs: C4, C2, C1+
Has thanked: 38 times
Been thanked: 16 times
Contact:

Re: Executing program at the veeery begining

Post by Sebas_Ledesma »

I'm using a 256x64 pixels oled display (4 bpp) and I've made my own routines to draw into it (as the manufacturer provided a very spartan demo).

Image

So no driver needed, I only need SPI access and wiringPi to set the data/command pin.

User avatar
rooted
Posts: 8852
Joined: Fri Dec 19, 2014 9:12 am
languages_spoken: english
Location: Gulf of Mexico, US
Has thanked: 743 times
Been thanked: 402 times
Contact:

Re: Executing program at the veeery begining

Post by rooted »

SPI can still be a module, if you are using SPI dev it's most likely a module.

Code: Select all

zcat /proc/config.gz | grep CONFIG_SPI_SPIDEV
If it says "y" it's built in but if it says "m" it's a module.
These users thanked the author rooted for the post:
Sebas_Ledesma (Tue Oct 26, 2021 11:56 pm)

User avatar
odroid
Site Admin
Posts: 38309
Joined: Fri Feb 22, 2013 11:14 pm
languages_spoken: English, Korean
ODROIDs: ODROID
Has thanked: 2112 times
Been thanked: 1263 times
Contact:

Re: Executing program at the veeery begining

Post by odroid »

I think you need to analyze the time of whole booting procedures first.
If you have a USB-UART cable, try this command on your Linux PC and turn on your device.

Code: Select all

grabserial -v -d "/dev/ttyUSB0" -b 115200 -w 8 -p N -s 1 -e 30 -t -m "bl2_stage_init"
It will show you a list of time stamps from SoC boot ROM to rc.local executions.

I believe you can reduce a few seconds with some tweaks in u-boot and kernel configurations.
But a period of 10~12 seconds is still quite long for your equipment.
In that case, you might need to add/implement a SPI driver in u-boot to control the OLED device in very early stage. It will show a splash logo in 1~2 seconds surely.
I have no idea if there is any SPI things in the current u-boot or not though.
These users thanked the author odroid for the post:
Sebas_Ledesma (Wed Oct 27, 2021 4:01 am)

User avatar
tobetter
Posts: 8560
Joined: Mon Feb 25, 2013 10:55 am
languages_spoken: Korean, English
ODROIDs: Many
Location: Paju, South Korea
Has thanked: 498 times
Been thanked: 1368 times
Contact:

Re: Executing program at the veeery begining

Post by tobetter »

Sorry for joining this thread late, let me add my understanding.

1. The OLED module on HC4 does not use SPI bus, but use I2C.
2. Since it uses I2C, not necessary to use WiringPi if you know how to communicate a device through /dev/i2c-0.
3. If you application can run on a linux console, you will need to add it to initramfs to start the app, I've not tried this with HC4 OS image yet.
4. In case if you like to display anything on OLED on booting earlier than Linux kernel start, you need to change U-Boot.

FYI, https://wiki.odroid.com/odroid-hc4/appl ... d?s[]=oled
These users thanked the author tobetter for the post:
Sebas_Ledesma (Wed Oct 27, 2021 4:01 am)

User avatar
mctom
Posts: 736
Joined: Wed Nov 11, 2020 4:44 am
languages_spoken: english, polish
ODROIDs: N2+, Game Advance, a few XU4
Location: Gdansk, Poland
Has thanked: 74 times
Been thanked: 93 times
Contact:

Re: Executing program at the veeery begining

Post by mctom »

From HW perspective, if this is I2C indeed, one really simple and solid way would be to connect a tiny micro controller in parallel to I2C and power lines of the display. The micro controller would send the splash logo right after its own power-on, and then sleep forever.

This will work even before Linux boots and is still possible to do despite The Shortage. ;)
Punk ain't no religious cult, punk means thinking for yourself!

Maintainer of PiStackMon

User avatar
tobetter
Posts: 8560
Joined: Mon Feb 25, 2013 10:55 am
languages_spoken: Korean, English
ODROIDs: Many
Location: Paju, South Korea
Has thanked: 498 times
Been thanked: 1368 times
Contact:

Re: Executing program at the veeery begining

Post by tobetter »

mctom wrote:
Tue Oct 26, 2021 4:17 pm
From HW perspective, if this is I2C indeed, one really simple and solid way would be to connect a tiny micro controller in parallel to I2C and power lines of the display. The micro controller would send the splash logo right after its own power-on, and then sleep forever.

This will work even before Linux boots and is still possible to do despite The Shortage. ;)
True, if one is not hesitate to add a tiny extra board and can manage small firmware to handle OLED and RTC for sure. :)

User avatar
odroid
Site Admin
Posts: 38309
Joined: Fri Feb 22, 2013 11:14 pm
languages_spoken: English, Korean
ODROIDs: ODROID
Has thanked: 2112 times
Been thanked: 1263 times
Contact:

Re: Executing program at the veeery begining

Post by odroid »

Relatively higher resolution OLED 256x64 dots with 4bit per pixel (16 grey level?) seems to have an SPI interface instead of I2C.

User avatar
mctom
Posts: 736
Joined: Wed Nov 11, 2020 4:44 am
languages_spoken: english, polish
ODROIDs: N2+, Game Advance, a few XU4
Location: Gdansk, Poland
Has thanked: 74 times
Been thanked: 93 times
Contact:

Re: Executing program at the veeery begining

Post by mctom »

Should be possible with SPI as well, especially if Odroid board stays in Hi-Z state before boot (which I expect to be the case).
No need to prepare sophisticated firmware, just dump data to SPI and go to sleep.

I know this is not what OP is asking for, but perhaps an alternative solution will spark some other idea to walk around the problem.
Punk ain't no religious cult, punk means thinking for yourself!

Maintainer of PiStackMon

Sebas_Ledesma
Posts: 209
Joined: Thu Jun 08, 2017 2:49 am
languages_spoken: english
ODROIDs: C4, C2, C1+
Has thanked: 38 times
Been thanked: 16 times
Contact:

Re: Executing program at the veeery begining

Post by Sebas_Ledesma »

odroid wrote:
Tue Oct 26, 2021 4:34 pm
Relatively higher resolution OLED 256x64 dots with 4bit per pixel (16 grey level?) seems to have an SPI interface instead of I2C.
Yes, this oled has a parallel interface (that I'm not using), and SPI inteface.
I'm opening "/dev/spidev0.0"

Code: Select all

void spi_WriteCmd(int fd, unsigned char cmd) {
	if (fd==-1) {
		return;
	}
	digitalWrite(MY_SPI_DC, 0); // Poner PIN data/cmd en 0

	int ret;
	uint8_t tx[] = {cmd};
	struct spi_ioc_transfer tr;

	memset(&tr, 0, sizeof(tr));
	tr.tx_buf = (unsigned long)tx;
	tr.rx_buf = (unsigned long)0;
	tr.len = ARRAY_SIZE(tx);
	tr.speed_hz = spiSpeed;
	tr.bits_per_word = bits;
	tr.delay_usecs = 0;
	tr.cs_change = 0;

	ret = ioctl(fd, SPI_IOC_MESSAGE(1), &tr);
	if (ret < 0)
		fprintf(stderr, "%s: can't send SPI message\n", __func__);

	digitalWrite(MY_SPI_DC, 1); /* */

}

void spi_WriteData(int fd, unsigned char data) {
	if (fd==-1) {
		return;
	}

	digitalWrite(MY_SPI_DC, 1); // Poner PIN data/cmd en 1
	int ret;
	uint8_t tx[] = {data};
	struct spi_ioc_transfer tr;

	memset(&tr, 0, sizeof(tr));
	tr.tx_buf = (unsigned long)tx;
	tr.rx_buf = (unsigned long)0;
	tr.len = ARRAY_SIZE(tx);
	tr.speed_hz = spiSpeed;
	tr.bits_per_word = bits;
	tr.delay_usecs = 0;
	tr.cs_change = 0;

	ret = ioctl(fd, SPI_IOC_MESSAGE(1), &tr);
	if (ret < 0)
		fprintf(stderr, "%s: can't send SPI message\n", __func__);
}
Perhaps I can avoid the wiringPi to set data/command line and use an ioctl command.

Sebas_Ledesma
Posts: 209
Joined: Thu Jun 08, 2017 2:49 am
languages_spoken: english
ODROIDs: C4, C2, C1+
Has thanked: 38 times
Been thanked: 16 times
Contact:

Re: Executing program at the veeery begining

Post by Sebas_Ledesma »

rooted wrote:
Tue Oct 26, 2021 1:36 pm
SPI can still be a module, if you are using SPI dev it's most likely a module.

Code: Select all

zcat /proc/config.gz | grep CONFIG_SPI_SPIDEV
If it says "y" it's built in but if it says "m" it's a module.
I can confirm that spi driver it's a module (using Ubuntu 20.04, with kernel 4.9.277-75)

Code: Select all

CONFIG_SPI_SPIDEV=m

User avatar
rooted
Posts: 8852
Joined: Fri Dec 19, 2014 9:12 am
languages_spoken: english
Location: Gulf of Mexico, US
Has thanked: 743 times
Been thanked: 402 times
Contact:

Re: Executing program at the veeery begining

Post by rooted »

If you include the module in initrd it will get loaded earlier and the screen should activate sooner.
These users thanked the author rooted for the post:
Sebas_Ledesma (Thu Oct 28, 2021 12:09 am)

Post Reply

Return to “Ubuntu”

Who is online

Users browsing this forum: No registered users and 0 guests