From patchwork Tue Feb 12 10:31:03 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Graf X-Patchwork-Id: 158147 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp3670002jaa; Tue, 12 Feb 2019 02:37:56 -0800 (PST) X-Google-Smtp-Source: AHgI3IZF78AIbh09PnZZnTKnPi04i1t+NOwLSNoMhZyyyEdoiTHOVJr7YjJgwh8qgB+VQKHrbbgV X-Received: by 2002:a25:1182:: with SMTP id 124mr2190594ybr.307.1549967876347; Tue, 12 Feb 2019 02:37:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549967876; cv=none; d=google.com; s=arc-20160816; b=tq8u2gk0eYgJPjm+q7pN6AUOEJCIkMMKfIweNZO4WZtPqpuXZp7UgsOYJDs7F32ElS V+yKWfWcpHxav9oASY+HRvy1PquIpVhmHpDuz6OH0w+Q7osNBBvSRgH6Odd1cHe0EMTx /1euT8GZ35mfyEoqnDV7BWG/tTPvVGM2EiCOIOfEg/3K5sWEUpEg4VOSy/jqkvtSaXWv ieQKG3uOh7OZKqYJbWmaOc2hJdwQioi5wfzcXNg1+Ud+vOKLAJWVDuk0DbwMtQxKa/t4 ecH0EvvtR3i+rz/qITu9Pmu7RehfbuQdgM3+9srUt2DNSRoAIhCKyUSNbUy8ZH0Vzm5t fQHQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:references:in-reply-to:message-id:date:subject :to:from; bh=Nv/Vy9eILNn8B/Q08M7RfkWGv9+yb9lSMlQigAXovro=; b=WcMAGG8ugeUAvp+4pp3JVqpE8l228dDTblQgDvC/QFSDAdQMhbAfIGgoFUqSsSNHii iylt6MsNrXoXfGGRFN3lbZWeolWaONnWO/DjsxBVkl53KihCqHQ00wybCeEbqLDcUXAz 4oqla+uwyzVaf29y1Zf4INVoZ3NetAEu/ajVmIhPdwwffcKAgd8PonMKDAl9g1JhcmBj MnZcHyctG60ysI9KSjD7d/eKqcYr9fTjJIVZlE4SQqwL3k7nfv+RZdwaobOVMqY1Wvna OAG8CbtGdny8LnhBb91/ni9VTwdzYCnvShgl3ysenvD6a+EyFaHsomGvPQoNmecTcXXF iDoA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of grub-devel-bounces+patch=linaro.org@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="grub-devel-bounces+patch=linaro.org@gnu.org" Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id v204si7441899ybb.69.2019.02.12.02.37.56 for (version=TLS1 cipher=AES128-SHA bits=128/128); Tue, 12 Feb 2019 02:37:56 -0800 (PST) Received-SPF: pass (google.com: domain of grub-devel-bounces+patch=linaro.org@gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; spf=pass (google.com: domain of grub-devel-bounces+patch=linaro.org@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="grub-devel-bounces+patch=linaro.org@gnu.org" Received: from localhost ([127.0.0.1]:37002 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gtVRr-0004xZ-Nu for patch@linaro.org; Tue, 12 Feb 2019 05:37:55 -0500 Received: from eggs.gnu.org ([209.51.188.92]:37365) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gtVMN-0000ym-FR for grub-devel@gnu.org; Tue, 12 Feb 2019 05:32:18 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gtVML-0004Qt-Cm for grub-devel@gnu.org; Tue, 12 Feb 2019 05:32:15 -0500 Received: from mx2.suse.de ([195.135.220.15]:52048 helo=mx1.suse.de) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gtVMI-00045f-TE for grub-devel@gnu.org; Tue, 12 Feb 2019 05:32:11 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 1A34EB39B; Tue, 12 Feb 2019 10:31:12 +0000 (UTC) From: Alexander Graf To: grub-devel@gnu.org Subject: [PATCH v6 06/11] RISC-V: Add Linux load logic Date: Tue, 12 Feb 2019 11:31:03 +0100 Message-Id: <20190212103108.56963-7-agraf@suse.de> X-Mailer: git-send-email 2.12.3 In-Reply-To: <20190212103108.56963-1-agraf@suse.de> References: <20190212103108.56963-1-agraf@suse.de> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] X-Received-From: 195.135.220.15 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: , Reply-To: The development of GNU GRUB Cc: "rickchen36 @ gmail . com" , David Abdurachmanov , schwab@suse.de, "greentime @ andestech . com" , leif.lindholm@linaro.org, atish.patra@wdc.com, Michael Chang , Alistair Francis , Lukas Auer , Paul Walmsley , Bin Meng , Daniel Kiper MIME-Version: 1.0 Errors-To: grub-devel-bounces+patch=linaro.org@gnu.org Sender: "Grub-devel" We currently only support to run grub on RISC-V as UEFI payload. Ideally, we also only want to support running Linux underneath as UEFI payload. Prepare that with some Linux boot stub code. Once the arm64 target is generalized, we can hook into that one and gain boot functionality. Signed-off-by: Alexander Graf --- v1 -> v2: - adapt to new grub_open_file() API - adapt to new grub_create_loader_cmdline() API v3 -> v4: - Change copyright from 2013 to 2018 - Coding style fixes v4 -> v5: - Use GRUB_EFI_LINUX_FDT_EXTRA_SPACE - Fix whitespace - s/failure/fail v5 -> v6: - remove most linux logic --- grub-core/loader/riscv/linux.c | 59 ++++++++++++++++++++++++++++++++++++++++++ include/grub/riscv32/linux.h | 41 +++++++++++++++++++++++++++++ include/grub/riscv64/linux.h | 43 ++++++++++++++++++++++++++++++ 3 files changed, 143 insertions(+) create mode 100644 grub-core/loader/riscv/linux.c create mode 100644 include/grub/riscv32/linux.h create mode 100644 include/grub/riscv64/linux.h -- 2.12.3 _______________________________________________ Grub-devel mailing list Grub-devel@gnu.org https://lists.gnu.org/mailman/listinfo/grub-devel Reviewed-by: Alistair Francis Reviewed-by: Daniel Kiper diff --git a/grub-core/loader/riscv/linux.c b/grub-core/loader/riscv/linux.c new file mode 100644 index 000000000..d17c488e1 --- /dev/null +++ b/grub-core/loader/riscv/linux.c @@ -0,0 +1,59 @@ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2018 Free Software Foundation, Inc. + * + * GRUB is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * GRUB is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GRUB. If not, see . + */ + +#include +#include +#include + +GRUB_MOD_LICENSE ("GPLv3+"); + +static grub_err_t +grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), + int argc __attribute__ ((unused)), + char *argv[] __attribute__ ((unused))) +{ + grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET, N_("Linux not supported yet")); + + return grub_errno; +} + +static grub_err_t +grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), + int argc __attribute__ ((unused)), + char *argv[] __attribute__ ((unused))) +{ + grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET, N_("Linux not supported yet")); + + return grub_errno; +} + +static grub_command_t cmd_linux, cmd_initrd; + +GRUB_MOD_INIT (linux) +{ + cmd_linux = grub_register_command ("linux", grub_cmd_linux, 0, + N_("Load Linux.")); + cmd_initrd = grub_register_command ("initrd", grub_cmd_initrd, 0, + N_("Load initrd.")); +} + +GRUB_MOD_FINI (linux) +{ + grub_unregister_command (cmd_linux); + grub_unregister_command (cmd_initrd); +} diff --git a/include/grub/riscv32/linux.h b/include/grub/riscv32/linux.h new file mode 100644 index 000000000..b8ed39407 --- /dev/null +++ b/include/grub/riscv32/linux.h @@ -0,0 +1,41 @@ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2018 Free Software Foundation, Inc. + * + * GRUB is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * GRUB is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GRUB. If not, see . + */ + +#ifndef GRUB_RISCV32_LINUX_HEADER +#define GRUB_RISCV32_LINUX_HEADER 1 + +#define GRUB_LINUX_RISCV_MAGIC_SIGNATURE 0x52534356 /* 'RSCV' */ + +/* From linux/Documentation/riscv/booting.txt */ +struct linux_riscv_kernel_header +{ + grub_uint32_t code0; /* Executable code */ + grub_uint32_t code1; /* Executable code */ + grub_uint64_t text_offset; /* Image load offset */ + grub_uint64_t res0; /* reserved */ + grub_uint64_t res1; /* reserved */ + grub_uint64_t res2; /* reserved */ + grub_uint64_t res3; /* reserved */ + grub_uint64_t res4; /* reserved */ + grub_uint32_t magic; /* Magic number, little endian, "RSCV" */ + grub_uint32_t hdr_offset; /* Offset of PE/COFF header */ +}; + +# define linux_arch_kernel_header linux_riscv_kernel_header + +#endif /* ! GRUB_RISCV32_LINUX_HEADER */ diff --git a/include/grub/riscv64/linux.h b/include/grub/riscv64/linux.h new file mode 100644 index 000000000..29140e45e --- /dev/null +++ b/include/grub/riscv64/linux.h @@ -0,0 +1,43 @@ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2018 Free Software Foundation, Inc. + * + * GRUB is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * GRUB is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GRUB. If not, see . + */ + +#ifndef GRUB_RISCV64_LINUX_HEADER +#define GRUB_RISCV64_LINUX_HEADER 1 + +#define GRUB_LINUX_RISCV_MAGIC_SIGNATURE 0x52534356 /* 'RSCV' */ + +#define GRUB_EFI_PE_MAGIC 0x5A4D + +/* From linux/Documentation/riscv/booting.txt */ +struct linux_riscv_kernel_header +{ + grub_uint32_t code0; /* Executable code */ + grub_uint32_t code1; /* Executable code */ + grub_uint64_t text_offset; /* Image load offset */ + grub_uint64_t res0; /* reserved */ + grub_uint64_t res1; /* reserved */ + grub_uint64_t res2; /* reserved */ + grub_uint64_t res3; /* reserved */ + grub_uint64_t res4; /* reserved */ + grub_uint32_t magic; /* Magic number, little endian, "RSCV" */ + grub_uint32_t hdr_offset; /* Offset of PE/COFF header */ +}; + +# define linux_arch_kernel_header linux_riscv_kernel_header + +#endif /* ! GRUB_RISCV64_LINUX_HEADER */