Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1mmpTG-000243-2E for mharc-grub-devel@gnu.org; Mon, 15 Nov 2021 22:49:22 -0500 Received: from eggs.gnu.org ([209.51.188.92]:49446) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mmpTE-00023n-JD for grub-devel@gnu.org; Mon, 15 Nov 2021 22:49:20 -0500 Received: from [2607:f8b0:4864:20::929] (port=42825 helo=mail-ua1-x929.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mmpTC-0005qm-Li for grub-devel@gnu.org; Mon, 15 Nov 2021 22:49:20 -0500 Received: by mail-ua1-x929.google.com with SMTP id t13so39485388uad.9 for ; Mon, 15 Nov 2021 19:49:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=axtens.net; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=D0GjZ+vkCi2KR8JUIsklIEQjp7zV7Yf0jW6CkHSO2Rk=; b=iZ+KhfricYlvAA7GIiClOQpTm33aqLvSgTufBlIYfc+ikGC6l74z9UIAzRHKPWZQ5W C6A/k5xy7eElFcZSoy1ywR4NbHIjL7pMF0u6zzz3GRzuqKa89mmeZ4A5HnXO5zft0y0l qL39bLuytAONRhamFWUB4fSEOXHI3uW/8+dFA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=D0GjZ+vkCi2KR8JUIsklIEQjp7zV7Yf0jW6CkHSO2Rk=; b=fgztHgnnPIaz4V4/EznH8dHmP3oDnQR4erOQPLULGoDlMxDJG5BD59kO0RdJusDKQt OmqJKlrLtmT4cqRo1hVAOEethspwVZS3HCERSPZQTF3Z0WF0k0x4qN3fV30ETiLbYr7G 0/g7d1I1knVPML/my87pt6f/7wDgs+RxtQwH8gUcrwYoamjvZj1BS3vuO03etosUcIVt 5ne/Yd+iFvNhqjSkPUAaocZOXRH01YxvBWlWOYItDa+KGYjD+Zo3fgZyU1tC58ROe3y1 7kDzY3CgAS4DoKDTzfaU2745ZZS0K+mKQrqmBdaXsccgafzy1RfPRXQiVQwX2ApPL53J je6g== X-Gm-Message-State: AOAM532p0vDfDqeNSy5/s7GUMyLJjDI+I0IWUsBsWG2GmwegfuG/8XGX FcjhKMHrC+PTQFKpYqm2AGh8RUV0yLDCTQ== X-Google-Smtp-Source: ABdhPJz41oAxvK+v7k/1qfzYYi37N0hX7xXeHaKNzCMwPL/tY9YisKyN/mlFMQEk02l78kq3dfEvgg== X-Received: by 2002:a17:902:7c13:b0:142:3599:74c5 with SMTP id x19-20020a1709027c1300b00142359974c5mr29167914pll.67.1637034136113; Mon, 15 Nov 2021 19:42:16 -0800 (PST) Received: from localhost ([2001:4479:e000:e400:390c:7b17:9641:ce9d]) by smtp.gmail.com with ESMTPSA id o11sm12923887pgh.91.2021.11.15.19.42.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Nov 2021 19:42:15 -0800 (PST) From: Daniel Axtens To: grub-devel@gnu.org Cc: Daniel Axtens Subject: [PATCH 2/2] ieee1275: set real-base in the PowerPC IEEE1275 Note to 32MB Date: Tue, 16 Nov 2021 14:42:05 +1100 Message-Id: <20211116034205.463101-3-dja@axtens.net> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20211116034205.463101-1-dja@axtens.net> References: <20211116034205.463101-1-dja@axtens.net> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Host-Lookup-Failed: Reverse DNS lookup failed for 2607:f8b0:4864:20::929 (failed) Received-SPF: pass client-ip=2607:f8b0:4864:20::929; envelope-from=dja@axtens.net; helo=mail-ua1-x929.google.com X-Spam_score_int: -12 X-Spam_score: -1.3 X-Spam_bar: - X-Spam_report: (-1.3 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, PDS_HP_HELO_NORDNS=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 16 Nov 2021 03:49:20 -0000 Background ---------- Figuring out how to lay out memory in powerpc OpenFirmware is a bit of a complicate dance. Firstly, firmware needs to reserve a little bit of space for things like interrupt vectors that live at a fixed address. This is usually 0x4000 bytes. PFW calls this "stage 1" (of the firmware, not the bootloader!) As discussed in the previous patch, the ELF image is loaded at 'load-base' before it's unpacked. load-base is, by default, set at the end of stage 1. From there, the ELF loader unpacks the binary to wherever the program headers say and the program is executed. Next in memory, we need space for the rest of firmware. (PFW calls this "stage 2" of firmware.) The starting address begins at 'real-base'.* We need to not run past real-base when loading our ELF binary. load-base and real-base have defaults from firmware, and may be configurable in various ways. On PFW: - real-base defaults to 12MB (0xc00000) - real-base is configurable with the IEEE1275 ELF note. - a proprietary OS bootloader configures real-base to 0x2000000 (32MB). On SLOF: - real-base is set dynamically towards the end of accessible memory. - real-base is not configurable. On 32-bit, I'm not sure quite what the story is. I don't have any 32-bit Apple hardware to test with. However, with this change, grub still loads and runs, including when I hack up the tests to install the note by default. * I'm assuming here that the firmware doesn't do virtual mode. This is true on Power for both PFW and SLOF; Apple OF implementations may do things differently. Moving real-base ---------------- To account for growing grub binary sizes, we want to try to expand the amount of memory that we have to work with. We have the following constraints and inputs: - A good practical limit for the size of the grub binary is 8MB, as that's about the size of the PReP partition on a number of distro setups. (See previous patch.) - We also want things to work if people forget to include the note. Even if distros build it in to signed images, people running grub-install will probably forget to set it and we don't want to break their systems. (Helpfully, if you're running grub-install manually there's a decent chance you're not building in a bunch of modules so things are likely to be smaller anyway.) - We want to avoid doing anything too novel with enterprise software. So when the note is included, set real-base to 32MB. Results ------- This means that: - The ELF file will be loaded at 0x4000 and have just short of 8MB to fit into. (This is entirely the work of the previous patch - the 8MB limitation is because we now load at 8MB instead of 2MB.) - Nothing changes on SLOF, because SLOF ignores the note. We have oodles of space in SLOF. - On PFW when the note is not installed, we have about 4MB of space for ELF loader to put the program into (the gap between 8MB and the default real-base of 12MB). This is well more than any current grub image uses. - On PFW when the note _is_ installed, we will have about 24MB of space to put the program bits into. This is well more than we're likely to use unless people start putting very large arrays in BSS, but it means we're aligned with a proprietary bootloader and therefore we can be assured that some testing has been done. Signed-off-by: Daniel Axtens --- util/grub-mkimagexx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util/grub-mkimagexx.c b/util/grub-mkimagexx.c index d78fa3e53308..2ac40b82a22d 100644 --- a/util/grub-mkimagexx.c +++ b/util/grub-mkimagexx.c @@ -467,7 +467,7 @@ SUFFIX (grub_mkimage_generate_elf) (const struct grub_install_image_target_desc note_ptr->header.n_type = grub_host_to_target32 (GRUB_IEEE1275_NOTE_TYPE); strcpy (note_ptr->name, GRUB_IEEE1275_NOTE_NAME); note_ptr->descriptor.real_mode = grub_host_to_target32 (0xffffffff); - note_ptr->descriptor.real_base = grub_host_to_target32 (0x00c00000); + note_ptr->descriptor.real_base = grub_host_to_target32 (0x02000000); note_ptr->descriptor.real_size = grub_host_to_target32 (0xffffffff); note_ptr->descriptor.virt_base = grub_host_to_target32 (0xffffffff); note_ptr->descriptor.virt_size = grub_host_to_target32 (0xffffffff); -- 2.32.0