Writing GRUB Modules: Difference between revisions

From OSDev.wiki
Jump to navigation Jump to search
[unchecked revision][unchecked revision]
Content added Content deleted
m (→‎Loading: architectural correction)
(→‎Introduction: Informtion on building.)
Line 17: Line 17:
const struct grub_arg_option * parser); //Registers a command on the GRUB command line
const struct grub_arg_option * parser); //Registers a command on the GRUB command line
</source>
</source>

==== Building ====
GRUB2 modules are object files. You therefore need to use GCC (i686-elf recommended) to build your C files, then use LD's -r option to combine your object files (if neccessary). the final output needs to be named .mod.


==== Loading ====
==== Loading ====

Revision as of 16:17, 28 September 2014

Difficulty level

Master

Introduction

GRUB2 changed the whole architecture of GRUB. The big new feature is GRUB modules. This lead to the elimination of Stage 1.5. It also means it is easier for you to put a s--tload of cool functionality into your bootloader. You can now create your own executable format and get GRUB to load it. Of course, you wouldn't need to write a compiler or GCC modules for that. Or, perhaps more pertinantely, you can add in support for your OS's specific requirements, or your own filesystem.

Modules

GRUB modules are relocatable ELF32 binaries. They have the extension .mod.

Initialization

Each module has GRUB_MOD_INIT(modname) and GRUB_MOD_FINI(modname). Note that modname is not in quotes. You the need to edit /conf/common.mk. Copy one of the modules and edit it for your own needs. Note thateach module is longwinded.

Functions

int EXPORT_FUNC() grub_printf(const char* func, ...);  //Very similar to standard printf()
grub_extcmd_t grub_register_extcmd (const char * name, grub_extcmd_func_t func, 
    grub_command_flags_t flags, const char * summary, const char * description, 
    const struct grub_arg_option * parser);  //Registers a command on the GRUB command line

Building

GRUB2 modules are object files. You therefore need to use GCC (i686-elf recommended) to build your C files, then use LD's -r option to combine your object files (if neccessary). the final output needs to be named .mod.

Loading

GRUB2 modules can be loaded with the insmod command, from the GRUB configuration file. For filesystem modules, this allows your OS to be booted from your FS, but requires a recongized format for your module. To solve this, you will need to add your module to core.img using grub-mkimage, which can be installed using grub-setup, or possibly grub-install (which is a shell script wrapper to mkimage and setup).

This page is a stub.
You can help the wiki by accurately adding more contents to it.

External Links