Received: from list by lists.gnu.org with archive (Exim 4.71) id 1h0yyi-00057l-5F for mharc-grub-devel@gnu.org; Mon, 04 Mar 2019 20:34:44 -0500 Received: from eggs.gnu.org ([209.51.188.92]:48085) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h0yyf-00057S-PO for grub-devel@gnu.org; Mon, 04 Mar 2019 20:34:43 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h0yyd-0005Uj-Sz for grub-devel@gnu.org; Mon, 04 Mar 2019 20:34:41 -0500 Received: from aserp2130.oracle.com ([141.146.126.79]:57694) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1h0yya-0005Ac-2x for grub-devel@gnu.org; Mon, 04 Mar 2019 20:34:38 -0500 Received: from pps.filterd (aserp2130.oracle.com [127.0.0.1]) by aserp2130.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x251YTwC013081; Tue, 5 Mar 2019 01:34:29 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id; s=corp-2018-07-02; bh=6fSRuXamKBSkBZgMflsPY+LnePXRdGIQyA5Ko9QswTU=; b=id93HzV7jF+6uM4T/t9kT/eRso2mw7WSJAgOlCFgntLOuXVj+5P06juN64o9SsWh+XSv +r8RiH6x3Cjd21Pc6UK3NfMG3uMdODtPeE+wNrRkKmxtysfAyatQmS1r890LpgV4vzo7 i+Z/t4fWMcKk5ZcNtRACgCYvKLOBfuDHmKFK4Ly9S0CE5aDDTjggurXp+dzhwRkQOjLM +Pt65ZAepS8gREExctdGYfuL7Oyr6vioU1VCZqfJ68L3SoJLe4yyd2U8VNBpIUTBFR6d ZG/u2AXChG05aTaSVYvi8yG8ujVRG9fHraetW5DcfSDEGrr+EbVvK7Q8n0j4qDAmqDas sQ== Received: from aserv0021.oracle.com (aserv0021.oracle.com [141.146.126.233]) by aserp2130.oracle.com with ESMTP id 2qyfbe2qq3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 05 Mar 2019 01:34:29 +0000 Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by aserv0021.oracle.com (8.14.4/8.14.4) with ESMTP id x251YNd2022662 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 5 Mar 2019 01:34:24 GMT Received: from abhmp0019.oracle.com (abhmp0019.oracle.com [141.146.116.25]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id x251YNrc015799; Tue, 5 Mar 2019 01:34:23 GMT Received: from ca-qasparc20.us.oracle.com (/10.147.24.73) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 04 Mar 2019 17:34:22 -0800 From: Eric Snowberg To: grub-devel@gnu.org Cc: daniel.kiper@oracle.com, eric.snowberg@oracle.com, glaubitz@physik.fu-berlin.de Subject: [PATCH] sparc64: add bios boot partition support Date: Mon, 4 Mar 2019 17:34:01 -0800 Message-Id: <1551749641-41374-1-git-send-email-eric.snowberg@oracle.com> X-Mailer: git-send-email 1.7.1 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9185 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=3 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=851 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1903050009 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] X-Received-From: 141.146.126.79 X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 05 Mar 2019 01:34:43 -0000 Add BIOS Boot Partition support for sparc64 platforms. This will work a little different than x86. With GPT, both the OBP "load" and "boot" commands are partition aware and neither command can see the partition table. Therefore the entire boot-loader is stored within the BIOS Boot Partition and nothing is stored within the bootstrap code area of MBR. To use it, the end user will issue the boot command with the path pointing to the BIOS Boot Partition. For example with the disk below: Model: Unknown (unknown) Disk /dev/nvme1n1: 1600GB Sector size (logical/physical): 512B/512B Partition Table: gpt Number Start End Size File system Name Flags 1 1049kB 1075MB 1074MB ext3 2 1075MB 1076MB 1049kB bios_grub 3 1076MB 1600GB 1599GB lvm To boot grub2 from OBP, you would use: boot /pci@302/pci@1/pci@0/pci@13/nvme@0/disk@1:b Signed-off-by: Eric Snowberg --- util/setup.c | 76 +++++++++++++++++++++++++++++++++++++++++++++++++++------- 1 files changed, 67 insertions(+), 9 deletions(-) diff --git a/util/setup.c b/util/setup.c index 9c1e1b7..7a1db9e 100644 --- a/util/setup.c +++ b/util/setup.c @@ -205,7 +205,6 @@ save_blocklists (grub_disk_addr_t sector, unsigned offset, unsigned length, #endif } -#ifdef GRUB_SETUP_BIOS /* Context for setup/identify_partmap. */ struct identify_partmap_ctx { @@ -241,7 +240,6 @@ identify_partmap (grub_disk_t disk __attribute__ ((unused)), ctx->multiple_partmaps = 1; return 1; } -#endif #ifdef GRUB_SETUP_BIOS #define SETUP grub_util_bios_setup @@ -262,9 +260,7 @@ SETUP (const char *dir, char *boot_img, *core_img, *boot_path; char *root = 0; size_t boot_size, core_size; -#ifdef GRUB_SETUP_BIOS grub_uint16_t core_sectors; -#endif grub_device_t root_dev = 0, dest_dev, core_dev; grub_util_fd_t fp; struct blocklists bl; @@ -288,10 +284,8 @@ SETUP (const char *dir, core_path = grub_util_get_path (dir, core_file); core_size = grub_util_get_image_size (core_path); -#ifdef GRUB_SETUP_BIOS core_sectors = ((core_size + GRUB_DISK_SECTOR_SIZE - 1) >> GRUB_DISK_SECTOR_BITS); -#endif if (core_size < GRUB_DISK_SECTOR_SIZE) grub_util_error (_("the size of `%s' is too small"), core_path); #ifdef GRUB_SETUP_BIOS @@ -372,8 +366,8 @@ SETUP (const char *dir, if (grub_env_set ("root", root) != GRUB_ERR_NONE) grub_util_error ("%s", grub_errmsg); -#ifdef GRUB_SETUP_BIOS { +#ifdef GRUB_SETUP_BIOS char *tmp_img; grub_uint8_t *boot_drive_check; @@ -398,6 +392,7 @@ SETUP (const char *dir, boot_drive_check[0] = 0x90; boot_drive_check[1] = 0x90; } +#endif struct identify_partmap_ctx ctx = { .dest_partmap = NULL, @@ -413,6 +408,7 @@ SETUP (const char *dir, grub_partition_iterate (dest_dev->disk, identify_partmap, &ctx); +#ifdef GRUB_SETUP_BIOS /* Copy the partition table. */ if (ctx.dest_partmap || (!allow_floppy && !grub_util_biosdisk_is_floppy (dest_dev->disk))) @@ -421,6 +417,7 @@ SETUP (const char *dir, GRUB_BOOT_MACHINE_PART_END - GRUB_BOOT_MACHINE_WINDOWS_NT_MAGIC); free (tmp_img); +#endif if (ctx.container && grub_strcmp (ctx.container->partmap->name, "msdos") == 0 @@ -508,10 +505,21 @@ SETUP (const char *dir, else maxsec = core_sectors; +#ifdef GRUB_SETUP_BIOS if (maxsec > ((0x78000 - GRUB_KERNEL_I386_PC_LINK_ADDR) >> GRUB_DISK_SECTOR_BITS)) maxsec = ((0x78000 - GRUB_KERNEL_I386_PC_LINK_ADDR) >> GRUB_DISK_SECTOR_BITS); +#endif + +#ifdef GRUB_SETUP_SPARC64 + /* On SPARC we need two extra. One is because we are combining the + * core.img with the boot.img. The other is because the boot sector + * starts at 1. + */ + nsec += 2; + maxsec += 2; +#endif if (is_ldm) err = grub_util_ldm_embed (dest_dev->disk, &nsec, maxsec, @@ -560,9 +568,35 @@ SETUP (const char *dir, bl.block--; bl.block->start = 0; bl.block->len = 0; +#ifdef GRUB_SETUP_BIOS bl.block->segment = 0; +#endif + +#ifdef GRUB_SETUP_SPARC64 + { + /* On SPARC, the block-list entries need to be based off the beginning + of the parition, not the beginning of the disk. */ + struct grub_boot_blocklist *block; + block = bl.first_block; + + while (block->len) + { + block->start -= bl.first_sector; + block--; + } + } + + /* Reserve space for the boot block since it can not be in the + Parition table on SPARC */ + assert (bl.first_block->len > 2); + bl.first_block->start += 2; + bl.first_block->len -= 2; + write_rootdev (root_dev, boot_img, sectors[BOOT_SECTOR + 1] - bl.first_sector); +#endif +#ifdef GRUB_SETUP_BIOS write_rootdev (root_dev, boot_img, bl.first_sector); +#endif /* Round up to the nearest sector boundary, and zero the extra memory */ core_img = xrealloc (core_img, nsec * GRUB_DISK_SECTOR_SIZE); @@ -572,7 +606,7 @@ SETUP (const char *dir, bl.first_block = (struct grub_boot_blocklist *) (core_img + GRUB_DISK_SECTOR_SIZE - sizeof (*bl.block)); - +#if GRUB_SETUP_BIOS grub_size_t no_rs_length; no_rs_length = grub_target_to_host16 (grub_get_unaligned16 (core_img @@ -603,14 +637,34 @@ SETUP (const char *dir, grub_disk_write (dest_dev->disk, sectors[i], 0, GRUB_DISK_SECTOR_SIZE, core_img + i * GRUB_DISK_SECTOR_SIZE); +#endif +#ifdef GRUB_SETUP_SPARC64 + { + int isec = BOOT_SECTOR; + + /* Write the boot image onto the disk. */ + if (grub_disk_write (dest_dev->disk, sectors[isec++], 0, + GRUB_DISK_SECTOR_SIZE, boot_img)) + grub_util_error ("%s", grub_errmsg); + + /* Write the core image onto the disk. */ + for (i = 0 ; isec < nsec; i++, isec++) + { + if (grub_disk_write (dest_dev->disk, sectors[isec], 0, + GRUB_DISK_SECTOR_SIZE, + core_img + i * GRUB_DISK_SECTOR_SIZE)) + grub_util_error ("%s", grub_errmsg); + } + } + +#endif grub_free (sectors); goto finish; } unable_to_embed: -#endif if (dest_dev->disk->dev->id != root_dev->disk->dev->id) grub_util_error ("%s", _("embedding is not possible, but this is required for " @@ -797,6 +851,10 @@ unable_to_embed: 0, GRUB_DISK_SECTOR_SIZE, boot_img)) grub_util_error ("%s", grub_errmsg); +#ifdef GRUB_SETUP_SPARC64 + finish: +#endif + grub_util_biosdisk_flush (root_dev->disk); grub_util_biosdisk_flush (dest_dev->disk); -- 1.7.1