From nobody Sat May 10 12:03:29 2025 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 80.81.252.135 is neither permitted nor denied by domain of seabios.org) client-ip=80.81.252.135; envelope-from=seabios-bounces@seabios.org; helo=mail.coreboot.org; Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 80.81.252.135 is neither permitted nor denied by domain of seabios.org) smtp.mailfrom=seabios-bounces@seabios.org Return-Path: Received: from mail.coreboot.org (mail.coreboot.org [80.81.252.135]) by mx.zohomail.com with SMTPS id 1505724476491194.92029420120446; Mon, 18 Sep 2017 01:47:56 -0700 (PDT) Received: from [127.0.0.1] (helo=ra.coreboot.org) by mail.coreboot.org with esmtp (Exim 4.86_2) (envelope-from ) id 1dtriP-0000T4-1Y; Mon, 18 Sep 2017 10:47:41 +0200 Received: from mx1.redhat.com ([209.132.183.28]) by mail.coreboot.org with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.86_2) (envelope-from ) id 1dtriD-0000QU-KN for seabios@seabios.org; Mon, 18 Sep 2017 10:47:37 +0200 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id F2D104E4C6 for ; Mon, 18 Sep 2017 08:47:26 +0000 (UTC) Received: from sirius.home.kraxel.org (ovpn-116-116.ams2.redhat.com [10.36.116.116]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9BA495D9CB; Mon, 18 Sep 2017 08:47:24 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id 29A553F104; Mon, 18 Sep 2017 10:47:24 +0200 (CEST) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com F2D104E4C6 Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=kraxel@redhat.com From: Gerd Hoffmann To: seabios@seabios.org Date: Mon, 18 Sep 2017 10:47:21 +0200 Message-Id: <20170918084724.1133-4-kraxel@redhat.com> In-Reply-To: <20170918084724.1133-1-kraxel@redhat.com> References: <20170918084724.1133-1-kraxel@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Mon, 18 Sep 2017 08:47:27 +0000 (UTC) X-Spam-Score: -6.5 (------) Subject: [SeaBIOS] [PATCH v3 3/6] romfile: add support for constant files. X-BeenThere: seabios@seabios.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: SeaBIOS mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Gerd Hoffmann MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: seabios-bounces@seabios.org Sender: "SeaBIOS" X-Duff: Orig. Duff, Duff Lite, Duff Dry, Duff Dark, Raspberry Duff, Lady Duff, Red Duff, Tartar Control Duff X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Gerd Hoffmann --- src/romfile.h | 2 ++ src/romfile.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/src/romfile.h b/src/romfile.h index c6d62a1ddc..3e0f820047 100644 --- a/src/romfile.h +++ b/src/romfile.h @@ -16,4 +16,6 @@ struct romfile_s *romfile_find(const char *name); void *romfile_loadfile(const char *name, int *psize); u64 romfile_loadint(const char *name, u64 defval); =20 +void const_romfile_add_int(char *name, u32 value); + #endif // romfile.h diff --git a/src/romfile.c b/src/romfile.c index 42261a624c..b598274edc 100644 --- a/src/romfile.c +++ b/src/romfile.c @@ -98,3 +98,49 @@ romfile_loadint(const char *name, u64 defval) return defval; return val; } + +struct const_romfile_s { + struct romfile_s file; + void *data; +}; + +static int +const_read_file(struct romfile_s *file, void *dst, u32 maxlen) +{ + if (file->size > maxlen) + return -1; + struct const_romfile_s *cfile; + cfile =3D container_of(file, struct const_romfile_s, file); + if (maxlen > file->size) + maxlen =3D file->size; + memcpy(dst, cfile->data, maxlen); + return file->size; +} + +static void +const_romfile_add(char *name, void *data, int size) +{ + struct const_romfile_s *cfile =3D malloc_tmp(sizeof(*cfile)); + if (!cfile) { + warn_noalloc(); + return; + } + memset(cfile, 0, sizeof(*cfile)); + strtcpy(cfile->file.name, name, sizeof(cfile->file.name)); + cfile->file.size =3D size; + cfile->file.copy =3D const_read_file; + cfile->data =3D data; + romfile_add(&cfile->file); +} + +void +const_romfile_add_int(char *name, u32 value) +{ + u32 *data =3D malloc_tmp(sizeof(*data)); + if (!data) { + warn_noalloc(); + return; + } + *data =3D value; + const_romfile_add(name, data, sizeof(*data)); +} --=20 2.9.3 _______________________________________________ SeaBIOS mailing list SeaBIOS@seabios.org https://mail.coreboot.org/mailman/listinfo/seabios