From patchwork Tue Jul 24 22:15:46 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geoff Levand X-Patchwork-Id: 948904 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 41Zt894pvPz9s2g for ; Wed, 25 Jul 2018 08:19:53 +1000 (AEST) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=infradead.org header.i=@infradead.org header.b="XYkfcaj3"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 41Zt893FdZzDrdd for ; Wed, 25 Jul 2018 08:19:53 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=infradead.org header.i=@infradead.org header.b="XYkfcaj3"; dkim-atps=neutral X-Original-To: Petitboot@lists.ozlabs.org Delivered-To: Petitboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=none (mailfrom) smtp.mailfrom=infradead.org (client-ip=2001:8b0:10b:1231::1; helo=merlin.infradead.org; envelope-from=geoff@infradead.org; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=infradead.org header.i=@infradead.org header.b="XYkfcaj3"; dkim-atps=neutral Received: from merlin.infradead.org (merlin.infradead.org [IPv6:2001:8b0:10b:1231::1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 41Zt3T5yyDzDrH0 for ; Wed, 25 Jul 2018 08:15:49 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=Date:Cc:To:Subject:From:References: In-Reply-To:Message-Id:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=LeF42v4nTF2ZlmYQadA5j6VAJiYeIWRBMd5JChFBRcM=; b=XYkfcaj35orTvJtY/GxOdnEAo NMYw0osbh8IQNGmthgHvkP2ZwbqaE4pR5ZkRpYYWYQyqEkEZ7kS4A8h+1ghdJqftwd/GB99bzvphB +ziUxaa3dU4s2TlTw1HQLvL8A73QXXy5EAIphX81EdMx13pGBYDbHGeYTQGuhzAhahzm8Pmn8iieu 8rVIjBam2XnDMzWaCLNP1Vp4Ha3HqrO/KJ+iU/WrF9To/zuLHeoRYB43vDXMitUmFw6Gi0FXcLq9P pc4tgBctmLVc4vLNfhWY0cArFIp3S4xN/MPhjc9NVQXCYHZWyoN/YefgME1w67+WwcC046F2tPIJw EgNRsz9oQ==; Received: from geoff by merlin.infradead.org with local (Exim 4.90_1 #2 (Red Hat Linux)) id 1fi5as-0004mq-1U; Tue, 24 Jul 2018 22:15:46 +0000 Message-Id: In-Reply-To: References: From: Geoff Levand Patch-Date: Tue, 24 Jul 2018 15:03:16 -0700 Subject: [PATCH v1 29/30] discover: Add platform-arm64 To: Samuel Mendoza-Jonas Date: Tue, 24 Jul 2018 22:15:46 +0000 X-BeenThere: petitboot@lists.ozlabs.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: Petitboot bootloader development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ge Song , Petitboot@lists.ozlabs.org MIME-Version: 1.0 Errors-To: petitboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Petitboot" From: Ge Song Signed-off-by: Ge Song [Split from a larger patch and cleaned up] Signed-off-by: Geoff Levand --- configure.ac | 12 +- discover/Makefile.am | 4 + discover/platform-arm64.c | 278 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 293 insertions(+), 1 deletion(-) create mode 100644 discover/platform-arm64.c diff --git a/configure.ac b/configure.ac index c92ef1d..952c4af 100644 --- a/configure.ac +++ b/configure.ac @@ -313,7 +313,7 @@ AC_ARG_ENABLE( ) AS_IF( [test "x$enable_platform_all" = "xyes"], - [enable_platform_powerpc="yes"; enable_platform_ps3="yes"] + [enable_platform_arm64="yes"; enable_platform_powerpc="yes"; enable_platform_ps3="yes"] ) AC_ARG_ENABLE( @@ -328,10 +328,20 @@ AC_ARG_ENABLE( AS_IF( [test "x$enable_platform_auto" = "xyes"], [AS_CASE([$host], + [aarch64-*-*], [enable_platform_arm64="yes"], [powerpc*-*-*], [enable_platform_powerpc="yes"], )] ) +AC_ARG_ENABLE( + [platform-arm64], + [AS_HELP_STRING( + [--enable-platform-arm64], + [build support for arm64 platforms [default=no]] + )] +) +AM_CONDITIONAL([PLATFORM_ARM64], [test "x$enable_platform_arm64" = "xyes"]) + AC_ARG_ENABLE( [platform-powerpc], [AS_HELP_STRING( diff --git a/discover/Makefile.am b/discover/Makefile.am index 2b7c794..f5b799d 100644 --- a/discover/Makefile.am +++ b/discover/Makefile.am @@ -82,6 +82,10 @@ discover_platform_ro_SOURCES = \ discover/dt.h \ discover/hostboot.h +if PLATFORM_ARM64 +discover_platform_ro_SOURCES += discover/platform-arm64.c +endif + if PLATFORM_POWERPC discover_platform_ro_SOURCES += discover/platform-powerpc.c endif diff --git a/discover/platform-arm64.c b/discover/platform-arm64.c new file mode 100644 index 0000000..9cd6641 --- /dev/null +++ b/discover/platform-arm64.c @@ -0,0 +1,278 @@ +/* + * This program 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; version 2 of the License. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Copyright (C) 2018 Huaxintong Semiconductor Technology Co.,Ltd. All rights + * reserved. + * Author: Ge Song + */ + +#include +#include +#include +#include +#include +#include + +#include "efi/efivar.h" +#include "file/file.h" +#include "log/log.h" +#include +#include +#include "talloc/talloc.h" +#include "types/types.h" + + +#include "ipmi.h" +#include "platform.h" + +static const char *efi_vars_guid = "fb78ab4b-bd43-41a0-99a2-4e74bef9169b"; + +struct platform_arm64 { + struct param_list params; + struct ipmi *ipmi; +}; + +static inline struct platform_arm64 *to_platform_arm64(struct platform *p) +{ + return (struct platform_arm64 *)(p->platform_data); +} + +static void parse_nvram(struct param_list *pl) +{ + const char** known; + + param_list_for_each_known_param(pl, known) { + struct efi_data *efi_data; + + if (efi_get_variable(NULL, efi_vars_guid, *known, &efi_data)) + continue; + + param_list_set(pl, *known, efi_data->data, + true); + + talloc_free(efi_data); + } +} + +static void write_nvram(const struct param_list *pl) +{ + struct efi_data efi_data; + struct param *param; + + efi_data.attributes = + EFI_VARIABLE_NON_VOLATILE | + EFI_VARIABLE_RUNTIME_ACCESS | + EFI_VARIABLE_BOOTSERVICE_ACCESS; + + param_list_for_each(pl, param) { + if (!param->modified) + continue; + + efi_data.data = param->value; + efi_data.data_size = strlen(param->value) + 1; + efi_set_variable(efi_vars_guid, param->name, &efi_data); + } +} + +static void get_active_consoles(struct config *config) +{ + config->n_consoles = 0; + config->consoles = talloc_array(config, char *, 3); + if (!config->consoles) + return; + + config->consoles[0] = talloc_asprintf(config, + "/dev/hvc0 [IPMI / Serial]"); + config->consoles[1] = talloc_asprintf(config, + "/dev/ttyAMA0 [Serial]"); + config->consoles[2] = talloc_asprintf(config, + "/dev/tty1 [VGA]"); + config->n_consoles = 3; +} + +static int load_config(struct platform *p, struct config *config) +{ + struct param_list *pl = &to_platform_arm64(p)->params; + + parse_nvram(pl); + config_populate_all(config, pl); + get_active_consoles(config); + + return 0; +} + +static char *stdout_cleaner(struct process_stdout *out) +{ + char *p; + const char *const end = out->buf + out->len; + + for (p = out->buf; *p && p < end; p++) { + if (*p == '\n' || *p == '\r') { + *p = 0; + } else if (!isprint(*p)) { + *p = '.'; + } else if (*p == '\t') { + *p = ' '; + } + } + return out->buf; +} + +static int get_sysinfo(struct platform *p, struct system_info *sysinfo) +{ + struct platform_arm64 *platform = to_platform_arm64(p); + struct process_stdout *out1, *out2; + + /* Use dmidecode to get sysinfo type and identifier. */ + + process_get_stdout(NULL, &out1, pb_system_apps.dmidecode, + "--string=system-manufacturer", + NULL); + process_get_stdout(NULL, &out2, pb_system_apps.dmidecode, + "--string=system-product-name", + NULL); + + if (out1 || out2) + sysinfo->type = talloc_asprintf(sysinfo, "%s %s", + out1 ? stdout_cleaner(out1) : "Unknown", + out2 ? stdout_cleaner(out2) : "Unknown"); + talloc_free(out1); + talloc_free(out2); + + process_get_stdout(NULL, &out1, pb_system_apps.dmidecode, + "--string=system-uuid", + NULL); + + if (out1) + sysinfo->identifier = talloc_asprintf(sysinfo, "%s", + stdout_cleaner(out1)); + talloc_free(out1); + + sysinfo->bmc_mac = talloc_zero_size(sysinfo, HWADDR_SIZE); + + if (platform->ipmi) { + ipmi_get_bmc_mac(platform->ipmi, sysinfo->bmc_mac); + ipmi_get_bmc_versions(platform->ipmi, sysinfo); + } + + pb_debug_fn("type: '%s'\n", sysinfo->type); + pb_debug_fn("identifier: '%s'\n", sysinfo->identifier); + pb_debug_fn("bmc_mac: '%s'\n", sysinfo->bmc_mac); + + return 0; +} + +static void params_update_all(struct param_list *pl, + const struct config *config, const struct config *defaults) +{ + char *tmp = NULL; + const char *val; + + if (config->autoboot_enabled == defaults->autoboot_enabled) + val = ""; + else + val = config->autoboot_enabled ? "true" : "false"; + + param_list_set_non_empty(pl, "auto-boot?", val, true); + + if (config->autoboot_timeout_sec == defaults->autoboot_timeout_sec) + val = ""; + else + val = tmp = talloc_asprintf(pl, "%d", + config->autoboot_timeout_sec); + + param_list_set_non_empty(pl, "petitboot,timeout", val, true); + if (tmp) + talloc_free(tmp); + + val = config->lang ?: ""; + param_list_set_non_empty(pl, "petitboot,language", val, true); + + if (config->allow_writes == defaults->allow_writes) + val = ""; + else + val = config->allow_writes ? "true" : "false"; + param_list_set_non_empty(pl, "petitboot,write?", val, true); + + if (!config->manual_console) { + val = config->boot_console ?: ""; + param_list_set_non_empty(pl, "petitboot,console", val, true); + } + + val = config->http_proxy ?: ""; + param_list_set_non_empty(pl, "petitboot,http_proxy", val, true); + val = config->https_proxy ?: ""; + param_list_set_non_empty(pl, "petitboot,https_proxy", val, true); + + params_update_network_values(pl, "petitboot,network", config); + params_update_bootdev_values(pl, "petitboot,bootdevs", config); +} + +static int save_config(struct platform *p, struct config *config) +{ + struct param_list *pl = &to_platform_arm64(p)->params; + struct config *defaults; + + defaults = talloc_zero(NULL, struct config); + config_set_defaults(defaults); + + params_update_all(pl, config, defaults); + talloc_free(defaults); + + write_nvram(pl); + + return 0; +} + +static bool probe(struct platform *p, void *ctx) +{ + static const char *efivars = "/sys/firmware/efi/efivars"; + struct platform_arm64 *platform; + struct statfs buf; + + if (access(efivars, R_OK | W_OK)) { + pb_debug_fn("Can't access %s\n", efivars); + return false; + } + + memset(&buf, '\0', sizeof(buf)); + if (statfs(efivars, &buf)) { + pb_debug_fn("statfs failed: %s: %s\n", efivars, + strerror(errno)); + return false; + } + + if (buf.f_type != EFIVARFS_MAGIC) { + pb_debug_fn("Bad magic = 0x%lx\n", (unsigned long)buf.f_type); + return false; + } + + platform = talloc_zero(ctx, struct platform_arm64); + param_list_init(&platform->params, common_known_params()); + + p->platform_data = platform; + + return true; +} + +static struct platform platform_arm64 = { + .name = "arm64", + .dhcp_arch_id = 0x000d, + .probe = probe, + .load_config = load_config, + .save_config = save_config, + .get_sysinfo = get_sysinfo, +}; + +register_platform(platform_arm64);