[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Grub2-Extras Lua Library Load Failure (Silent) and Signature Mismatch is

From: Lucas Thalen
Subject: Grub2-Extras Lua Library Load Failure (Silent) and Signature Mismatch issues with Lua's C files and GRUB->file.h
Date: Wed, 2 Jun 2021 00:34:16 -0600

First time using one of these, hopefully this is in line with expectation
and etiquette.

Grub2 v2.04 (Pulled from GIT on 05/28/2021... I can't readily find a
specific version number, hopefully that's good enough)

Grub-Extras (latest, pulled 05/28/2021 it's been some time since an update,

Available as described here:
Targeting x86-64-efi, attempting to run on Android X86 (It boots, the menus
show, and I can at least load the lua interpreter)

Compiled on Ubuntu 21.04, installed with the following command line to
grub-install, everything said and done, to the bootloader partition on an
X86 (BlissOS) Android install.

*TLDR: *
I am trying to get LUA.mod working in GRUB2. I can get as far as the
interpreter, but most 'extra' functionality (ie, os.execute()) is not
available. I suspect this is related to some edits I had to make
in ignorance to get function signatures matching as the build was broken
from source. See below, unless there's something else obvious I'm just
doing wrong.

Lua's .c files do not have a signature matched to grub_file_open in
grub/file.h such that Lua's passes one parameter (fname) and grub_file_open
requires two, (fname and GRUB_FILE_TYPE enum).

*End goal: *Anyway, that's my end goal. Get LUA.mod working to its full
normal functionality in Grub2. Any guidance is heartily appreciated, I've
been at this for some 3 weeks now... the grub docs are just a little
opaque. I've gotten as far as loading the CLI, but it's defective for
anything but LUA's pure base.
*Full Summary*
Anyway, I've been trying to build grub-extras onto grub and then compile
it. I've *mostly* succeeded, but strangely, it seems the last major update
done to the lua portion of grub-extras was sort of half finished. There's a
bunch of function signature mismatches between the caller and the callee.

I did figure out how to 'patch' this, but the trouble is, the new
additional parameter required to get those working properly is an enum
value, and... try as I may, the comments in it don't do a great job of
clarifying what the different items mean.

If you attempt to build this, it will show with stacktraces to a few
*grub_file_open* function calls (exclusively present in lua's source .c/h
files) that have a mismatched signature, such as between lua.c (default: 1
parameter, filename) to grub_file (default: 2 parameters, filename and

One precise example is line 594 in lauxlib.c:
 >> lf.f = grub_file_open(filename);

However, if one traces back to grub_file_open in /grub/file.h, the
signature it has:
>> grub_file_t EXPORT_FUNC(grub_file_open) (const char *name, enum
grub_file_type type); [Line 209]

(All errors, as I fortunately took a screenshot. I don't have full code,
but I do have the numbered lines in the stack trace)
>> lua -> grub_lib.c [L: 331]
>> lua -> grub_lib.c [L: 468]

I managed to get it to compile, but it seems unable to do anything beyond
the purest basic functionality in lua (strings, tables, control flow).
Given that I have an old compiled example of lua.mod (incompatible with
current GRUB2, I did try overwriting it xD) included with YUMI that *does*
work, the failure to bring in these extra libraries like *os* is due to my
edit not having the correct flag and the mismatched source code. I'm not
sure which file was edited last, but whoever made the last commit there
didn't really check that.

My trouble comes in, that between the context I can derive from the limited
commenting on the offending functions, and from the enum comments itself...
I really don't have a clue *which* flag to actually use in that second
slot. I'd really, really rather not brute force it.

That's why I'm sending this, I'm hoping some kind soul with more context on
this bootloader stuff might assist me by clarifying what these flags mean.
I suspect I only need to load a 'generic file', but no clue which one I'd
put in for that.
Even if one could be so kind as to just confirm how to properly pass an
enum as a function parameter, so I can ensure I'm not messing that up, I'd
still be thankful.

There were 3 or 4 spots in the lua c files that needed this correction, by
adding GRUB_FILE_TYPE_NONE as the second parameter, it's enough to pass
compile time checks, but it seems there's some runtime issues evidencing.

*I would stress, don't defer to my judgement on that - i'm a relative
novice, especially with c - and i'm not *entirely* certain this is the root
of the library loading problem. But... It seems probable.*

Anyway, I understand there's probably a way these things are done, and I
sincerely apologize if I've contravened some rule in ignorance. If it's too
long, I'm just trying to be as thorough as possible so I hopefully don't
miss any key detail.

My sincere thanks to anyone who is kind enough to assist me in fixing this
up, it's occupied quite a bit of my time, and I can only promise I've made
every effort at researching this, but lua.mod and grub mentions are sparse.
I can guarantee I've spent at least 15 hours on it. Please afford me some
leniency... I'm a rather hobbyist coder at best, so it's not deep stuff
like this I tend to mess around in.

Thank you for your consideration, and please feel free to ask if there are
any useful further details I can oblige - I thank anyone reading this and
offer my gratitude to anyone who might also opt to assist me.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]