From nobody Thu Nov 14 16:55:31 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1602263519; cv=none; d=zohomail.com; s=zohoarc; b=DYJycfVpHJw3AJPaYcLJpLSW/VP8YW7nJk6bbFYOfAerjshY3HExJ6UoSo6mB8SqMdQG93QS4VqIZ9jDMG3GbdccdjXtiL6J7PS4pbxGzNJCrUdk3qJFYaTFmisQ8I20kIZnKuagrqWxDqEqSWZ/YwAmADBWDG8XDKGsNJQhR70= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602263519; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=PVp+3SZoiBidmYUzudMKJXMJHPS5QgRn7t+s2x5BNPU=; b=R1ltMi5r+0ENeYU2KmcQOceFHnRQgW0TP4qV4EvGsi652g97L9/eKJcq0Ugmh9MCXtbGoetgV+2sR+IKv/AyxkDb48w06njbL0bRtOpexf/3tK7IGwy7teCNA/mJMX/2J37Q3OMohq8ktjJpa7T0fWp90z0+CYiOMu/zUxiMBI4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1602263519225610.149182332748; Fri, 9 Oct 2020 10:11:59 -0700 (PDT) Received: from localhost ([::1]:35602 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kQvvx-0001Sc-VE for importer@patchew.org; Fri, 09 Oct 2020 13:11:57 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46696) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kQvs6-0004eB-5G for qemu-devel@nongnu.org; Fri, 09 Oct 2020 13:07:58 -0400 Received: from mail-wm1-x344.google.com ([2a00:1450:4864:20::344]:52591) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kQvs4-0001Jp-2M for qemu-devel@nongnu.org; Fri, 09 Oct 2020 13:07:57 -0400 Received: by mail-wm1-x344.google.com with SMTP id e23so3502183wme.2 for ; Fri, 09 Oct 2020 10:07:55 -0700 (PDT) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id x1sm5234530wrl.41.2020.10.09.10.07.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Oct 2020 10:07:49 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 6F2EB1FF90; Fri, 9 Oct 2020 18:07:43 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=PVp+3SZoiBidmYUzudMKJXMJHPS5QgRn7t+s2x5BNPU=; b=NaBUfz3x+ZRd3OG7DSuoRY7/ptq0o+d/mIN50vFjfzN1m13XIx+3fYTaLNxJVDTLgk ZWyz4LbxWcP5jbI1Wbbfll44vW8Qj8UUsDSxyVbSCFcTow2pbOgRKgwJTIBa8jhdjbvo 7dK4fV00t3E/YIGz0dSwRhU1ye80PL8xM2/QUw8yYfLa+iFtgvRaTMHr5d4WH26eMjsd yavscVKZsU7cC7DnNOA6RVXrJ28v+AYGeohVl1aqVrl8B5M+Lh+eY/lFBwDmKAeuRNy8 7nMRwy7Zup66cj+Ff0wykrXItjndHQPd/EktLPD+1fhsppPcswuy18JX5fMI/WQ4p10o ACHw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=PVp+3SZoiBidmYUzudMKJXMJHPS5QgRn7t+s2x5BNPU=; b=AhlMk8xZHe3/A8hLE4+BD8UprkyeAuAfOn4oHfNCc/StIwfiqU3OQfqRo/HLSv7sj6 /JtytXD0Unx5UVgmLPdtpO9qdcrQ+TcincnYyC7pZY5LumhEDGy5pQl8dSrftc1FtyTg Bqw47GO/pAATMvSgj3y24G/MXjeGd+IozttmuDnXY17+mHsP6O4ZGLYhXpGBepngHWBR 1NbluxX3wVbdpwMWdFm3voJNF2bo1WW0oV0rmRns94aAYUnE1SPWYXN05QlfKLjqjzIy eWwRCmqQL4PdSHzFDSnB1M49S215UFn9SaawV4t9akl3esvfQ1scXFpatNDy7lLLorp0 kpWw== X-Gm-Message-State: AOAM533loQrpw/62BTLX+SULqDtRZ2vTf6goBfMOndHTEjUa2FaCEGV6 qWIinihZ5JXvFXD/8H0XzMxIDg== X-Google-Smtp-Source: ABdhPJyTtKCuSA1tJG8uzXn9hLxtvNGMhVPEKuTabr9I5CuNqdL0JxfCiaob2O8iTlniAtrfp4+M0A== X-Received: by 2002:a1c:5988:: with SMTP id n130mr15912119wmb.95.1602263274526; Fri, 09 Oct 2020 10:07:54 -0700 (PDT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [RFC PATCH 4/4] generic_loader: allow the insertion of /chosen/module stanzas Date: Fri, 9 Oct 2020 18:07:42 +0100 Message-Id: <20201009170742.23695-5-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20201009170742.23695-1-alex.bennee@linaro.org> References: <20201009170742.23695-1-alex.bennee@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::344; envelope-from=alex.bennee@linaro.org; helo=mail-wm1-x344.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Alistair Francis , julien@xen.org, masami.hiramatsu@linaro.org, andre.przywara@arm.com, stefano.stabellini@linaro.org, takahiro.akashi@linaro.org, stefano.stabellini@xilinx.com, =?UTF-8?q?Alex=20Benn=C3=A9e?= , stratos-dev@op-lists.linaro.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) The /chosen FDT node is how the firmware indicates information about the kernel to the loader code. In a full boot chain this would come from something like a boot loader. However if we use the generic loader to load blobs into RAM before launching a hypervisor for example we can boot directly: $QEMU $ARGS -kernel ~/xen.git/xen/xen \ -append "dom0_mem=3D1G,max:1G loglvl=3Dall guest_loglvl=3Dall" \ -device loader,addr=3D0x47000000,\ file=3DImage,\ len-fdt-compat=3D2,\ fdt-compat[0]=3D'multiboot,,module',\ fdt-compat[1]=3D'multiboot,,kernel',\ fdt-bootargs=3D"root=3D/dev/mapper/vg0-root ro console=3Dhvc0 earlyprin= tk=3Dxen" Note the ,, escapes required for the command line parser. Signed-off-by: Alex Benn=C3=A9e --- include/hw/core/generic-loader.h | 4 +++ hw/core/generic-loader.c | 42 ++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/include/hw/core/generic-loader.h b/include/hw/core/generic-loa= der.h index 19d87b39c8..98b0452430 100644 --- a/include/hw/core/generic-loader.h +++ b/include/hw/core/generic-loader.h @@ -39,6 +39,10 @@ struct GenericLoaderState { bool force_raw; bool data_be; bool set_pc; + + char **fdt_compat; + uint32_t fdt_compat_count; + char *fdt_bootargs; }; =20 #define TYPE_GENERIC_LOADER "loader" diff --git a/hw/core/generic-loader.c b/hw/core/generic-loader.c index a242c076f6..8bd8a33e80 100644 --- a/hw/core/generic-loader.c +++ b/hw/core/generic-loader.c @@ -40,6 +40,8 @@ #include "qapi/error.h" #include "qemu/module.h" #include "hw/core/generic-loader.h" +#include "sysemu/device_tree.h" +#include "hw/boards.h" =20 #define CPU_NONE 0xFFFFFFFF =20 @@ -61,6 +63,39 @@ static void generic_loader_reset(void *opaque) } } =20 +/* + * Insert some FDT nodes for the loaded blob. + */ +static void loader_insert_fdt(GenericLoaderState *s, int size, Error **err= p) +{ + MachineState *machine =3D MACHINE(qdev_get_machine()); + void *fdt =3D machine->fdt; + g_autofree char *node =3D g_strdup_printf("/chosen/module@%#08lx", s->= addr); + uint64_t reg_attr[2] =3D {cpu_to_be64(s->addr), cpu_to_be64(size)}; + + if (!fdt) { + error_setg(errp, "Cannot modify FDT fields if the machine has none= "); + return; + } + + qemu_fdt_add_subnode(fdt, node); + qemu_fdt_setprop(fdt, node, "reg", ®_attr, sizeof(reg_attr)); + + if (s->fdt_compat) { + if (qemu_fdt_setprop_string_array + (fdt, node, "compatible", s->fdt_compat, s->fdt_compat_count) = < 0) { + error_setg(errp, "couldn't set %s/compatible", node); + return; + } + } + + if (s->fdt_bootargs) { + if (qemu_fdt_setprop_string(fdt, node, "bootargs", s->fdt_bootargs= ) < 0) { + error_setg(errp, "couldn't set %s/bootargs", node); + } + } +} + static void generic_loader_realize(DeviceState *dev, Error **errp) { GenericLoaderState *s =3D GENERIC_LOADER(dev); @@ -171,6 +206,10 @@ static void generic_loader_realize(DeviceState *dev, E= rror **errp) } else { s->data =3D cpu_to_le64(s->data); } + + if (s->fdt_compat || s->fdt_bootargs) { + loader_insert_fdt(s, size, errp); + } } =20 static void generic_loader_unrealize(DeviceState *dev) @@ -186,6 +225,9 @@ static Property generic_loader_props[] =3D { DEFINE_PROP_UINT32("cpu-num", GenericLoaderState, cpu_num, CPU_NONE), DEFINE_PROP_BOOL("force-raw", GenericLoaderState, force_raw, false), DEFINE_PROP_STRING("file", GenericLoaderState, file), + DEFINE_PROP_ARRAY("fdt-compat", GenericLoaderState, fdt_compat_count, + fdt_compat, qdev_prop_string, char *), + DEFINE_PROP_STRING("fdt-bootargs", GenericLoaderState, fdt_bootargs), DEFINE_PROP_END_OF_LIST(), }; =20 --=20 2.20.1