From nobody Thu Mar 28 15:28:18 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of seabios.org designates 78.46.105.101 as permitted sender) client-ip=78.46.105.101; envelope-from=seabios-bounces@seabios.org; helo=coreboot.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of seabios.org designates 78.46.105.101 as permitted sender) smtp.mailfrom=seabios-bounces@seabios.org; dmarc=fail(p=none dis=none) header.from=aheymans.xyz ARC-Seal: i=1; a=rsa-sha256; t=1619771328; cv=none; d=zohomail.com; s=zohoarc; b=oFf85bjwZOu0r+HV/98ycB9fgpyxCNf60SabzI9iG+PcQkyKaZqUsAO8A/ZN1JCShd+Os7Tw8gn73kWwQrc6JGtxC6CgcWHCD7b4+B9G49RDYf3Hx3mlDeYItvvZpZ1llMNaCwVVnILLnEuAo/F9xvWKLk30OFkOipP2iryvqQI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1619771328; h=Content-Type:Content-Transfer-Encoding:Date:From:List-Subscribe:List-Post:List-Owner:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Subject:To; bh=E22XWyipUlrHD/PjUXZkFFV4B2M2y0hofFtnsgAuapo=; b=bEwNeM+o32AEJ9K6i2YWQ5QQtfepNFu/AxSDwI+2D0nNVjUa1PB9N1omF4nwQFjuyebd3lRbKf2udLlE44SWGnTzDYSedP44yd/9E3oe/6xpaPyu4LtAkfVq5qH9Z3vOqW3QGIMVqyjCAv6bwPHNcaZso4F6f3iOpE0SDKsVbeY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of seabios.org designates 78.46.105.101 as permitted sender) smtp.mailfrom=seabios-bounces@seabios.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from coreboot.org (coreboot.org [78.46.105.101]) by mx.zohomail.com with SMTPS id 1619771328074412.17009681122545; Fri, 30 Apr 2021 01:28:48 -0700 (PDT) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by coreboot.org (Postfix) with ESMTPA id 9267716A09D2; Fri, 30 Apr 2021 08:28:44 +0000 (UTC) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by coreboot.org (Postfix) with ESMTP id AF1E616A09CB for ; Fri, 30 Apr 2021 08:28:30 +0000 (UTC) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) for ; Fri, 30 Apr 2021 01:28:30 -0700 (PDT) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by smtp.gmail.com with ESMTPSA id j7sm731812edv.40.2021.04.30.01.28.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Apr 2021 01:28:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aheymans-xyz.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=i4VKyYl2cFyy6h9hNMnc5Rj538904339jYJvMpqIXBQ=; b=MC2tXE8XxjlqI8altNNFm72372VZeht2iek8ANqD4aYaPfpJzgmtzyihjei2cIlmnJ 1b6Yb649O2YLoKGrfEgr4TDBROzNQrwB/PpbF2MD/dwLxUv9hYywo00EyDxixaHa0esR P0XUa+tkYwhAvZ1auHMMSPFOdlK+Z81C28kHp2+N/W0Eqr1NJl8FKmvSO0R2RS2osI+g +vzOewr2F+LdEtCHNls2J3vQc9GE8RmUziT/KYdgn7m0s7C1SAQmztX1JKt6SLEK+bbn TAiriyrvItFQC/PtkKsuD1hV4qYyPPVOCXRZf4y4RChEnJ88GXf228+m4OGbVrapqaD3 Jgdg== 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:mime-version :content-transfer-encoding; bh=i4VKyYl2cFyy6h9hNMnc5Rj538904339jYJvMpqIXBQ=; b=TCvC3iSQez36R5cKvsdKwRdbEQpFhq+wwZ59nhoV0oYaqULCpHtQu2xNf6KAUPLANg Vww6BVA5AYXPA/2mMrArKuOf11VB73H62cjB65JUQ7QGU38OeFzRGizv0GKMsYRSL+7E DRTD0LDLPOP1nPopi5zYOMn0xZd8nUzcwmJN11NftVtYHphmKSjMlBUZYWK0WdA3h5pu AAsEc8lw8NGd8PCiJA9Vg5DEqA+nyiypbHPHsXorxSAhX11H8oJ/bef/bdhy3puqIHYk Jo9LabR6+Y9TyrIUhKkELJDYIX71b2gSIE5oDZgTGC8rMDnMAS+Q0F7NzuAlF4mO30HK yH3w== X-Gm-Message-State: AOAM532QJwbltIx07iIrxJYGeBu52O7mnC4g43Dtz6fAwddFMqae209M gjhxqKTejZ5+Fhvd092xdXCCg2DENMdn4JN0 X-Google-Smtp-Source: ABdhPJzDYDzGr52+1+e8koQtl9A69BWy8KTnz8frFCeuksnO9pRgnN7KAlcVtGlAzSKDGypqVfRVVg== X-Received: by 2002:aa7:cc03:: with SMTP id q3mr4454807edt.366.1619771309821; Fri, 30 Apr 2021 01:28:29 -0700 (PDT) From: Arthur Heymans To: seabios@seabios.org Date: Fri, 30 Apr 2021 10:28:26 +0200 Message-Id: <20210430082826.394372-1-arthur@aheymans.xyz> MIME-Version: 1.0 Message-ID-Hash: PSLZAMCG7C5IU6TLEGXWZCESXHPYUS76 X-Message-ID-Hash: PSLZAMCG7C5IU6TLEGXWZCESXHPYUS76 X-MailFrom: arthur@aheymans.xyz X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-seabios.seabios.org-0; header-match-seabios.seabios.org-1; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.4b1 Precedence: list Subject: [SeaBIOS] [PATCH] fw/coreboot.c: Use coreboot table to find cbfs List-Id: SeaBIOS mailing list Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Content-Transfer-Encoding: quoted-printable Authentication-Results: coreboot.org; auth=pass smtp.auth=mailman@coreboot.org smtp.mailfrom=seabios-bounces@seabios.org X-Spamd-Bar: -- X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" The "cbfs master header" cbfs file is considered a legacy feature in coreboot and is planned for removal in the master branch. Since 2015 the coreboot tables have exported info about the active cbfs. This change uses the cbfs information in the coreboot tables instead of following the cbfs master header pointer in the bootblock to find cbfs. This change makes it possible to access CBFS fmap regions that don't feature a "cbfs master header", which is the case with Googles VBOOT solution. This breaks compatibility with very old coreboot build (build before fb5d5b16 "2015-07-14, cbtable: describe boot media"). Keeping backward compatibility with the "cbfs master header" would complicate the code. Signed-off-by: Arthur Heymans diff --git a/src/Kconfig b/src/Kconfig index 3a8ffa1..51ba827 100644 --- a/src/Kconfig +++ b/src/Kconfig @@ -93,15 +93,6 @@ endchoice help Support CBFS files compressed using the lzma decompression algorithm. - config CBFS_LOCATION - depends on COREBOOT_FLASH - hex "CBFS memory end location" - default 0 - help - Memory address of where the CBFS data ends. This should - be zero for normal builds. It may be a non-zero value if - the CBFS filesystem is at a non-standard location (eg, - 0xffe00000 if CBFS ends 2Meg below the end of flash). =20 config MULTIBOOT depends on COREBOOT diff --git a/src/fw/coreboot.c b/src/fw/coreboot.c index 7c0954b..8a35c1d 100644 --- a/src/fw/coreboot.c +++ b/src/fw/coreboot.c @@ -88,6 +88,18 @@ struct cbmem_console { #define CBMC_OVERFLOW (1 << 31) static struct cbmem_console *cbcon =3D NULL; =20 +#define CB_TAG_BOOT_MEDIA_PARAMS 0x30 + +struct cb_boot_media_params { + u32 tag; + u32 size; + /* offsets are relative to start of boot media */ + u64 fmap_offset; + u64 cbfs_offset; + u64 cbfs_size; + u64 boot_media_size; +}; + static u16 ipchksum(char *buf, int count) { @@ -146,7 +158,12 @@ find_cb_subtable(struct cb_header *cbh, u32 tag) struct cb_header * find_cb_table(void) { - struct cb_header *cbh =3D find_cb_header(0, 0x1000); + static struct cb_header *cbh; + + if (cbh) + return cbh; + + cbh=3D find_cb_header(0, 0x1000); if (!cbh) return NULL; struct cb_forward *cbf =3D find_cb_subtable(cbh, CB_TAG_FORWARD); @@ -317,20 +334,8 @@ ulzma(u8 *dst, u32 maxlen, const u8 *src, u32 srclen) * Coreboot flash format ****************************************************************/ =20 -#define CBFS_HEADER_MAGIC 0x4F524243 -#define CBFS_VERSION1 0x31313131 - -struct cbfs_header { - u32 magic; - u32 version; - u32 romsize; - u32 bootblocksize; - u32 align; - u32 offset; - u32 pad[2]; -} PACKED; - #define CBFS_FILE_MAGIC 0x455649484352414cLL // LARCHIVE +#define CBFS_ALIGNMENT 64 =20 struct cbfs_file { u64 magic; @@ -429,30 +434,50 @@ coreboot_cbfs_init(void) if (!CONFIG_COREBOOT_FLASH) return; =20 - struct cbfs_header *hdr =3D *(void **)(CONFIG_CBFS_LOCATION - 4); - if ((u32)hdr & 0x03) { - dprintf(1, "Invalid CBFS pointer %p\n", hdr); + dprintf(3, "Attempting to initialize coreboot cbfs\n"); + + struct cb_header *cbh =3D find_cb_table(); + if (!cbh) { + dprintf(1, "cbfs_init: unable to find cb table\n"); return; } - if (CONFIG_CBFS_LOCATION && (u32)hdr > CONFIG_CBFS_LOCATION) - // Looks like the pointer is relative to CONFIG_CBFS_LOCATION - hdr =3D (void*)hdr + CONFIG_CBFS_LOCATION; - if (hdr->magic !=3D cpu_to_be32(CBFS_HEADER_MAGIC)) { - dprintf(1, "Unable to find CBFS (ptr=3D%p; got %x not %x)\n" - , hdr, hdr->magic, cpu_to_be32(CBFS_HEADER_MAGIC)); + + struct cb_boot_media_params *cbbmp =3D + find_cb_subtable(cbh, CB_TAG_BOOT_MEDIA_PARAMS); + + if (!cbbmp) { + dprintf(1, "cbfs_init: unable to find boot media params\n"); return; } - dprintf(1, "Found CBFS header at %p\n", hdr); =20 - u32 romsize =3D be32_to_cpu(hdr->romsize); - u32 romstart =3D CONFIG_CBFS_LOCATION - romsize; - struct cbfs_file *fhdr =3D (void*)romstart + be32_to_cpu(hdr->offset); + const u32 romsize =3D cbbmp->boot_media_size; + const u32 cbfs_start =3D cbbmp->cbfs_offset - romsize; + const u32 cbfs_end =3D cbfs_start + cbbmp->cbfs_size - 1; + + dprintf(3, "cbfs_init: cbfs_start=3D0x%08x, cbfs_end=3D0x%08x\n", cbfs= _start, + cbfs_end); + + u32 offset =3D cbfs_start; + for (;;) { - if ((u32)fhdr - romstart > romsize) - break; - u64 magic =3D fhdr->magic; - if (magic !=3D CBFS_FILE_MAGIC) + if (offset > cbfs_end || offset < cbfs_start) break; + + struct cbfs_file *fhdr =3D (void*)offset; + + if (fhdr->magic !=3D CBFS_FILE_MAGIC) { + offset++; + offset =3D ALIGN(offset, CBFS_ALIGNMENT); + continue; + } + + /* Skip empty space */ + if (strcmp(fhdr->filename, "") =3D=3D 0) { + offset +=3D ALIGN(be32_to_cpu(fhdr->offset) + be32_to_cpu(fhdr= ->len) + , CBFS_ALIGNMENT); + continue; + } + struct cbfs_romfile_s *cfile =3D malloc_tmp(sizeof(*cfile)); if (!cfile) { warn_noalloc(); @@ -473,8 +498,8 @@ coreboot_cbfs_init(void) } romfile_add(&cfile->file); =20 - fhdr =3D (void*)ALIGN((u32)cfile->data + cfile->rawsize - , be32_to_cpu(hdr->align)); + offset =3D ALIGN((u32)cfile->data + cfile->rawsize + , CBFS_ALIGNMENT); } =20 process_links_file(); --=20 2.30.2 _______________________________________________ SeaBIOS mailing list -- seabios@seabios.org To unsubscribe send an email to seabios-leave@seabios.org