Hi,
I've a question. I'm writing a software that installs a specific Linux distro on the target computer automatically. It also should flash coreboot as part of the install process, and that's where I'm stuck.
From what I've gathered, for that I would need a stripped down version of libflashrom that only has the internal SPI driver, nothing else (without laptop-checks, Paralell, LPC, NICs, external USB programmers etc.) What is the best way to achieve this?
I've already set up my test environment: I've configured and compiled qemu with "-enable-m25p80", which emulates lots of flash chips, among others the one that my target machine has. Then I can run qemu with "-device m25p80" and start a minimal Linux VM with the flashrom utility that I've compiled from source.
I've also cleaned up flashrom.c to only list the chips with the BUS_SPI interface (I need to support one specific chip only, but my understanding is, all of these use the same driver so it shouldn't be a problem having all these chips in this list). Now I need to remove files and functions that are not related to internal SPI, and I'm not sure how to proceed. Which would be the easiest and suggested way to have a stripped down libflashrom with just the internal SPI driver?
ps: unfortunately using flashrom as-is is out of question because it has way too many dependencies that the installer image simply does not have. For example, there's no libpci, libusb and no /dev/spidev device either, so I must restrict libflashrom to use its own driver, and also my installer can't call system(), so I must link it with libflashrom.
Can somebody help me with this?
On Sun, Feb 25, 2024, 01:06 bzt bztemail@gmail.com wrote:
Hi,
I've a question. I'm writing a software that installs a specific Linux distro on the target computer automatically. It also should flash coreboot as part of the install process, and that's where I'm stuck.
From what I've gathered, for that I would need a stripped down version of libflashrom that only has the internal SPI driver, nothing else (without laptop-checks, Paralell, LPC, NICs, external USB programmers etc.) What is the best way to achieve this?
I've already set up my test environment: I've configured and compiled qemu with "-enable-m25p80", which emulates lots of flash chips, among others the one that my target machine has. Then I can run qemu with "-device m25p80" and start a minimal Linux VM with the flashrom utility that I've compiled from source.
I've also cleaned up flashrom.c to only list the chips with the BUS_SPI interface (I need to support one specific chip only, but my understanding is, all of these use the same driver so it shouldn't be a problem having all these chips in this list). Now I need to remove files and functions that are not related to internal SPI, and I'm not sure how to proceed. Which would be the easiest and suggested way to have a stripped down libflashrom with just the internal SPI driver?
ps: unfortunately using flashrom as-is is out of question because it has way too many dependencies that the installer image simply does not have. For example, there's no libpci, libusb and no /dev/spidev device either, so I must restrict libflashrom to use its own driver, and also my installer can't call system(), so I must link it with libflashrom.
You did not mention the actual CPU architecture or mainboard you are running on, so I'd have to guess a bit here. But changes are that you will need at least libpci to configure the spi controller. You can configure a flashrom binary without USB support however.
You did not mention why system() is not an option. Maybe using execve(2) works for you?
Generally there is no difference in dependencies between libflashrom and flashrom. You can configure either without certain drivers to control dependencies. Check out Makefile or meson_options.txt
Stefan
Hello! You can select which programmer(s) to enable and disable, at build time. You can enable just one programmer that you need (internal is it?).
An example can be a test_build.sh which is in the root of the tree. This script is what Jenkins runs, and it builds lots of things. But specifically to the subject, script loops through all the options for programmers, enables one option and disables the rest, and tries to build with this. Seems similar to what you want to achieve.
On Mon, Feb 26, 2024 at 3:21 AM Stefan Reinauer stefan.k.reinauer@gmail.com wrote:
On Sun, Feb 25, 2024, 01:06 bzt bztemail@gmail.com wrote:
Hi,
I've a question. I'm writing a software that installs a specific Linux distro on the target computer automatically. It also should flash coreboot as part of the install process, and that's where I'm stuck.
From what I've gathered, for that I would need a stripped down version of libflashrom that only has the internal SPI driver, nothing else (without laptop-checks, Paralell, LPC, NICs, external USB programmers etc.) What is the best way to achieve this?
I've already set up my test environment: I've configured and compiled qemu with "-enable-m25p80", which emulates lots of flash chips, among others the one that my target machine has. Then I can run qemu with "-device m25p80" and start a minimal Linux VM with the flashrom utility that I've compiled from source.
I've also cleaned up flashrom.c to only list the chips with the BUS_SPI interface (I need to support one specific chip only, but my understanding is, all of these use the same driver so it shouldn't be a problem having all these chips in this list). Now I need to remove files and functions that are not related to internal SPI, and I'm not sure how to proceed. Which would be the easiest and suggested way to have a stripped down libflashrom with just the internal SPI driver?
ps: unfortunately using flashrom as-is is out of question because it has way too many dependencies that the installer image simply does not have. For example, there's no libpci, libusb and no /dev/spidev device either, so I must restrict libflashrom to use its own driver, and also my installer can't call system(), so I must link it with libflashrom.
You did not mention the actual CPU architecture or mainboard you are running on, so I'd have to guess a bit here. But changes are that you will need at least libpci to configure the spi controller. You can configure a flashrom binary without USB support however.
You did not mention why system() is not an option. Maybe using execve(2) works for you?
Generally there is no difference in dependencies between libflashrom and flashrom. You can configure either without certain drivers to control dependencies. Check out Makefile or meson_options.txt
Stefan
flashrom mailing list -- flashrom@flashrom.org To unsubscribe send an email to flashrom-leave@flashrom.org
Thank you for your answers!
But changes are that you will need at least libpci to configure the spi controller.
I don't think so, but I could replace libpci with a quick'n'dirty static direct-pci-access library if really that's the case. What I can replace is libusb, I certainly must omit that and all related code from libflashrom to make this work.
Maybe using execve(2) works for you?
No. The installer is an UEFI application, no libpci, no libusb, no system(), no execve() syscalls exists at all. The main issue here is, this environment isn't POSIX, much less Linux-compatible.
You can select which programmer(s) to enable and disable, at
build time. You can enable just one programmer that you need (internal is it?).
Yes, it's internal, an M25P80 compatible (at least, qemu's m25p80.c emulates the exact model I need to support, and flashrom.c also lists it with BUS_SPI). I need to flash coreboot into the motherboard's ROM as part of an automatic install process.
My problem is, I haven't seen anything like enabling/disabling drivers in the source (no "ifdef"s), which makes me wonder if disabling certain chips would actually strip their source code or not.
But specifically to the subject, script loops through all the options
for programmers, enables one option and disables the rest, and tries to build with this. Seems similar to what you want to achieve.
Thank you, I'll look into that!
So what I want to achieve here is: 1. create a stripped down libflashrom source code that contains only internal SPI programmer, nothing else 2. compile it under Linux with flashrom utility and test it in qemu 3. if works well, start porting that smaller source code base to UEFI 4. finally add the stripped down, ported libflashrom to the existing installer UEFI application
Thank you for your answers again, I'll look into that test_build.sh, hopefully I can use it to shrink the source.
Cheers, bzt
On 26/02/2024, Anastasia Klimchuk aklm@chromium.org wrote:
Hello! You can select which programmer(s) to enable and disable, at build time. You can enable just one programmer that you need (internal is it?).
An example can be a test_build.sh which is in the root of the tree. This script is what Jenkins runs, and it builds lots of things. But specifically to the subject, script loops through all the options for programmers, enables one option and disables the rest, and tries to build with this. Seems similar to what you want to achieve.
On Mon, Feb 26, 2024 at 3:21 AM Stefan Reinauer stefan.k.reinauer@gmail.com wrote:
On Sun, Feb 25, 2024, 01:06 bzt bztemail@gmail.com wrote:
Hi,
I've a question. I'm writing a software that installs a specific Linux distro on the target computer automatically. It also should flash coreboot as part of the install process, and that's where I'm stuck.
From what I've gathered, for that I would need a stripped down version of libflashrom that only has the internal SPI driver, nothing else (without laptop-checks, Paralell, LPC, NICs, external USB programmers etc.) What is the best way to achieve this?
I've already set up my test environment: I've configured and compiled qemu with "-enable-m25p80", which emulates lots of flash chips, among others the one that my target machine has. Then I can run qemu with "-device m25p80" and start a minimal Linux VM with the flashrom utility that I've compiled from source.
I've also cleaned up flashrom.c to only list the chips with the BUS_SPI interface (I need to support one specific chip only, but my understanding is, all of these use the same driver so it shouldn't be a problem having all these chips in this list). Now I need to remove files and functions that are not related to internal SPI, and I'm not sure how to proceed. Which would be the easiest and suggested way to have a stripped down libflashrom with just the internal SPI driver?
ps: unfortunately using flashrom as-is is out of question because it has way too many dependencies that the installer image simply does not have. For example, there's no libpci, libusb and no /dev/spidev device either, so I must restrict libflashrom to use its own driver, and also my installer can't call system(), so I must link it with libflashrom.
You did not mention the actual CPU architecture or mainboard you are running on, so I'd have to guess a bit here. But changes are that you will need at least libpci to configure the spi controller. You can configure a flashrom binary without USB support however.
You did not mention why system() is not an option. Maybe using execve(2) works for you?
Generally there is no difference in dependencies between libflashrom and flashrom. You can configure either without certain drivers to control dependencies. Check out Makefile or meson_options.txt
Stefan
flashrom mailing list -- flashrom@flashrom.org To unsubscribe send an email to flashrom-leave@flashrom.org
-- Anastasia.
Am 26.02.24 um 10:33 schrieb bzt:
Thank you for your answers!
But changes are that you will need at least libpci to configure the spi controller.
I don't think so, but I could replace libpci with a quick'n'dirty static direct-pci-access library if really that's the case. What I can replace is libusb, I certainly must omit that and all related code from libflashrom to make this work.
Maybe using execve(2) works for you?
No. The installer is an UEFI application, no libpci, no libusb, no system(), no execve() syscalls exists at all. The main issue here is, this environment isn't POSIX, much less Linux-compatible.
You can select which programmer(s) to enable and disable, at
build time. You can enable just one programmer that you need (internal is it?).
Yes, it's internal, an M25P80 compatible (at least, qemu's m25p80.c emulates the exact model I need to support, and flashrom.c also lists it with BUS_SPI). I need to flash coreboot into the motherboard's ROM as part of an automatic install process.
My problem is, I haven't seen anything like enabling/disabling drivers in the source (no "ifdef"s), which makes me wonder if disabling certain chips would actually strip their source code or not.
But specifically to the subject, script loops through all the options
for programmers, enables one option and disables the rest, and tries to build with this. Seems similar to what you want to achieve.
Thank you, I'll look into that!
So what I want to achieve here is:
- create a stripped down libflashrom source code that contains only
internal SPI programmer, nothing else 2. compile it under Linux with flashrom utility and test it in qemu 3. if works well, start porting that smaller source code base to UEFI 4. finally add the stripped down, ported libflashrom to the existing installer UEFI application
Thank you for your answers again, I'll look into that test_build.sh, hopefully I can use it to shrink the source.
There used to be (I haven't checked recently) an option to restrict building to a specific bus type only, i.e. only allow SPI flash. Combining this with building only for specific programmers would probably yield most of the result you want.
In the past, I have successfully built flashrom with only the internal driver to forward all hardware accesses to SerialICE (dependency on an external lib), so what you want should be possible also from a technical perspective.
Regards, Carl-Daniel