Skip to contentSkip to conversation

Preboot support

PATCH In review phcoder 3 participants 9 messages Apr 10, 2009 – Apr 27, 2009

lore
Share & tools
lore

phcoder

author
#0 lore raw

PATCH 1/1 Preboot support

Hello, here is the preboot hooks support. Apply on top of my bootmove patch. They are very useful for patches like sendkey (my old patch that I'll rediff), badram, acpi (2 patches in separate threads) or drivemap

Signature · 2 lines
Regards
Vladimir 'phcoder' Serbinenko
ChangeLog +13 -0
index a69e381..2b37e04 100644
@@ -1,3 +1,16 @@
+2009-04-06  Vladimir Serbinenko <[email protected]>
+
+	Preboot hooks support
+
+	* commands/boot.c (struct grub_preboot_t): new declaration
+	(preboots_head): new variable
+	(preboots_tail): likewise
+	(grub_loader_add_preboot): new function
+	(grub_loader_remove_preboot): likewise
+	(grub_loader_set): launch preboot hooks
+	* include/grub/loader.h (grub_loader_add_preboot): new declaration
+	(grub_loader_remove_preboot): likewise
+
 2009-03-22  Vladimir Serbinenko <[email protected]>
 
 	Move loader out of the kernel
commands/boot.c +96 -1

127 lines not on this page · raw message

include/grub/loader.h +8 -0
index 185d297..f701569 100644
@@ -41,4 +41,12 @@ void grub_loader_unset (void);
    depending on the setting by grub_loader_set.  */
 grub_err_t grub_loader_boot (void);
 
+/* Add a preboot function */
+void *grub_loader_add_preboot (grub_err_t (*preboot_func) (int noreturn),
+			       grub_err_t (*preboot_rest_func) (void),
+			       int prio);
+
+/* Remove given preboot function */
+void grub_loader_remove_preboot (void *hnd);
+
 #endif /* ! GRUB_LOADER_HEADER */
#1 lore raw
Quoted 3 lines · On Saturday 11 April 2009 08:48:07 phcoder wrote:

Hello, here is the preboot hooks support. Apply on top of my bootmove patch. They are very useful for patches like sendkey (my old patch that I'll rediff), badram, acpi (2 patches in separate threads) or drivemap

Some comments about the design.

- register/unregister is more appropriate than add/remove.

- preboot is ambigous. preboot_hook is better.

- Using an int value for the priority is quetionable. Very often, this style of priority system leads to chaos, because everyone picks up arbitrary numbers randomly. I prefer to define enums with a careful analysis.

Regards,
Okuji

author
#2 lore raw
Quoted 2 lines

- Using an int value for the priority is quetionable. Very often, this style
of priority system leads to chaos, because everyone picks up arbitrary numbers randomly. I prefer to define enums with a careful analysis.

I will think about it. But the analysis is difficult because we don't know in advance all the possible use cases of this feature

Quoted 9 lines

Regards,
Okuji

_______________________________________________
Grub-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-devel

Signature · 2 lines
Regards
Vladimir 'phcoder' Serbinenko
ChangeLog +13 -0
index 401a374..a6dd8f7 100644
@@ -1,3 +1,16 @@
+2009-04-06  Vladimir Serbinenko <[email protected]>
+
+	Preboot hooks support
+
+	* commands/boot.c (struct grub_preboot_t): new declaration
+	(preboots_head): new variable
+	(preboots_tail): likewise
+	(grub_loader_add_preboot): new function
+	(grub_loader_remove_preboot): likewise
+	(grub_loader_set): launch preboot hooks
+	* include/grub/loader.h (grub_loader_add_preboot): new declaration
+	(grub_loader_remove_preboot): likewise
+
 2009-03-22  Vladimir Serbinenko <[email protected]>
 
 	Move loader out of the kernel
commands/boot.c +94 -1

125 lines not on this page · raw message

include/grub/loader.h +8 -0
index 185d297..72d1894 100644
@@ -41,4 +41,12 @@ void grub_loader_unset (void);
    depending on the setting by grub_loader_set.  */
 grub_err_t grub_loader_boot (void);
 
+/* Register a preboot hook. */
+void *grub_loader_register_preboot_hook (grub_err_t (*preboot_func) (int noret),
+					 grub_err_t (*preboot_rest_func) (void),
+					 int prio);
+
+/* Unregister given preboot hook. */
+void grub_loader_unregister_preboot_hook (void *hnd);
+
 #endif /* ! GRUB_LOADER_HEADER */
author
#3 lore raw

What about this one?

Quoted 14 lines · phcoder
Quoted 2 lines

- Using an int value for the priority is quetionable. Very often, this
style of priority system leads to chaos, because everyone picks up arbitrary numbers randomly. I prefer to define enums with a careful analysis.

I will think about it. But the analysis is difficult because we don't know in advance all the possible use cases of this feature

Quoted 9 lines

Regards,
Okuji

_______________________________________________
Grub-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-devel

Signature · 2 lines
Regards
Vladimir 'phcoder' Serbinenko
ChangeLog +13 -0
index 401a374..a6dd8f7 100644
@@ -1,3 +1,16 @@
+2009-04-06  Vladimir Serbinenko <[email protected]>
+
+	Preboot hooks support
+
+	* commands/boot.c (struct grub_preboot_t): new declaration
+	(preboots_head): new variable
+	(preboots_tail): likewise
+	(grub_loader_add_preboot): new function
+	(grub_loader_remove_preboot): likewise
+	(grub_loader_set): launch preboot hooks
+	* include/grub/loader.h (grub_loader_add_preboot): new declaration
+	(grub_loader_remove_preboot): likewise
+
 2009-03-22  Vladimir Serbinenko <[email protected]>
 
 	Move loader out of the kernel
commands/boot.c +94 -1

125 lines not on this page · raw message

include/grub/loader.h +22 -0
index 185d297..319f3c5 100644
@@ -41,4 +41,26 @@ void grub_loader_unset (void);
    depending on the setting by grub_loader_set.  */
 grub_err_t grub_loader_boot (void);
 
+/* The space between numbers is intentional for the simplicity of adding new
+   values even if external modules use them. */
+typedef enum {
+  /* A preboot hook which can use everything and turns nothing off. */
+  GRUB_LOADER_PREBOOT_HOOK_PRIO_NORMAL = 400,
+  /* A preboot hook which can't use disks and may stop disks. */
+  GRUB_LOADER_PREBOOT_HOOK_PRIO_DISK = 300,
+  /* A preboot hook which can't use disks or console and may stop console. */
+  GRUB_LOADER_PREBOOT_HOOK_PRIO_CONSOLE = 200,
+  /* A preboot hook which can't use disks or console, can't modify memory map
+     and may stop memory services or finalize memory map. */
+  GRUB_LOADER_PREBOOT_HOOK_PRIO_MEMORY = 100,
+} grub_loader_preboot_hook_prio_t;
+
+/* Register a preboot hook. */
+void *grub_loader_register_preboot_hook (grub_err_t (*preboot_func) (int noret),
+					 grub_err_t (*preboot_rest_func) (void),
+					 grub_loader_preboot_hook_prio_t prio);
+
+/* Unregister given preboot hook. */
+void grub_loader_unregister_preboot_hook (void *hnd);
+
 #endif /* ! GRUB_LOADER_HEADER */
#4 lore raw
Quoted 1 line · On Monday 13 April 2009 02:19:07 phcoder wrote:

What about this one?

- ChangeLog, loader.h and loader.c are not consistent. For example, loader.h declares grub_loader_unregister_preboot_hook, but loader.c defines grub_loader_remove_preboot.

- I don't understand how preboot_func and preboot_rest_func are different. At least, not obvious. Can you elaborate on them?

- This part:

+
+ for (cur = preboots_head; cur; cur = cur->next)
+ if (err = cur->preboot_func (grub_loader_noreturn))
+ {
+ for (cur = cur->prev; cur; cur = cur->prev)
+ cur->preboot_rest_func ();
+ return err;
+ }

You should not set ERR inside the "if" clause. This is against the GNU Coding Standards. The main reason is that it is not friendly to debuggers (as you may not "step" between the assignment and the conditional jump).

Regards,
Okuji

author
#5 lore raw
Quoted 2 lines · Yoshinori K. Okuji

- I don't understand how preboot_func and preboot_rest_func are different. At least, not obvious. Can you elaborate on them?

preboot_rest_func is a function which should undo any action taken by preboot_func. It's used if either loader aborts due to an error or returns (which is possible on some platforms)

Quoted 5 lines

_______________________________________________
Grub-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-devel

Signature · 2 lines
Regards
Vladimir 'phcoder' Serbinenko
ChangeLog +14 -0
index dd28915..1b2bbda 100644
@@ -1,3 +1,17 @@
+2009-04-06  Vladimir Serbinenko <[email protected]>
+
+	Preboot hooks support
+
+	* commands/boot.c (struct grub_preboot_t): new declaration
+	(preboots_head): new variable
+	(preboots_tail): likewise
+	(grub_loader_register_preboot_hook): new function
+	(grub_loader_unregister_preboot_hook): likewise
+	(grub_loader_set): launch preboot hooks
+	* include/grub/loader.h (grub_loader_register_preboot_hook): 
+	new declaration
+	(grub_loader_unregister_preboot_hook): likewise
+
 2009-03-22  Vladimir Serbinenko <[email protected]>
 
 	Move loader out of the kernel
commands/boot.c +97 -2

128 lines not on this page · raw message

include/grub/loader.h +22 -0
index 185d297..319f3c5 100644
@@ -41,4 +41,26 @@ void grub_loader_unset (void);
    depending on the setting by grub_loader_set.  */
 grub_err_t grub_loader_boot (void);
 
+/* The space between numbers is intentional for the simplicity of adding new
+   values even if external modules use them. */
+typedef enum {
+  /* A preboot hook which can use everything and turns nothing off. */
+  GRUB_LOADER_PREBOOT_HOOK_PRIO_NORMAL = 400,
+  /* A preboot hook which can't use disks and may stop disks. */
+  GRUB_LOADER_PREBOOT_HOOK_PRIO_DISK = 300,
+  /* A preboot hook which can't use disks or console and may stop console. */
+  GRUB_LOADER_PREBOOT_HOOK_PRIO_CONSOLE = 200,
+  /* A preboot hook which can't use disks or console, can't modify memory map
+     and may stop memory services or finalize memory map. */
+  GRUB_LOADER_PREBOOT_HOOK_PRIO_MEMORY = 100,
+} grub_loader_preboot_hook_prio_t;
+
+/* Register a preboot hook. */
+void *grub_loader_register_preboot_hook (grub_err_t (*preboot_func) (int noret),
+					 grub_err_t (*preboot_rest_func) (void),
+					 grub_loader_preboot_hook_prio_t prio);
+
+/* Unregister given preboot hook. */
+void grub_loader_unregister_preboot_hook (void *hnd);
+
 #endif /* ! GRUB_LOADER_HEADER */
#6 lore raw

The way it looks to me is that preboot_func is the function to be executed a preboot time, whereas preboot_rest_func is a cleanup function to be called to "restore" things to the pre-preboot_func state. Something like this anyway.. its not yet real clear to me either.

Quoted 18 lines · phcoder
Quoted 2 lines · Yoshinori K. Okuji

- I don't understand how preboot_func and preboot_rest_func are different. At least, not obvious. Can you elaborate on them?

preboot_rest_func is a function which should undo any action taken by preboot_func. It's used if either loader aborts due to an error or returns (which is possible on some platforms)

Quoted 5 lines

_______________________________________________
Grub-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-devel

------------------------------------------------------------------------

_______________________________________________
Grub-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-devel

#7 lore raw

Warning fixed in the patch. If nobody objects I commit it tomorrow

Quoted 38 lines · John Stanley

The way it looks to me is that preboot_func is the function to be executed
a preboot time, whereas preboot_rest_func is a cleanup function to be
called to "restore" things to the pre-preboot_func state. Something like this anyway.. its not yet real clear to me either.

Quoted 17 lines · phcoder

Yoshinori K. Okuji wrote:

- I don't understand how preboot_func and preboot_rest_func are

Quoted 2 lines

different. At least, not obvious. Can you elaborate on them?

preboot_rest_func is a function which should undo any action taken by preboot_func. It's used if either loader aborts due to an error or returns (which is possible on some platforms)

Quoted 6 lines

_______________________________________________
Grub-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-devel

Quoted 7 lines

------------------------------------------------------------------------

_______________________________________________
Grub-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-devel

_______________________________________________
Grub-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-devel

Signature · 2 lines
Regards
Vladimir 'phcoder' Serbinenko
ChangeLog +14 -0
index e5b3086..2f2afc2 100644
@@ -1,3 +1,17 @@
+2009-04-26  Vladimir Serbinenko <[email protected]>
+
+	Preboot hooks support
+
+	* commands/boot.c (struct grub_preboot_t): new declaration
+	(preboots_head): new variable
+	(preboots_tail): likewise
+	(grub_loader_register_preboot_hook): new function
+	(grub_loader_unregister_preboot_hook): likewise
+	(grub_loader_set): launch preboot hooks
+	* include/grub/loader.h (grub_loader_register_preboot_hook): 
+	new declaration
+	(grub_loader_unregister_preboot_hook): likewise
+
 2009-04-26  David S. Miller  <[email protected]>
 
 	* util/grub-mkdevicemap.c (make_device_map): Add missing
commands/boot.c +97 -3

130 lines not on this page · raw message

include/grub/loader.h +22 -0
index 185d297..319f3c5 100644
@@ -41,4 +41,26 @@ void grub_loader_unset (void);
    depending on the setting by grub_loader_set.  */
 grub_err_t grub_loader_boot (void);
 
+/* The space between numbers is intentional for the simplicity of adding new
+   values even if external modules use them. */
+typedef enum {
+  /* A preboot hook which can use everything and turns nothing off. */
+  GRUB_LOADER_PREBOOT_HOOK_PRIO_NORMAL = 400,
+  /* A preboot hook which can't use disks and may stop disks. */
+  GRUB_LOADER_PREBOOT_HOOK_PRIO_DISK = 300,
+  /* A preboot hook which can't use disks or console and may stop console. */
+  GRUB_LOADER_PREBOOT_HOOK_PRIO_CONSOLE = 200,
+  /* A preboot hook which can't use disks or console, can't modify memory map
+     and may stop memory services or finalize memory map. */
+  GRUB_LOADER_PREBOOT_HOOK_PRIO_MEMORY = 100,
+} grub_loader_preboot_hook_prio_t;
+
+/* Register a preboot hook. */
+void *grub_loader_register_preboot_hook (grub_err_t (*preboot_func) (int noret),
+					 grub_err_t (*preboot_rest_func) (void),
+					 grub_loader_preboot_hook_prio_t prio);
+
+/* Unregister given preboot hook. */
+void grub_loader_unregister_preboot_hook (void *hnd);
+
 #endif /* ! GRUB_LOADER_HEADER */
#8 lore raw

Commited

Quoted 50 lines · Vladimir 'phcoder' Serbinenko

Warning fixed in the patch. If nobody objects I commit it tomorrow

Quoted 33 lines · John Stanley

The way it looks to me is that preboot_func is the function to be executed
a preboot time, whereas preboot_rest_func is a cleanup function to be
called to "restore" things to the pre-preboot_func state. Something like this anyway.. its not yet real clear to me either.

Quoted 17 lines · phcoder

Yoshinori K. Okuji wrote:

- I don't understand how preboot_func and preboot_rest_func are

Quoted 2 lines

different. At least, not obvious. Can you elaborate on them?

preboot_rest_func is a function which should undo any action taken by preboot_func. It's used if either loader aborts due to an error or returns (which is possible on some platforms)

Quoted 6 lines

_______________________________________________
Grub-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-devel

Quoted 7 lines

------------------------------------------------------------------------

_______________________________________________
Grub-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-devel

Quoted 5 lines

_______________________________________________
Grub-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-devel

--
Regards
Vladimir 'phcoder' Serbinenko

Signature · 2 lines
Regards
Vladimir 'phcoder' Serbinenko