Skip to contentSkip to conversation

Implement grub-mkrescue for PowerMac and CHRP

PATCH In review Pavel Roskin 3 participants 8 messages Jan 26, 2008 – Jan 29, 2008

lore
Share & tools
lore
#0 lore raw

PATCH 1/3 Implement grub-mkrescue for PowerMac and CHRP

* DISTLIST: Add util/powerpc/ieee1275/grub-mkrescue.in.
* conf/powerpc-ieee1275.mk: Add grub-mkrescue support.
* conf/powerpc-ieee1275.mk: Regenerate.
* util/powerpc/ieee1275/grub-mkrescue.in: Implement grub-mkrescue for PowerMac and CHRP.
---

 DISTLIST                               |    1 
 conf/powerpc-ieee1275.mk               |   10 +++
 conf/powerpc-ieee1275.rmk              |    4 +
 util/powerpc/ieee1275/grub-mkrescue.in |  116 ++++++++++++++++++++++++++++++++
 4 files changed, 131 insertions(+), 0 deletions(-)
 create mode 100644 util/powerpc/ieee1275/grub-mkrescue.in
DISTLIST +1 -0
index 6388257..6b527c7 100644
@@ -330,6 +330,7 @@ util/i386/pc/misc.c
 util/i386/pc/grub-mkrescue.in
 util/ieee1275/get_disk_name.c
 util/powerpc/ieee1275/grub-install.in
+util/powerpc/ieee1275/grub-mkrescue.in
 util/powerpc/ieee1275/misc.c
 video/bitmap.c
 video/video.c
conf/powerpc-ieee1275.mk +10 -0
index 8869f5b..925027f 100644
@@ -686,6 +686,7 @@ kernel_elf_LDFLAGS = $(COMMON_LDFLAGS) -static-libgcc -lgcc \
 
 # Scripts.
 sbin_SCRIPTS = grub-install
+bin_SCRIPTS = grub-mkrescue
 
 # For grub-install.
 grub_install_SOURCES = util/powerpc/ieee1275/grub-install.in
@@ -696,6 +697,15 @@ grub-install: util/powerpc/ieee1275/grub-install.in config.status
 	chmod +x $@
 
 
+# For grub-mkrescue.
+grub_mkrescue_SOURCES = util/powerpc/ieee1275/grub-mkrescue.in
+CLEANFILES += grub-mkrescue
+
+grub-mkrescue: util/powerpc/ieee1275/grub-mkrescue.in config.status
+	./config.status --file=grub-mkrescue:util/powerpc/ieee1275/grub-mkrescue.in
+	chmod +x $@
+
+
 # Modules.
 pkglib_MODULES = halt.mod \
 	_linux.mod \
conf/powerpc-ieee1275.rmk +4 -0
index 5a43e9f..42af2c5 100644
@@ -104,10 +104,14 @@ kernel_elf_LDFLAGS = $(COMMON_LDFLAGS) -static-libgcc -lgcc \
 
 # Scripts.
 sbin_SCRIPTS = grub-install
+bin_SCRIPTS = grub-mkrescue
 
 # For grub-install.
 grub_install_SOURCES = util/powerpc/ieee1275/grub-install.in
 
+# For grub-mkrescue.
+grub_mkrescue_SOURCES = util/powerpc/ieee1275/grub-mkrescue.in
+
 # Modules.
 pkglib_MODULES = halt.mod \
 	_linux.mod \
util/powerpc/ieee1275/grub-mkrescue.in new file +116 -0

116 lines not on this page · raw message

#1 lore raw

PATCH 2/3 Provide fallback if /memory/available is missing

* kern/powerpc/ieee1275/openfw.c (grub_available_iterate):
Provide fallback if /memory/available is missing - try claiming memory between 3Mb and 4Mb. That's what yaboot does.
---

 kern/powerpc/ieee1275/openfw.c |    9 +++++++--
 1 files changed, 7 insertions(+), 2 deletions(-)
kern/powerpc/ieee1275/openfw.c +7 -2
index 26ff3d5..c8b30e5 100644
@@ -170,8 +170,13 @@ grub_err_t grub_available_iterate (int (*hook) (grub_uint64_t, grub_uint64_t))
 		       "Couldn't find /memory node");
   if (grub_ieee1275_get_integer_property (memory, "available", available,
 					  sizeof available, &available_size))
-    return grub_error (GRUB_ERR_UNKNOWN_DEVICE,
-		       "Couldn't examine /memory/available property");
+    {
+      /* Fallback for Open Hack'Ware - try claiming memory between 3Mb
+	 and 4Mb, just like yaboot would do.  */
+      hook (0x300000, 0x100000);
+      return grub_error (GRUB_ERR_UNKNOWN_DEVICE,
+			 "Couldn't examine /memory/available property");
+    }
 
   /* Decode each entry and call `hook'.  */
   i = 0;
#2 lore raw

PATCH 3/3 Work around "CLAIM failed" on PowerMac

In reply to Pavel Roskin

* include/grub/powerpc/ieee1275/kernel.h: Introduce GRUB_MOD_GAP to create a gap between _end and the modules added to the image with grub-mkrescue. That fixes "CLAIM failed" on PowerMAC.
* kern/powerpc/ieee1275/init.c: Use GRUB_MOD_GAP.
* util/elf/grub-mkimage.c (add_segments): Likewise.
---

 include/grub/powerpc/ieee1275/kernel.h |    5 +++++
 kern/powerpc/ieee1275/init.c           |    2 +-
 util/elf/grub-mkimage.c                |    2 +-
 3 files changed, 7 insertions(+), 2 deletions(-)
include/grub/powerpc/ieee1275/kernel.h +5 -0
index 107b928..129ee20 100644
@@ -23,6 +23,11 @@
 
 #define GRUB_MOD_ALIGN 0x1000
 
+/* Minimal gap between _end and the start of the modules.  It's a hack
+   for PowerMac to prevent "CLAIM failed" error.  The real fix is to
+   rewrite grub-mkimage to generate valid ELF files.  */
+#define GRUB_MOD_GAP 0x8000
+
 void EXPORT_FUNC (grub_reboot) (void);
 void EXPORT_FUNC (grub_halt) (void);
 
kern/powerpc/ieee1275/init.c +1 -1
index b38f017..6d08140 100644
@@ -242,5 +242,5 @@ grub_get_rtc (void)
 grub_addr_t
 grub_arch_modules_addr (void)
 {
-  return ALIGN_UP(_end, GRUB_MOD_ALIGN);
+  return ALIGN_UP(_end + GRUB_MOD_GAP, GRUB_MOD_ALIGN);
 }
util/elf/grub-mkimage.c +1 -1
index 9e44af1..316169f 100644
@@ -218,7 +218,7 @@ add_segments (char *dir, FILE *out, int chrp, char *mods[])
       grub_addr_t modbase;
 
       /* Place modules just after grub segment.  */
-      modbase = ALIGN_UP(grub_end, GRUB_MOD_ALIGN);
+      modbase = ALIGN_UP(grub_end + GRUB_MOD_GAP, GRUB_MOD_ALIGN);
 
       /* Construct new segment header for modules.  */
       phdr = phdrs + grub_target_to_host16 (ehdr.e_phnum);
#3 lore raw

Re: [PATCH 3/3] Work around "CLAIM failed" on PowerMac

kern/powerpc/ieee1275/init.c grub_get_rtc (void) · line 245

Quoted 2 lines · Pavel Roskin
kern/powerpc/ieee1275/init.c +1 -1
-  return ALIGN_UP(_end, GRUB_MOD_ALIGN);
+  return ALIGN_UP(_end + GRUB_MOD_GAP, GRUB_MOD_ALIGN);

Did you check if the requirement is just a bigger alignment rather than a gap?

Signature · 5 lines
Robert Millan

<GPLv2> I know my rights; I want my phone call!
<DRM> What use is a phone call… if you are unable to speak?
(as seen on /.)
#4 lore raw

Re: [PATCH 3/3] Work around "CLAIM failed" on PowerMac

Quoting Robert Millan <[email protected]>:

Quoted 6 lines · Pavel Roskin

kern/powerpc/ieee1275/init.c grub_get_rtc (void) · line 245

Quoted 2 lines
kern/powerpc/ieee1275/init.c +1 -1
-  return ALIGN_UP(_end, GRUB_MOD_ALIGN);
+  return ALIGN_UP(_end + GRUB_MOD_GAP, GRUB_MOD_ALIGN);

Did you check if the requirement is just a bigger alignment rather than a gap?

Yes, I checked that. I wish it would be bigger alignment, but it's not.

_end is 0x29NNN, so the module base 0x32000 is OK, but 0x31000 or 0x30000 is not OK. 0x30000 is better aligned than 0x32000.

I also tried adding more code to the core image, and the 0x8000 gap was still OK.

We could increase GRUB_MOD_ALIGN, say, to 0x40000 (256k), but we could eventually hit the limit for the code and have this problem again. I'll rather add a couple of lines and avoid a problem that could re-appear suddenly and for no obvious reason.

Of course, we would be very unlikely to hit a higher limit, like 0x100000 (1Mb). After all, 640k should be enough for everyone ;-)

It's your call.

Signature · 2 lines
Regards,
Pavel Roskin
#5 lore raw

Re: [PATCH 3/3] Work around "CLAIM failed" on PowerMac

Quoted 10 lines · Pavel Roskin

Quoting Robert Millan <[email protected]>:

Quoted 6 lines · Pavel Roskin

kern/powerpc/ieee1275/init.c grub_get_rtc (void) · line 245

Quoted 2 lines
kern/powerpc/ieee1275/init.c +1 -1
-  return ALIGN_UP(_end, GRUB_MOD_ALIGN);
+  return ALIGN_UP(_end + GRUB_MOD_GAP, GRUB_MOD_ALIGN);

Did you check if the requirement is just a bigger alignment rather than a gap?

Yes, I checked that. I wish it would be bigger alignment, but it's not.

Ah, ok.

Signature · 5 lines
Robert Millan

<GPLv2> I know my rights; I want my phone call!
<DRM> What use is a phone call… if you are unable to speak?
(as seen on /.)
author Applied
#6 lore raw

Re: [PATCH 3/3] Work around "CLAIM failed" on PowerMac

Quoted 7 lines · Robert Millan
Quoted 6 lines · Pavel Roskin

Quoting Robert Millan <[email protected]>:

Quoted 4 lines · Pavel Roskin
Quoted 2 lines
kern/powerpc/ieee1275/init.c +1 -1
-  return ALIGN_UP(_end, GRUB_MOD_ALIGN);
+  return ALIGN_UP(_end + GRUB_MOD_GAP, GRUB_MOD_ALIGN);
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines

Did you check if the requirement is just a bigger alignment rather than a gap?

Yes, I checked that. I wish it would be bigger alignment, but it's not.

Ah, ok.

Applied.

Signature · 2 lines
Regards,
Pavel Roskin
#7 lore raw
In reply to Pavel Roskin
Quoted 2 lines · Pavel Roskin

* DISTLIST: Add util/powerpc/ieee1275/grub-mkrescue.in.
* conf/powerpc-ieee1275.mk: Add grub-mkrescue support.

I guess you mean .rmk? Please mention the changes you made.

Quoted 1 line

* conf/powerpc-ieee1275.mk: Regenerate.

No need to mention regenerated files.

Quoted 2 lines

* util/powerpc/ieee1275/grub-mkrescue.in: Implement grub-mkrescue for PowerMac and CHRP.

This is a new file? In that case please say that.

Can you please include a proper changelog entry including its header and tabs? It's important that you describe what you change, not what it is supposed to do.

--
Marco