From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.71) id 1W8B3z-0005OC-4F for mharc-grub-devel@gnu.org; Tue, 28 Jan 2014 10:58:59 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52129) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W8B3n-0005A5-G4 for grub-devel@gnu.org; Tue, 28 Jan 2014 10:58:57 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1W8B3l-0000mY-Vw for grub-devel@gnu.org; Tue, 28 Jan 2014 10:58:47 -0500 Received: from v6.chiark.greenend.org.uk ([2001:ba8:1e3::]:42516 helo=chiark.greenend.org.uk) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W8B3l-0000mP-O0 for grub-devel@gnu.org; Tue, 28 Jan 2014 10:58:45 -0500 Received: from [172.20.153.9] (helo=riva.pelham.vpn.ucam.org) by chiark.greenend.org.uk (Debian Exim 4.72 #1) with esmtps (return-path cjwatson@ubuntu.com) id 1W8B3j-0001Sr-Tp for grub-devel@gnu.org; Tue, 28 Jan 2014 15:58:44 +0000 Received: from ns1.pelham.vpn.ucam.org ([172.20.153.2] helo=riva.ucam.org) by riva.pelham.vpn.ucam.org with esmtps (TLS1.2:DHE_RSA_AES_128_CBC_SHA1:128) (Exim 4.80) (envelope-from ) id 1W8B3h-0001Dm-GG for grub-devel@gnu.org; Tue, 28 Jan 2014 15:58:41 +0000 Date: Tue, 28 Jan 2014 15:58:40 +0000 From: Colin Watson To: grub-devel@gnu.org Subject: [PATCH] Port yaboot logic for various powerpc machine types Message-ID: <20140128155840.GA4520@riva.ucam.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2001:ba8:1e3:: X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list Reply-To: The development of GNU GRUB List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 28 Jan 2014 15:58:57 -0000 Some powerpc machines require not updating the NVRAM, and some require adding a CHRP note. This can be handled by existing grub-install command-line options, but it's friendlier to detect this automatically. (Some of these machines may not be supported, but I made the list match for the sake of completeness.) * grub-core/osdep/basic/platform.c (grub_install_get_default_powerpc_machtype): New function. * grub-core/osdep/linux/platform.c (grub_install_get_default_powerpc_machtype): Likewise. * grub-core/osdep/windows/platform.c (grub_install_get_default_powerpc_machtype): Likewise. * include/grub/util/install.h (grub_install_get_default_powerpc_machtype): Add prototype. * util/grub-install.c (main): Set update_nvram to 0 for pmac_oldworld, chrp_ibm, cell, and generic; set chrp_note to 1 for chrp_ibm. Pass chrp_note to grub_install_make_image_wrap. --- grub-core/osdep/basic/platform.c | 5 +++ grub-core/osdep/linux/platform.c | 63 ++++++++++++++++++++++++++++++++++++++ grub-core/osdep/windows/platform.c | 6 ++++ include/grub/util/install.h | 3 ++ util/grub-install.c | 17 +++++++++- 5 files changed, 93 insertions(+), 1 deletion(-) diff --git a/grub-core/osdep/basic/platform.c b/grub-core/osdep/basic/platform.c index 4b5502a..2ab9079 100644 --- a/grub-core/osdep/basic/platform.c +++ b/grub-core/osdep/basic/platform.c @@ -24,3 +24,8 @@ grub_install_get_default_x86_platform (void) return "i386-pc"; } +const char * +grub_install_get_default_powerpc_machtype (void) +{ + return "generic"; +} diff --git a/grub-core/osdep/linux/platform.c b/grub-core/osdep/linux/platform.c index 4b9f6ef..e4b6c3c 100644 --- a/grub-core/osdep/linux/platform.c +++ b/grub-core/osdep/linux/platform.c @@ -93,3 +93,66 @@ grub_install_get_default_x86_platform (void) grub_util_info ("... not found"); return "i386-pc"; } + +const char * +grub_install_get_default_powerpc_machtype (void) +{ + FILE *fp; + char *buf = NULL; + size_t len = 0; + const char *machtype = "generic"; + + fp = grub_util_fopen ("/proc/cpuinfo", "r"); + if (! fp) + return machtype; + + while (getline (&buf, &len, fp) > 0) + { + if (strncmp (buf, "pmac-generation", + sizeof ("pmac-generation") - 1) == 0) + { + if (strstr (buf, "NewWorld")) + { + machtype = "pmac_newworld"; + break; + } + if (strstr (buf, "OldWorld")) + { + machtype = "pmac_oldworld"; + break; + } + } + + if (strncmp (buf, "motherboard", sizeof ("motherboard") - 1) == 0 && + strstr (buf, "AAPL")) + { + machtype = "pmac_oldworld"; + break; + } + + if (strncmp (buf, "machine", sizeof ("machine") - 1) == 0 && + strstr (buf, "CHRP IBM")) + { + machtype = "chrp_ibm"; + break; + } + + if (strncmp (buf, "platform", sizeof ("platform") - 1) == 0) + { + if (strstr (buf, "Maple")) + { + machtype = "maple"; + break; + } + if (strstr (buf, "Cell")) + { + machtype = "cell"; + break; + } + } + } + + free (buf); + fclose (fp); + return machtype; +} diff --git a/grub-core/osdep/windows/platform.c b/grub-core/osdep/windows/platform.c index d217efe..8b42065 100644 --- a/grub-core/osdep/windows/platform.c +++ b/grub-core/osdep/windows/platform.c @@ -128,6 +128,12 @@ grub_install_get_default_x86_platform (void) return "i386-efi"; } +const char * +grub_install_get_default_powerpc_machtype (void) +{ + return "generic"; +} + static void * get_efi_variable (const wchar_t *varname, ssize_t *len) { diff --git a/include/grub/util/install.h b/include/grub/util/install.h index aedcd29..0b18e3f 100644 --- a/include/grub/util/install.h +++ b/include/grub/util/install.h @@ -206,6 +206,9 @@ grub_install_create_envblk_file (const char *name); const char * grub_install_get_default_x86_platform (void); +const char * +grub_install_get_default_powerpc_machtype (void); + void grub_install_register_efi (grub_device_t efidir_grub_dev, const char *efifile_path, diff --git a/util/grub-install.c b/util/grub-install.c index 2e6226a..8d21f8d 100644 --- a/util/grub-install.c +++ b/util/grub-install.c @@ -57,6 +57,7 @@ static char *target; static int removable = 0; static int recheck = 0; static int update_nvram = 1; +static int chrp_note = 0; static char *install_device = NULL; static char *debug_image = NULL; static char *rootdir = NULL; @@ -1140,7 +1141,21 @@ main (int argc, char *argv[]) if (platform == GRUB_INSTALL_PLATFORM_POWERPC_IEEE1275) { + const char *machtype = grub_install_get_default_powerpc_machtype (); int is_guess = 0; + + if (strcmp (machtype, "pmac_oldworld") == 0) + update_nvram = 0; + else if (strcmp (machtype, "chrp_ibm") == 0) + { + update_nvram = 0; + chrp_note = 1; + } + else if (strcmp (machtype, "cell") == 0) + update_nvram = 0; + else if (strcmp (machtype, "generic") == 0) + update_nvram = 0; + if (!macppcdir) { char *d; @@ -1584,7 +1599,7 @@ main (int argc, char *argv[]) /* output */ imgfile, /* memdisk */ NULL, have_load_cfg ? load_cfg : NULL, - /* image target */ mkimage_target, 0); + /* image target */ mkimage_target, chrp_note); /* Backward-compatibility kludges. */ switch (platform) { -- 1.8.5.3