2

One of the new features of Grub2 is scriptability. At my work we're using it to great affect. However, I recent stumbled on a terrible short coming. There isn't any string manipulation or arithmetic support.

My exact problem: I need to mess with a PCI device before booting. Between setpci and write_dword I can easily write the values I need to. I get the Base address register from setpci, and 0x18 to it, and write the desired value to that address.

I did the math in my head while experimenting, but now I can't figure out how to get Grub2 to do the same math at boot time.

To add insult to injury, the PCI address always end in 000. So in theory I could just replace the last two 0's with "18" and that would work as well. Once again Grub2 fails me, with no string manipulation support.

Is there a way to get a substring in Grub2 script?
Is there a way to perform arithmetic in Grub2 script?

2 Answers 2

2

If you want scriptability in Grub2, you need the lua support, which is not part of the released version. It's part of the grub-extras, and you can get the source from the bazaar repository. You'll need to rebuild Grub2 from source. I don't think there's any documentation apart from the source, though you can ask for help on the grub-devel mailing list. Good luck.

3

The regexp command can be used to do limited string manipulation.

https://www.gnu.org/software/grub/manual/grub/grub.html#regexp

untested example:

regexp --set base "(....)00" "$reg"
if [ "$base" != "" ]; then
    setpci "${base}18" ...
fi

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .