Grub2 on Mac OS X
Selon "Yoshinori K. Okuji" <[email protected]>:
Quoted 11 lines · Antoine Terrienne
Quoted 2 lines
Here is a patch with the modifications I made. Please tell me if some of them are wrong. I hope I would help.
Could you make a patch with -u? The standard diff format is too difficult for me.
I describe what I think are not appropriate in your patch:
- memalign should not be just a macro. memalign is not the same as malloc.
memalign doesn't exist on Mac OS. malloc always returns 16 bytes aligned memory. This macro is only defined if there is no HAVE_MEMALIGN defined by the configure script. If 16 bytes alignment not enouth there is valloc that allocates on a page bondary but there is no such function as memalign.
Quoted 8 lines
- The macro _MACOSX_ should not be defined. OS-specific code should be enabled
in a more generic way. Take a look at the autoconf manual and the autobook
<http://sources.redhat.com/autobook/>.- Rather than replacing argp with getopt, please include the standalone version of argp <http://gd.tuwien.ac.at/utils/shells/lsh/>.
You mean include it in Grub ?
Where such code should be placed in the source three ? normal/ util/ ... ?
getopt is already used by grub-mkimage and available everywere so why not just using it with grub-emu ? Are there somme specific reasons ?
Quoted 4 lines
- ChangeLog, please.
Okuji
Ok I'll do that and send you a new patch with -u
Thank you for the comments
I have some others questions about the powerpc part of Grub2. It seems that many parts are just a copy of the i386. For exemple in the conf/powerpc-ieee1275.rmk. grub_emu_sources refer to commands/i386/pc/{reboot.c,halt.c,suspend.c} but there exist somme commands/ieee1275/{reboot.c,halt.c,suspend.c}. Is this normal ?
thank you for the answers
Quoted 5 lines · antoine terrienne
memalign doesn't exist on Mac OS. malloc always returns 16 bytes aligned memory. This macro is only defined if there is no
HAVE_MEMALIGNdefined by the configure script. If 16 bytes alignment not enouth there is valloc that allocates on a page bondary but there is no such function as memalign.
Is it hard to implement memalign using valloc? I don't know how it works on MacOSX.
Quoted 1 line
You mean include it in Grub ?
Sure.
Quoted 2 lines
Where such code should be placed in the source three ? normal/ util/ ... ?
Create a directory "lib" at the top source directory and link it if your system library does not have it.
Quoted 2 lines
getopt is already used by grub-mkimage and available everywere so why not just using it with grub-emu ? Are there somme specific reasons ?
Technically speaking, argp is superior. So, I prefer keeping it to throwing it away.
Quoted 5 lines
I have some others questions about the powerpc part of Grub2. It seems that many parts are just a copy of the i386. For exemple in the conf/powerpc-ieee1275.rmk.
grub_emu_sourcesrefer to commands/i386/pc/{reboot.c,halt.c,suspend.c} but there exist somme commands/ieee1275/{reboot.c,halt.c,suspend.c}. Is this normal ?
Yes. There are good reasons. Take a look at the archive of this list.
Okuji
Selon "Yoshinori K. Okuji" <[email protected]>:
Quoted 4 lines
Is it hard to implement memalign using valloc? I don't know how it works on MacOSX.
Should be possible I'll take a look. But in most cases i found on the web malloc is a good subtitute to memalign.
Quoted 4 lines
Technically speaking, argp is superior. So, I prefer keeping it to throwing it
away.
I agree argp is techically superior but adding a library in Grub2 mean keeping it up-to-date with the mainstream distribution. This add a little anoyng work just to add some functionalities that aren't used. If you really want to add it I can do it but I'm not sure it is necessary.
Quoted 8 lines
Quoted 5 lines
I have some others questions about the powerpc part of Grub2. It seems that many parts are just a copy of the i386. For exemple in the conf/powerpc-ieee1275.rmk.
grub_emu_sourcesrefer to commands/i386/pc/{reboot.c,halt.c,suspend.c} but there exist somme commands/ieee1275/{reboot.c,halt.c,suspend.c}. Is this normal ?Yes. There are good reasons. Take a look at the archive of this list.
Ok promise next time I will look before asking stupid question ;)
Quoted 3 lines
Okuji
I found another glibc specific function : alloca. Used in cmain in boot/powerpc/ieee1275/cmain.c. I repace it by declaring argv as an array of 64 elements : char *arg[64] (should be enouth ?). As the variables are allocated in the stack just like alloca do it should work just the same.
I have another question about -DGRUB_UTIL. Can it be used to distinguish the host compiled part and the build compiled part of grub ?
I have to handle types differenty in host and build as the build part doesn't have stdlib.h. But this method fails on boot/powerpc/ieee1275/cmain.c that is compiled with powerpc-elf-gcc (build) and the -DGRUB_UTIL flag.
Thanks for your answers
--
--
____
/ \ / [email protected]
| o o | - http://antoine.terrienne.free.fr | o | \ #153026466 \ V V /
\_/\_/
Quoted 2 lines · Antoine Terrienne
Should be possible I'll take a look. But in most cases i found on the web malloc is a good subtitute to memalign.
But you must still check if a pointer returned by malloc is aligned correctly.
Quoted 4 lines
I agree argp is techically superior but adding a library in Grub2 mean keeping it up-to-date with the mainstream distribution. This add a little anoyng work just to add some functionalities that aren't used. If you really want to add it I can do it but I'm not sure it is necessary.
Necessary. It is not a big burden anyway.
Quoted 4 lines
I found another glibc specific function : alloca. Used in cmain in
boot/powerpc/ieee1275/cmain.c. I repace it by declaring argv as an array of 64 elements : char *arg[64] (should be enouth ?). As the variables are allocated in the stack just like alloca do it should work just the same.
This kind of functions should be complemented by a library. Look at Gnulib:
http://www.gnu.org/software/gnulib/
I think Gnulib contains argp as well.
Quoted 6 lines
I have another question about -DGRUB_UTIL. Can it be used to distinguish the host compiled part and the build compiled part of grub ?
I have to handle types differenty in host and build as the build part doesn't havestdlib.h. But this method fails onboot/powerpc/ieee1275/cmain.cthat is compiled with powerpc-elf-gcc (build) and the -DGRUB_UTIL flag.
I don't understand. Why is stdlib.h related to types?
Okuji
Selon "Yoshinori K. Okuji" <[email protected]>:
Quoted 3 lines
But you must still check if a pointer returned by malloc is aligned correctly.
Ok i'll make some checks to make it cleaner
Quoted 3 lines
Necessary. It is not a big burden anyway.
Ok so I guess we should change the getopt method used by grub-mkimage to argp too.
Quoted 11 lines
Quoted 4 lines
I found another glibc specific function : alloca. Used in cmain in
boot/powerpc/ieee1275/cmain.c. I repace it by declaring argv as an array of 64 elements : char *arg[64] (should be enouth ?). As the variables are allocated in the stack just like alloca do it should work just the same.This kind of functions should be complemented by a library. Look at Gnulib:
http://www.gnu.org/software/gnulib/
I think Gnulib contains argp as well.
Ok I'll look at this too
Quoted 3 lines
I don't understand. Why is
stdlib.hrelated to types?
Oop sory I mean stdint.h
Types like int32_t, uint32_t and intprt_t are defined from stdint.h
I try to send a new patch several times but it is too big for the mailing list size limit (100Kb) so I put it here :
http://antoine.terrienne.free.fr/grub2/grub2_on_macosx_20050326.patch
And the mail I sent with it :
Here is a new patch much cleaner (with -u).
Everything compiles now but I didn't test It yet. In fact I don't know how to use and install grub2 on a drive. If you have and docs or info about installing a binary to be open firmware bootable that could help me, thanks ;-)
The compilation is OK but this patch is still ugly : I left the getopt. I add a flag -DGRUB_HOST to make a distinction between the host and build parts. The GRUB_HOST flag is only used in some specific powerpc include directories so it shouldn't affect the i386 part. I also add a grub_machine_fini in kern/powerpc/ieee1275/init.c needed by kern/loader.c. Right now grub_machine_fini is empty but it should call for someting like grub_console_fini (not present in powerpc part) and grub_ofdisk_fini (not implemented). I left malloc as an alternative to memalign. As far as I look in the code memalign is used to align memory segment from elf files and every usual cases in elf segments fits in the 16 byte alignment. So it should work well for now waiting for a better implementation to support exotic segment alignments.
Compilation and installation are OK. I get grub-emu grub-mkimage and every modules in the share/grub/ directory and grub-mkimage can produce images. Still need test and improvements but it seems to work.
--
--
____
/ \ / [email protected]
| o o | - http://antoine.terrienne.free.fr | o | \ #153026466 \ V V /
\_/\_/
Quoted 2 lines · Antoine Terrienne
Ok so I guess we should change the getopt method used by grub-mkimage to argp too.
IMHO it should be changed for every utility in that case. If no one knows argp, I could do that when I have some time and some other issues are solved. That would be in some months, but it will be done.
Quoted 2 lines
Oop sory I mean
stdint.h
Types likeint32_t,uint32_tandintprt_tare defined fromstdint.h
If that is used, you could replace int32_t by grub_uint32_t, etc.
Quoted 3 lines
I try to send a new patch several times but it is too big for the mailing list size limit (100Kb) so I put it here :
http://antoine.terrienne.free.fr/grub2/grub2_on_macosx_20050326.patch
Not including generated files will make the patch a lot smaller. I personally don't have problems with big patches on the mailinglist. Having the patch in the email will make it a lot easier for me to review the patch.
Quoted 3 lines
And the mail I sent with it :
Here is a new patch much cleaner (with -u).
Please use -p as well. It will make reviewing the patch a *LOT* easier.
Quoted 3 lines
Everything compiles now but I didn't test It yet. In fact I don't know how to use and install grub2 on a drive. If you have and docs or info about installing a binary to be open firmware bootable that could help me, thanks ;-)
First you have to compile GRUB 2. After that you can use grub-mkimage to create an ELF file that is loadable by open firmware. Using grub-mkimage you should specify the name of the output executable and which modules should be included. For testing you should at least include apple.mod, ext2.mod, hfs.mod, ls.mod and normal.mod I think.
After that I just load it using "boot" or tftp.
Quoted 4 lines
The compilation is OK but this patch is still ugly : I left the getopt. I add a flag -DGRUB_HOST to make a distinction between the host and build parts. The
GRUB_HOSTflag is only used in some specific powerpc include directories so it shouldn't affect the i386 part. I also add agrub_machine_finiin
Quoted 8 lines
kern/powerpc/ieee1275/init.cneeded bykern/loader.c. Right nowgrub_machine_finiis empty but it should call for someting likegrub_console_fini(not present in powerpc part) andgrub_ofdisk_fini(not implemented). I left malloc as an alternative to memalign. As far as I look in the code memalign is used to align memory segment from elf files and every usual cases in elf segments fits in the 16 byte alignment. So it should work well for now waiting for a better implementation to support exotic segment alignments.
I thought GRUBOF was not used anymore, but I see you replaced it. I hope I can find some time to have a look at your patch soon, but please understand if it will take a while.
Quoted 3 lines
Compilation and installation are OK. I get grub-emu grub-mkimage and every modules in the share/grub/ directory and grub-mkimage can produce images. Still need test and improvements but it seems to work.
Cool! please check if your modification did not add any warnings or so, we would like to keep GRUB quite clean.
A complete review has to follow... sorry...
Thanks,
Marco
Selon Marco Gerards <[email protected]>:
Quoted 3 lines
If that is used, you could replace
int32_tbygrub_uint32_t, etc.
ok I was wondering if here were a specific reason for using both grub_int32_t and int32_t types like one for the host part and one for the build part. But if we can always use grub_xxx types it will make it a lot easier.
Quoted 9 lines
Not including generated files will make the patch a lot smaller. I personally don't have problems with big patches on the mailinglist. Having the patch in the email will make it a lot easier for me to review the patch.
Please use -p as well. It will make reviewing the patch a *LOT* easier.
Ok I will do this
Quoted 8 lines
First you have to compile GRUB 2. After that you can use grub-mkimage to create an ELF file that is loadable by open firmware. Using grub-mkimage you should specify the name of the output executable and which modules should be included. For testing you should at least include apple.mod, ext2.mod, hfs.mod, ls.mod and normal.mod I think.
After that I just load it using "boot" or tftp.
Thank's I will try
Quoted 5 lines
I thought GRUBOF was not used anymore, but I see you replaced it. I hope I can find some time to have a look at your patch soon, but please understand if it will take a while.
Yes GRUBOF have been removed from everywere exept in one .h file in the powerpc part. Must have been forgotten. In fact many little problems like this one seems to come from some great improvements made to Grub2-i386 that have not been ported to the powerpc part.
Quoted 4 lines
Cool! please check if your modification did not add any warnings or so, we would like to keep GRUB quite clean.
most warnings come from the memcpy function that conflicts with the gcc builtin.
Quoted 2 lines
A complete review has to follow... sorry...
No problem there's no rush.
By the way I will probably put a more complete patch in a few days with all your remarks.
Thank's
--
--
____
/ \ / [email protected]
| o o | - http://antoine.terrienne.free.fr | o | \ #153026466 \ V V /
\_/\_/
Antoine Terrienne <[email protected]> writes:
Hi Antoine,
Quoted 4 lines
Quoted 1 line
If that is used, you could replace
int32_tbygrub_uint32_t, etc.ok I was wondering if here were a specific reason for using both
grub_int32_tandint32_ttypes like one for the host part and one for the build part. But if we can always usegrub_xxxtypes it will make it a lot easier.
The reason was that this code was part of another project. It has been put into GRUB 2 and I think I missed these int32_t thingies.
Quoted 9 lines
Quoted 4 lines
I thought GRUBOF was not used anymore, but I see you replaced it. I hope I can find some time to have a look at your patch soon, but please understand if it will take a while.
Yes GRUBOF have been removed from everywere exept in one .h file in the powerpc part. Must have been forgotten. In fact many little problems like this one seems to come from some great improvements made to Grub2-i386 that have not been ported to the powerpc part.
What kind of things do you think there are missing for the PPC port? It should be quite complete by now. It does not compile at the moment, but this will be fixed in CVS really soon.
Quoted 6 lines
Quoted 4 lines
Cool! please check if your modification did not add any warnings or so, we would like to keep GRUB quite clean.
most warnings come from the memcpy function that conflicts with the gcc builtin.
Can you show us?
Quoted 6 lines
Quoted 2 lines
A complete review has to follow... sorry...
No problem there's no rush.
By the way I will probably put a more complete patch in a few days with all your remarks.
Cool.
Thanks,
Marco
Selon Marco Gerards <[email protected]>:
Quoted 5 lines
What kind of things do you think there are missing for the PPC port? It should be quite complete by now. It does not compile at the moment, but this will be fixed in CVS really soon.
for exemple the gub_loader_boot function in kern/loader.c uses grub_machine_fini. This function is defined in kern/i386/pc/init.c but not in kern/powerpc/ieee1275/init.c. Same problem with include/grub/i386/pc/init.h and include/powerpc/ieee1275/init.h. As powerpc par uses somme i386 parts there are somme missing declarations in powerpc. It just looks like the powerpc part is not up to date with the i386 one.
Well I fix must of these litte problems in the patch in a way to comile but I'm not sure it is fully fonctionnal.
Quoted 6 lines
Quoted 2 lines
most warnings come from the memcpy function that conflicts with the gcc
builtin.
Can you show us?
Yes of course, I join a file with all the warnings I get at compilation.
--
--
____
/ \ / [email protected]
| o o | - http://antoine.terrienne.free.fr | o | \ #153026466 \ V V /
\_/\_/
In file included from ../grub2/commands/boot.c:24:../grub2/include/grub/misc.h:41: warning: conflicting types for built-in function `memcpy'
In file included from ../grub2/commands/cat.c:27:../grub2/include/grub/misc.h:41: warning: conflicting types for built-in function `memcpy'
In file included from ../grub2/commands/cmp.c:24:../grub2/include/grub/misc.h:41: warning: conflicting types for built-in function `memcpy'
In file included from ../grub2/commands/configfile.c:25:../grub2/include/grub/misc.h:41: warning: conflicting types for built-in function `memcpy'
In file included from ../grub2/commands/default.c:22:../grub2/include/grub/misc.h:41: warning: conflicting types for built-in function `memcpy'
In file included from ../grub2/commands/help.c:24:../grub2/include/grub/misc.h:41: warning: conflicting types for built-in function `memcpy'
In file included from ../grub2/commands/terminal.c:24:../grub2/include/grub/misc.h:41: warning: conflicting types for built-in function `memcpy'
In file included from ../grub2/commands/ls.c:22:../grub2/include/grub/misc.h:41: warning: conflicting types for built-in function `memcpy'
In file included from ../grub2/commands/timeout.c:22:../grub2/include/grub/misc.h:41: warning: conflicting types for built-in function `memcpy'../grub2/commands/i386/pc/reboot.c: In function `grub_cmd_reboot':../grub2/commands/i386/pc/reboot.c:32: warning: implicit declaration of function `grub_reboot'
In file included from ../grub2/disk/loopback.c:24:../grub2/include/grub/misc.h:41: warning: conflicting types for built-in function `memcpy'
In file included from ../grub2/fs/ext2.c:45:../grub2/include/grub/misc.h:41: warning: conflicting types for built-in function `memcpy'
In file included from ../grub2/fs/fat.c:25:../grub2/include/grub/misc.h:41: warning: conflicting types for built-in function `memcpy'
In file included from ../grub2/fs/fshelp.c:23:../grub2/include/grub/misc.h:41: warning: conflicting types for built-in function `memcpy'
In file included from ../grub2/fs/hfs.c:24:../grub2/include/grub/misc.h:41: warning: conflicting types for built-in function `memcpy'
In file included from ../grub2/fs/iso9660.c:25:../grub2/include/grub/misc.h:41: warning: conflicting types for built-in function `memcpy'
In file included from ../grub2/fs/jfs.c:24:../grub2/include/grub/misc.h:41: warning: conflicting types for built-in function `memcpy'
In file included from ../grub2/fs/minix.c:24:../grub2/include/grub/misc.h:41: warning: conflicting types for built-in function `memcpy'
In file included from ../grub2/fs/ufs.c:24:../grub2/include/grub/misc.h:41: warning: conflicting types for built-in function `memcpy'
In file included from ../grub2/kern/device.c:26:../grub2/include/grub/misc.h:41: warning: conflicting types for built-in function `memcpy'
In file included from ../grub2/kern/disk.c:25:../grub2/include/grub/misc.h:41: warning: conflicting types for built-in function `memcpy'
In file included from ../grub2/kern/dl.c:24:../grub2/include/grub/misc.h:41: warning: conflicting types for built-in function `memcpy'
In file included from ../grub2/kern/env.c:22:../grub2/include/grub/misc.h:41: warning: conflicting types for built-in function `memcpy'
In file included from ../grub2/kern/err.c:22:../grub2/include/grub/misc.h:41: warning: conflicting types for built-in function `memcpy'
In file included from ../grub2/kern/file.c:21:../grub2/include/grub/misc.h:41: warning: conflicting types for built-in function `memcpy'
In file included from ../grub2/kern/fs.c:26:../grub2/include/grub/misc.h:41: warning: conflicting types for built-in function `memcpy'
In file included from ../grub2/kern/loader.c:21:../grub2/include/grub/misc.h:41: warning: conflicting types for built-in function `memcpy'
In file included from ../grub2/kern/main.c:22:../grub2/include/grub/misc.h:41: warning: conflicting types for built-in function `memcpy'
In file included from ../grub2/kern/misc.c:21:../grub2/include/grub/misc.h:41: warning: conflicting types for built-in function `memcpy'../grub2/kern/misc.c:49: warning: alias definitions not supported in this configuration; ignored../grub2/kern/misc.c:52: warning: alias definitions not supported in this configuration; ignored../grub2/kern/misc.c:159: warning: conflicting types for built-in function `memcmp'../grub2/kern/misc.c:159: warning: alias definitions not supported in this configuration; ignored../grub2/kern/misc.c:387: warning: conflicting types for built-in function `memset'../grub2/kern/misc.c:387: warning: alias definitions not supported in this configuration; ignored
In file included from ../grub2/kern/rescue.c:24:../grub2/include/grub/misc.h:41: warning: conflicting types for built-in function `memcpy'
In file included from ../grub2/kern/term.c:23:../grub2/include/grub/misc.h:41: warning: conflicting types for built-in function `memcpy'
In file included from ../grub2/normal/arg.c:22:../grub2/include/grub/misc.h:41: warning: conflicting types for built-in function `memcpy'
In file included from ../grub2/normal/cmdline.c:21:../grub2/include/grub/misc.h:41: warning: conflicting types for built-in function `memcpy'
In file included from ../grub2/normal/command.c:21:../grub2/include/grub/misc.h:41: warning: conflicting types for built-in function `memcpy'
In file included from ../grub2/normal/main.c:25:../grub2/include/grub/misc.h:41: warning: conflicting types for built-in function `memcpy'
In file included from ../grub2/normal/menu.c:22:../grub2/include/grub/misc.h:41: warning: conflicting types for built-in function `memcpy'
In file included from ../grub2/normal/menu_entry.c:22:../grub2/include/grub/misc.h:41: warning: conflicting types for built-in function `memcpy'
In file included from ../grub2/partmap/amiga.c:22:../grub2/include/grub/misc.h:41: warning: conflicting types for built-in function `memcpy'
In file included from ../grub2/partmap/apple.c:22:../grub2/include/grub/misc.h:41: warning: conflicting types for built-in function `memcpy'
In file included from ../grub2/partmap/pc.c:25:../grub2/include/grub/misc.h:41: warning: conflicting types for built-in function `memcpy'
In file included from ../grub2/partmap/sun.c:24:../grub2/include/grub/misc.h:41: warning: conflicting types for built-in function `memcpy'../grub2/util/grub-emu.c: In function `grub_machine_fini':../grub2/util/grub-emu.c:89: warning: implicit declaration of function `grub_console_fini'../grub2/util/misc.c: In function `grub_memalign':../grub2/util/misc.c:232: warning: unused parameter `align'../grub2/util/i386/pc/biosdisk.c:198:3: warning: #warning "No special routine to get the size of a block device is implemented for your OS. This is not possibly fatal." ../grub2/util/i386/pc/biosdisk.c:675:3: warning: #warning "The function get_os_disk' might not work on your OS correctly." ../grub2/util/i386/pc/biosdisk.c: In function get_os_disk':../grub2/util/i386/pc/biosdisk.c:606: warning: unused variable `path'../grub2/util/i386/pc/biosdisk.c:606: warning: unused variable `p'../grub2/util/i386/pc/biosdisk.c:855:3: warning: #warning "The function grub_util_biosdisk_get_grub_dev' might not work on your OS correctly." ../grub2/util/misc.c: In function grub_memalign':../grub2/util/misc.c:232: warning: unused parameter `align'../grub2/fs/ufs.c: In function `grub_ufs_find_file':../grub2/fs/ufs.c:474: warning: declaration of `_x' shadows a previous local../grub2/fs/ufs.c:474: warning: shadowed declaration is here../grub2/fs/ufs.c:474: warning: declaration of `_x' shadows a previous local../grub2/fs/ufs.c:474: warning: shadowed declaration is here
Quoted 8 lines · Antoine Terrienne
Selon Marco Gerards <[email protected]>:
Quoted 5 lines
What kind of things do you think there are missing for the PPC port? It should be quite complete by now. It does not compile at the moment, but this will be fixed in CVS really soon.
Quoted 8 lines
for exemple the
gub_loader_bootfunction inkern/loader.cusesgrub_machine_fini. This function is defined inkern/i386/pc/init.cbut not inkern/powerpc/ieee1275/init.c. Same problem withinclude/grub/i386/pc/init.handinclude/powerpc/ieee1275/init.h. As powerpc par uses somme i386 parts there are somme missing declarations in powerpc. It just looks like the powerpc part is not up to date with the i386 one.
Well I fix must of these litte problems in the patch in a way to comile but I'm not sure it is fully fonctionnal.
It is fixed in CVS now, thanks to Hollis. I thought you meant functionality instead of brokenness.
Thanks,
Marco
Quoted 10 lines · Yoshinori K. Okuji
Quoted 4 lines
I found another glibc specific function : alloca. Used in cmain in
boot/powerpc/ieee1275/cmain.c. I repace it by declaring argv as an array of 64 elements : char *arg[64] (should be enouth ?). As the variables are allocated in the stack just like alloca do it should work just the same.This kind of functions should be complemented by a library. Look at Gnulib:
http://www.gnu.org/software/gnulib/
I think Gnulib contains argp as well.
It does and I would prefer using argp from gnulib.
Thanks,
Marco