From nobody Mon Nov 10 12:52:49 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.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=163.com ARC-Seal: i=1; a=rsa-sha256; t=1556115827; cv=none; d=zoho.com; s=zohoarc; b=RZbguELgAEuM02Qw2hHuyIIYAxLBOS5v0LwNM9cYsJIMMfjsi6SazZGI+CgZSoFrKg0X7WohJUkFhTPhjFaUY09IkxT1SCQlsL+L7vVvYCXapjgNnzhfWn9LCSQ8iwspLxYogKIMt5v/rJmQWhOq4pZQLthKSHTFFWbwnoFUe8A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1556115827; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=PwPb4mLM2B0UzCTSk2KeE78xv8ZHNYgaXG8Hlt3/UP8=; b=U2t0XDaHm1PsvkvjoLOyWP93KKN0SB1+84I4B12fl01J+Z2eJue218i6EqS6yzel7pW3iSgZZb5WgOBCoU0pAwAqc6BNVoE2122mVz+SDyL9b6cIz8kYBVM56jp2TxY9zC3x39ibpRnQfBEomJBchsZT42kxCfzL8i6o3TQ0tMc= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=pass (zoho.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 1556115827810492.1517612178151; Wed, 24 Apr 2019 07:23:47 -0700 (PDT) Received: from localhost ([127.0.0.1]:42493 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hJIoJ-0000j8-QN for importer@patchew.org; Wed, 24 Apr 2019 10:23:43 -0400 Received: from eggs.gnu.org ([209.51.188.92]:39117) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hJIfe-0002as-7g for qemu-devel@nongnu.org; Wed, 24 Apr 2019 10:14:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hJIY6-0006jE-2f for qemu-devel@nongnu.org; Wed, 24 Apr 2019 10:06:59 -0400 Received: from m12-14.163.com ([220.181.12.14]:54282) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hJIY4-0006fB-19 for qemu-devel@nongnu.org; Wed, 24 Apr 2019 10:06:57 -0400 Received: from localhost.localdomain (unknown [115.200.201.0]) by smtp10 (Coremail) with SMTP id DsCowAC3Ayl0bcBcrks9CA--.5531S4; Wed, 24 Apr 2019 22:06:49 +0800 (CST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-Id; bh=PwPb4mLM2B0UzCTSk2 KeE78xv8ZHNYgaXG8Hlt3/UP8=; b=Bj4KFbY+oJQhATtW8WDlyUSG7ACyBW490c nlwxDY79kJ53viKMgb2h9Kdg+oejgb00a+xpV3rzu/ZfCSvt1LDHqZjn/TiQ6bhV JfCYX5qIdFpQmNjJ4ImVaajbkuCTcYPIf+r9i59oGef3uKPwhQAzKHnskoemcpZm HMsa7sIu8= From: Li Qiang To: philmd@redhat.com, lersek@redhat.com, kraxel@redhat.com, thuth@redhat.com, lvivier@redhat.com, pbonzini@redhat.com Date: Wed, 24 Apr 2019 07:06:40 -0700 Message-Id: <20190424140643.62457-3-liq3ea@163.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190424140643.62457-1-liq3ea@163.com> References: <20190424140643.62457-1-liq3ea@163.com> X-CM-TRANSID: DsCowAC3Ayl0bcBcrks9CA--.5531S4 X-Coremail-Antispam: 1Uf129KBjvJXoWxWr4DAr4rtrW8Jw18Ar1xAFb_yoW5AFW3pF ZxCF13trZ3G3WfKrnxJw17JF1a9rykXr1UW3y3uFWFyw17Arn8tF42k34Y9ryUXrW8ZF45 A3yq9Fyak3Z7XFJanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07j8TmhUUUUU= X-Originating-IP: [115.200.201.0] X-CM-SenderInfo: 5oltjvrd6rljoofrz/xtbBZhmgbVaD1JFpjQAAsG X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 220.181.12.14 Subject: [Qemu-devel] [PATCH v2 2/5] tests: fw_cfg: add a function to get the fw_cfg file X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Li Qiang , liq3ea@gmail.com, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This is useful to write qtest about fw_cfg file entry. Signed-off-by: Li Qiang Acked-by: Thomas Huth --- tests/libqos/fw_cfg.c | 45 +++++++++++++++++++++++++++++++++++++++++++ tests/libqos/fw_cfg.h | 2 ++ 2 files changed, 47 insertions(+) diff --git a/tests/libqos/fw_cfg.c b/tests/libqos/fw_cfg.c index c6839c53c8..1f46258f96 100644 --- a/tests/libqos/fw_cfg.c +++ b/tests/libqos/fw_cfg.c @@ -16,6 +16,7 @@ #include "libqos/fw_cfg.h" #include "libqtest.h" #include "qemu/bswap.h" +#include "hw/nvram/fw_cfg.h" =20 void qfw_cfg_select(QFWCFG *fw_cfg, uint16_t key) { @@ -59,6 +60,50 @@ static void mm_fw_cfg_select(QFWCFG *fw_cfg, uint16_t ke= y) qtest_writew(fw_cfg->qts, fw_cfg->base, key); } =20 +/* + * The caller need check the return value. When the return value is + * nonzero, it means that some bytes have been transferred. + * + * If the fw_cfg file in question is smaller than the allocated & passed-in + * buffer, then the buffer has been populated only in part. + * + * If the fw_cfg file in question is larger than the passed-in + * buffer, then the return value explains how much room would have been + * necessary in total. And, while the caller's buffer has been fully + * populated, it has received only a starting slice of the fw_cfg file. + */ +size_t qfw_cfg_get_file(QFWCFG *fw_cfg, const char *filename, + void *data, size_t buflen) +{ + uint32_t count; + uint32_t i; + unsigned char *filesbuf =3D NULL; + size_t dsize; + FWCfgFile *pdir_entry; + size_t filesize =3D 0; + + qfw_cfg_get(fw_cfg, FW_CFG_FILE_DIR, &count, sizeof(count)); + count =3D be32_to_cpu(count); + dsize =3D sizeof(uint32_t) + count * sizeof(struct fw_cfg_file); + filesbuf =3D g_malloc(dsize); + qfw_cfg_get(fw_cfg, FW_CFG_FILE_DIR, filesbuf, dsize); + pdir_entry =3D (FWCfgFile *)(filesbuf + sizeof(uint32_t)); + for (i =3D 0; i < count; ++i, ++pdir_entry) { + if (!strcmp(pdir_entry->name, filename)) { + uint32_t len =3D be32_to_cpu(pdir_entry->size); + uint16_t sel =3D be16_to_cpu(pdir_entry->select); + filesize =3D len; + if (len > buflen) { + len =3D buflen; + } + qfw_cfg_get(fw_cfg, sel, data, len); + break; + } + } + g_free(filesbuf); + return filesize; +} + static void mm_fw_cfg_read(QFWCFG *fw_cfg, void *data, size_t len) { uint8_t *ptr =3D data; diff --git a/tests/libqos/fw_cfg.h b/tests/libqos/fw_cfg.h index 60de81e863..13325cc4ff 100644 --- a/tests/libqos/fw_cfg.h +++ b/tests/libqos/fw_cfg.h @@ -31,6 +31,8 @@ void qfw_cfg_get(QFWCFG *fw_cfg, uint16_t key, void *data= , size_t len); uint16_t qfw_cfg_get_u16(QFWCFG *fw_cfg, uint16_t key); uint32_t qfw_cfg_get_u32(QFWCFG *fw_cfg, uint16_t key); uint64_t qfw_cfg_get_u64(QFWCFG *fw_cfg, uint16_t key); +size_t qfw_cfg_get_file(QFWCFG *fw_cfg, const char *filename, + void *data, size_t buflen); =20 QFWCFG *mm_fw_cfg_init(QTestState *qts, uint64_t base); void mm_fw_cfg_uninit(QFWCFG *fw_cfg); --=20 2.17.1