Hello Aaron Durbin,
I'd like you to do a code review. Please visit
https://review.coreboot.org/c/coreboot/+/38422
to review the following change.
Change subject: cbfs: Hook up to new CBFS implmentation ......................................................................
cbfs: Hook up to new CBFS implmentation
This patch hooks coreboot up to the new commonlib/bsd CBFS implementation. This is intended as the "minimum viable patch" that makes the new implementation useable with the smallest amount of changes -- that is why some of this may look a bit roundabout (returning the whole metadata for a file but then just using that to fill out the rdevs of the existing struct cbfsf). Future changes will migrate the higher level CBFS APIs one-by-one to use the new implementation directly (rather than translated into the results of the old one), at which point this will become more efficient.
Change-Id: I4d112d1239475920de2d872dac179c245275038d Signed-off-by: Julius Werner jwerner@chromium.org --- M src/commonlib/Makefile.inc A src/include/cbfs_glue.h M src/lib/cbfs.c 3 files changed, 63 insertions(+), 25 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/22/38422/1
diff --git a/src/commonlib/Makefile.inc b/src/commonlib/Makefile.inc index 5bd6cf9..b2225cb 100644 --- a/src/commonlib/Makefile.inc +++ b/src/commonlib/Makefile.inc @@ -30,6 +30,13 @@ smm-y += cbfs.c postcar-y += cbfs.c
+bootblock-y += bsd/cbfs_private.c +verstage-y += bsd/cbfs_private.c +romstage-y += bsd/cbfs_private.c +postcar-y += bsd/cbfs_private.c +ramstage-y += bsd/cbfs_private.c +smm-y += bsd/cbfs_private.c + decompressor-y += bsd/lz4_wrapper.c bootblock-y += bsd/lz4_wrapper.c verstage-y += bsd/lz4_wrapper.c diff --git a/src/include/cbfs_glue.h b/src/include/cbfs_glue.h new file mode 100644 index 0000000..10f4187 --- /dev/null +++ b/src/include/cbfs_glue.h @@ -0,0 +1,31 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +#ifndef _CBFS_GLUE_H_ +#define _CBFS_GLUE_H_ + +#include <commonlib/region.h> +#include <console/console.h> + +#define ENABLE_HASHING 0 + +#define ERROR(...) printk(BIOS_ERR, "CBFS ERROR: " __VA_ARGS__) +#define LOG(...) printk(BIOS_ERR, "CBFS: " __VA_ARGS__) +#if CONFIG(DEBUG_CBFS) +#define DEBUG(...) printk(BIOS_SPEW, "CBFS DEBUG: " __VA_ARGS__) +#else +#define DEBUG(...) +#endif + +typedef const struct region_device *cbfs_dev_t; + +static inline ssize_t cbfs_dev_read(cbfs_dev_t dev, void *buffer, size_t offset, size_t size) +{ + return rdev_readat(dev, buffer, offset, size); +} + +static inline size_t cbfs_dev_size(cbfs_dev_t dev) +{ + return region_device_sz(dev); +} + +#endif /* _CBFS_GLUE_H_ */ diff --git a/src/lib/cbfs.c b/src/lib/cbfs.c index c712f76..d6fb99c 100644 --- a/src/lib/cbfs.c +++ b/src/lib/cbfs.c @@ -20,6 +20,7 @@ #include <stdlib.h> #include <boot_device.h> #include <cbfs.h> +#include <commonlib/bsd/cbfs_private.h> #include <commonlib/bsd/compression.h> #include <endian.h> #include <lib.h> @@ -29,14 +30,6 @@ #include <security/vboot/vboot_crtm.h> #include <security/vboot/vboot_common.h>
-#define ERROR(x...) printk(BIOS_ERR, "CBFS: " x) -#define LOG(x...) printk(BIOS_INFO, "CBFS: " x) -#if CONFIG(DEBUG_CBFS) -#define DEBUG(x...) printk(BIOS_SPEW, "CBFS: " x) -#else -#define DEBUG(x...) -#endif - int cbfs_boot_locate(struct cbfsf *fh, const char *name, uint32_t *type) { struct region_device rdev; @@ -44,28 +37,35 @@ if (cbfs_boot_region_device(&rdev)) return -1;
- int ret = cbfs_locate(fh, &rdev, name, type); + union cbfs_mdata mdata; + size_t data_offset; + cb_err_t err = cbfs_lookup(&rdev, name, &mdata, &data_offset, NULL);
- if (CONFIG(VBOOT_ENABLE_CBFS_FALLBACK) && ret) { + if (CONFIG(VBOOT_ENABLE_CBFS_FALLBACK) && err == CB_CBFS_NOT_FOUND) { + printk(BIOS_INFO, "CBFS: Fall back to RO region for %s\n", + name); + if (fmap_locate_area_as_rdev("COREBOOT", &rdev)) + return -1; + err = cbfs_lookup(&rdev, name, &mdata, &data_offset, NULL); + } + if (err) + return -1;
- /* - * When VBOOT_ENABLE_CBFS_FALLBACK is enabled and a file is not available in the - * active RW region, the RO (COREBOOT) region will be used to locate the file. - * - * This functionality makes it possible to avoid duplicate files in the RO - * and RW partitions while maintaining updateability. - * - * Files can be added to the RO_REGION_ONLY config option to use this feature. - */ - printk(BIOS_DEBUG, "Fall back to RO region for %s\n", name); - ret = cbfs_locate_file_in_region(fh, "COREBOOT", name, type); + size_t msize = be32toh(mdata.h.offset); + if (rdev_chain(&fh->metadata, &rdev, data_offset - msize, msize) || + rdev_chain(&fh->data, &rdev, data_offset, be32toh(mdata.h.len))) + return -1; + if (type) { + if (!*type) + *type = be32toh(mdata.h.type); + else if (*type != be32toh(mdata.h.type)) + return -1; }
- if (!ret) - if (vboot_measure_cbfs_hook(fh, name)) - return -1; + if (vboot_measure_cbfs_hook(fh, name)) + return -1;
- return ret; + return 0; }
void *cbfs_boot_map_with_leak(const char *name, uint32_t type, size_t *size)
Aaron Durbin has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/38422 )
Change subject: cbfs: Hook up to new CBFS implmentation ......................................................................
Patch Set 4:
(1 comment)
https://review.coreboot.org/c/coreboot/+/38422/4/src/lib/cbfs.c File src/lib/cbfs.c:
https://review.coreboot.org/c/coreboot/+/38422/4/src/lib/cbfs.c@62 PS4, Line 62: return -1; Is this to handle that weird case that Ron added in https://review.coreboot.org/26279 ? I don't think that should have landed in practice. Comment for this function still indicates:
/* Locate file by name and optional type. Return 0 on success. < 0 on error. */
I think we should nuke this.
Julius Werner has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/38422 )
Change subject: cbfs: Hook up to new CBFS implmentation ......................................................................
Patch Set 4:
(1 comment)
https://review.coreboot.org/c/coreboot/+/38422/4/src/lib/cbfs.c File src/lib/cbfs.c:
https://review.coreboot.org/c/coreboot/+/38422/4/src/lib/cbfs.c@62 PS4, Line 62: return -1;
Is this to handle that weird case that Ron added in https://review.coreboot. […]
I just copied the existing behavior. Long term I'd prefer to just remove the whole 'type' argument from all these APIs, because I don't think they add anything (the filename already uniquely identifies a file). Callers should be able to explicitly figure out the type if they want to but I don't think they should be forced to pass it for every CBFS access.
For this patch I'd prefer to not change behavior of the API to not conflate any issues arising from that with the rest of the patch. I'm planning to further refactor these APIs later and will then probably remove the type argument completely.
Hello Aaron Durbin, build bot (Jenkins), Patrick Georgi, Martin Roth,
I'd like you to reexamine a change. Please visit
https://review.coreboot.org/c/coreboot/+/38422
to look at the new patch set (#5).
Change subject: cbfs: Hook up to new CBFS implmentation ......................................................................
cbfs: Hook up to new CBFS implmentation
This patch hooks coreboot up to the new commonlib/bsd CBFS implementation. This is intended as the "minimum viable patch" that makes the new implementation useable with the smallest amount of changes -- that is why some of this may look a bit roundabout (returning the whole metadata for a file but then just using that to fill out the rdevs of the existing struct cbfsf). Future changes will migrate the higher level CBFS APIs one-by-one to use the new implementation directly (rather than translated into the results of the old one), at which point this will become more efficient.
Change-Id: I4d112d1239475920de2d872dac179c245275038d Signed-off-by: Julius Werner jwerner@chromium.org --- M src/commonlib/Makefile.inc A src/include/cbfs_glue.h M src/lib/cbfs.c 3 files changed, 63 insertions(+), 25 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/22/38422/5
Hello build bot (Jenkins), Patrick Georgi, Martin Roth, Aaron Durbin,
I'd like you to reexamine a change. Please visit
https://review.coreboot.org/c/coreboot/+/38422
to look at the new patch set (#8).
Change subject: cbfs: Hook up to new CBFS implementation ......................................................................
cbfs: Hook up to new CBFS implementation
This patch hooks coreboot up to the new commonlib/bsd CBFS implementation. This is intended as the "minimum viable patch" that makes the new implementation useable with the smallest amount of changes -- that is why some of this may look a bit roundabout (returning the whole metadata for a file but then just using that to fill out the rdevs of the existing struct cbfsf). Future changes will migrate the higher level CBFS APIs one-by-one to use the new implementation directly (rather than translated into the results of the old one), at which point this will become more efficient.
Change-Id: I4d112d1239475920de2d872dac179c245275038d Signed-off-by: Julius Werner jwerner@chromium.org --- M src/commonlib/Makefile.inc A src/include/cbfs_glue.h M src/lib/cbfs.c 3 files changed, 63 insertions(+), 25 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/22/38422/8
Patrick Rudolph has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/38422 )
Change subject: cbfs: Hook up to new CBFS implementation ......................................................................
Patch Set 9: Code-Review+1
Hello build bot (Jenkins), Patrick Georgi, Martin Roth, Patrick Rudolph, Aaron Durbin,
I'd like you to reexamine a change. Please visit
https://review.coreboot.org/c/coreboot/+/38422
to look at the new patch set (#10).
Change subject: cbfs: Hook up to new CBFS implementation ......................................................................
cbfs: Hook up to new CBFS implementation
This patch hooks coreboot up to the new commonlib/bsd CBFS implementation. This is intended as the "minimum viable patch" that makes the new implementation useable with the smallest amount of changes -- that is why some of this may look a bit roundabout (returning the whole metadata for a file but then just using that to fill out the rdevs of the existing struct cbfsf). Future changes will migrate the higher level CBFS APIs one-by-one to use the new implementation directly (rather than translated into the results of the old one), at which point this will become more efficient.
Change-Id: I4d112d1239475920de2d872dac179c245275038d Signed-off-by: Julius Werner jwerner@chromium.org --- M src/commonlib/Makefile.inc A src/include/cbfs_glue.h M src/lib/cbfs.c 3 files changed, 63 insertions(+), 28 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/22/38422/10
HAOUAS Elyes has uploaded a new patch set (#11) to the change originally created by Julius Werner. ( https://review.coreboot.org/c/coreboot/+/38422 )
Change subject: cbfs: Hook up to new CBFS implementation ......................................................................
cbfs: Hook up to new CBFS implementation
This patch hooks coreboot up to the new commonlib/bsd CBFS implementation. This is intended as the "minimum viable patch" that makes the new implementation useable with the smallest amount of changes -- that is why some of this may look a bit roundabout (returning the whole metadata for a file but then just using that to fill out the rdevs of the existing struct cbfsf). Future changes will migrate the higher level CBFS APIs one-by-one to use the new implementation directly (rather than translated into the results of the old one), at which point this will become more efficient.
Change-Id: I4d112d1239475920de2d872dac179c245275038d Signed-off-by: Julius Werner jwerner@chromium.org --- M src/commonlib/Makefile.inc A src/include/cbfs_glue.h M src/lib/cbfs.c 3 files changed, 63 insertions(+), 23 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/22/38422/11
HAOUAS Elyes has uploaded a new patch set (#12) to the change originally created by Julius Werner. ( https://review.coreboot.org/c/coreboot/+/38422 )
Change subject: cbfs: Hook up to new CBFS implementation ......................................................................
cbfs: Hook up to new CBFS implementation
This patch hooks coreboot up to the new commonlib/bsd CBFS implementation. This is intended as the "minimum viable patch" that makes the new implementation useable with the smallest amount of changes -- that is why some of this may look a bit roundabout (returning the whole metadata for a file but then just using that to fill out the rdevs of the existing struct cbfsf). Future changes will migrate the higher level CBFS APIs one-by-one to use the new implementation directly (rather than translated into the results of the old one), at which point this will become more efficient.
Change-Id: I4d112d1239475920de2d872dac179c245275038d Signed-off-by: Julius Werner jwerner@chromium.org --- M src/commonlib/Makefile.inc A src/include/cbfs_glue.h M src/lib/cbfs.c 3 files changed, 63 insertions(+), 28 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/22/38422/12
Julius Werner has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/38422 )
Change subject: cbfs: Hook up to new CBFS implementation ......................................................................
Patch Set 12:
Was this intentional, Elyes? The patches you uploaded on top of this don't seem to touch any of the same files, so you probably wanted to upload them independently instead? (Note, if you do want to upload something dependent on someone else's patches without rewriting them like this, the trick is to make sure the patch you're based on in your local repository is the exact same SHA as the last one currently uploaded on Gerrit (the SHA listed at the top of the "Files" section). You can use git rebase --onto <copy&paste that SHA> to get your local branch into the right state.)
HAOUAS Elyes has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/38422 )
Change subject: cbfs: Hook up to new CBFS implementation ......................................................................
Patch Set 12:
Patch Set 12:
Was this intentional, Elyes? The patches you uploaded on top of this don't seem to touch any of the same files, so you probably wanted to upload them independently instead? (Note, if you do want to upload something dependent on someone else's patches without rewriting them like this, the trick is to make sure the patch you're based on in your local repository is the exact same SHA as the last one currently uploaded on Gerrit (the SHA listed at the top of the "Files" section). You can use git rebase --onto <copy&paste that SHA> to get your local branch into the right state.)
No it wasn't. I've rebased current patch (see patch set 11) on CB:41781 in my local and pushed it accidentally. Sorry for that, Then I've restored your patch.
Thank you for git & SHA trick. It will go faster than what I usually do (git checkout && git rebase).
HAOUAS Elyes has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/38422 )
Change subject: cbfs: Hook up to new CBFS implementation ......................................................................
Patch Set 12:
is it still active, or can we merge 41781 ?
Julius Werner has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/38422 )
Change subject: cbfs: Hook up to new CBFS implementation ......................................................................
Patch Set 12:
is it still active, or can we merge 41781 ?
Still waiting on the next review cycle from adurbin@...
Aaron Durbin has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/38422 )
Change subject: cbfs: Hook up to new CBFS implementation ......................................................................
Patch Set 12: Code-Review+2
Hello build bot (Jenkins), Patrick Georgi, Martin Roth, Patrick Rudolph, Aaron Durbin, HAOUAS Elyes,
I'd like you to reexamine a change. Please visit
https://review.coreboot.org/c/coreboot/+/38422
to look at the new patch set (#15).
Change subject: cbfs: Hook up to new CBFS implementation ......................................................................
cbfs: Hook up to new CBFS implementation
This patch hooks coreboot up to the new commonlib/bsd CBFS implementation. This is intended as the "minimum viable patch" that makes the new implementation useable with the smallest amount of changes -- that is why some of this may look a bit roundabout (returning the whole metadata for a file but then just using that to fill out the rdevs of the existing struct cbfsf). Future changes will migrate the higher level CBFS APIs one-by-one to use the new implementation directly (rather than translated into the results of the old one), at which point this will become more efficient.
Change-Id: I4d112d1239475920de2d872dac179c245275038d Signed-off-by: Julius Werner jwerner@chromium.org --- M src/commonlib/Makefile.inc M src/commonlib/cbfs.c M src/commonlib/include/commonlib/cbfs.h A src/include/cbfs_glue.h M src/lib/cbfs.c 5 files changed, 64 insertions(+), 44 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/22/38422/15
Aaron Durbin has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/38422 )
Change subject: cbfs: Hook up to new CBFS implementation ......................................................................
Patch Set 17: Code-Review+2
(1 comment)
https://review.coreboot.org/c/coreboot/+/38422/17/src/lib/cbfs.c File src/lib/cbfs.c:
https://review.coreboot.org/c/coreboot/+/38422/17/src/lib/cbfs.c@41 PS17, Line 41: (uintptr_t)&fh->mdata, msize) || Did you happen to see any users assuming metadata was chained to boot_device ?
Julius Werner has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/38422 )
Change subject: cbfs: Hook up to new CBFS implementation ......................................................................
Patch Set 17:
(1 comment)
https://review.coreboot.org/c/coreboot/+/38422/17/src/lib/cbfs.c File src/lib/cbfs.c:
https://review.coreboot.org/c/coreboot/+/38422/17/src/lib/cbfs.c@41 PS17, Line 41: (uintptr_t)&fh->mdata, msize) ||
Did you happen to see any users assuming metadata was chained to boot_device ?
No. Nothing outside of commonlib/cbfs.c ever really touches the metadata directly.
Julius Werner has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/38422 )
Change subject: cbfs: Hook up to new CBFS implementation ......................................................................
Patch Set 17:
(1 comment)
https://review.coreboot.org/c/coreboot/+/38422/4/src/lib/cbfs.c File src/lib/cbfs.c:
https://review.coreboot.org/c/coreboot/+/38422/4/src/lib/cbfs.c@62 PS4, Line 62: return -1;
I just copied the existing behavior. […]
Resolved?
Aaron Durbin has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/38422 )
Change subject: cbfs: Hook up to new CBFS implementation ......................................................................
Patch Set 17:
(1 comment)
https://review.coreboot.org/c/coreboot/+/38422/4/src/lib/cbfs.c File src/lib/cbfs.c:
https://review.coreboot.org/c/coreboot/+/38422/4/src/lib/cbfs.c@62 PS4, Line 62: return -1;
Resolved?
yes
Philipp Deppenwiese has submitted this change. ( https://review.coreboot.org/c/coreboot/+/38422 )
Change subject: cbfs: Hook up to new CBFS implementation ......................................................................
cbfs: Hook up to new CBFS implementation
This patch hooks coreboot up to the new commonlib/bsd CBFS implementation. This is intended as the "minimum viable patch" that makes the new implementation useable with the smallest amount of changes -- that is why some of this may look a bit roundabout (returning the whole metadata for a file but then just using that to fill out the rdevs of the existing struct cbfsf). Future changes will migrate the higher level CBFS APIs one-by-one to use the new implementation directly (rather than translated into the results of the old one), at which point this will become more efficient.
Change-Id: I4d112d1239475920de2d872dac179c245275038d Signed-off-by: Julius Werner jwerner@chromium.org Reviewed-on: https://review.coreboot.org/c/coreboot/+/38422 Reviewed-by: Aaron Durbin adurbin@chromium.org Tested-by: build bot (Jenkins) no-reply@coreboot.org --- M src/commonlib/Makefile.inc M src/commonlib/cbfs.c M src/commonlib/include/commonlib/cbfs.h A src/include/cbfs_glue.h M src/lib/cbfs.c 5 files changed, 64 insertions(+), 44 deletions(-)
Approvals: build bot (Jenkins): Verified Aaron Durbin: Looks good to me, approved
diff --git a/src/commonlib/Makefile.inc b/src/commonlib/Makefile.inc index 5bd6cf9..b2225cb 100644 --- a/src/commonlib/Makefile.inc +++ b/src/commonlib/Makefile.inc @@ -30,6 +30,13 @@ smm-y += cbfs.c postcar-y += cbfs.c
+bootblock-y += bsd/cbfs_private.c +verstage-y += bsd/cbfs_private.c +romstage-y += bsd/cbfs_private.c +postcar-y += bsd/cbfs_private.c +ramstage-y += bsd/cbfs_private.c +smm-y += bsd/cbfs_private.c + decompressor-y += bsd/lz4_wrapper.c bootblock-y += bsd/lz4_wrapper.c verstage-y += bsd/lz4_wrapper.c diff --git a/src/commonlib/cbfs.c b/src/commonlib/cbfs.c index 115f99a..999c35e 100644 --- a/src/commonlib/cbfs.c +++ b/src/commonlib/cbfs.c @@ -7,21 +7,6 @@ #include <string.h> #include <vb2_sha.h>
-#if !defined(LOG) -#define LOG(x...) printk(BIOS_INFO, "CBFS: " x) -#endif -#if defined(CONFIG) - -#if CONFIG(DEBUG_CBFS) -#define DEBUG(x...) printk(BIOS_SPEW, "CBFS: " x) -#else -#define DEBUG(x...) -#endif - -#elif !defined(DEBUG) -#define DEBUG(x...) -#endif - static size_t cbfs_next_offset(const struct region_device *cbfs, const struct cbfsf *f) { diff --git a/src/commonlib/include/commonlib/cbfs.h b/src/commonlib/include/commonlib/cbfs.h index 90aa0b2..6565c1d 100644 --- a/src/commonlib/include/commonlib/cbfs.h +++ b/src/commonlib/include/commonlib/cbfs.h @@ -3,7 +3,7 @@ #ifndef _COMMONLIB_CBFS_H_ #define _COMMONLIB_CBFS_H_
-#include <commonlib/bsd/cbfs_serialized.h> +#include <commonlib/bsd/cbfs_private.h> #include <commonlib/region.h> #include <vb2_api.h>
@@ -11,6 +11,7 @@ struct cbfsf { struct region_device metadata; struct region_device data; + union cbfs_mdata mdata; };
/* Locate file by name and optional type. Returns 0 on success else < 0 on diff --git a/src/include/cbfs_glue.h b/src/include/cbfs_glue.h new file mode 100644 index 0000000..ebfbc2e --- /dev/null +++ b/src/include/cbfs_glue.h @@ -0,0 +1,30 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +#ifndef _CBFS_GLUE_H_ +#define _CBFS_GLUE_H_ + +#include <commonlib/region.h> +#include <console/console.h> + +#define CBFS_ENABLE_HASHING 0 + +#define ERROR(...) printk(BIOS_ERR, "CBFS ERROR: " __VA_ARGS__) +#define LOG(...) printk(BIOS_ERR, "CBFS: " __VA_ARGS__) +#define DEBUG(...) do { \ + if (CONFIG(DEBUG_CBFS)) \ + printk(BIOS_SPEW, "CBFS DEBUG: " __VA_ARGS__); \ +} while (0) + +typedef const struct region_device *cbfs_dev_t; + +static inline ssize_t cbfs_dev_read(cbfs_dev_t dev, void *buffer, size_t offset, size_t size) +{ + return rdev_readat(dev, buffer, offset, size); +} + +static inline size_t cbfs_dev_size(cbfs_dev_t dev) +{ + return region_device_sz(dev); +} + +#endif /* _CBFS_GLUE_H_ */ diff --git a/src/lib/cbfs.c b/src/lib/cbfs.c index 35193d0..447d91f 100644 --- a/src/lib/cbfs.c +++ b/src/lib/cbfs.c @@ -3,6 +3,7 @@ #include <assert.h> #include <boot_device.h> #include <cbfs.h> +#include <commonlib/bsd/cbfs_private.h> #include <commonlib/bsd/compression.h> #include <commonlib/endian.h> #include <console/console.h> @@ -15,14 +16,6 @@ #include <symbols.h> #include <timestamp.h>
-#define ERROR(x...) printk(BIOS_ERR, "CBFS: " x) -#define LOG(x...) printk(BIOS_INFO, "CBFS: " x) -#if CONFIG(DEBUG_CBFS) -#define DEBUG(x...) printk(BIOS_SPEW, "CBFS: " x) -#else -#define DEBUG(x...) -#endif - int cbfs_boot_locate(struct cbfsf *fh, const char *name, uint32_t *type) { struct region_device rdev; @@ -30,31 +23,35 @@ if (cbfs_boot_region_device(&rdev)) return -1;
- int ret = cbfs_locate(fh, &rdev, name, type); + size_t data_offset; + cb_err_t err = cbfs_lookup(&rdev, name, &fh->mdata, &data_offset, NULL);
- if (CONFIG(VBOOT_ENABLE_CBFS_FALLBACK) && ret) { - - /* - * When VBOOT_ENABLE_CBFS_FALLBACK is enabled and a file is not available in the - * active RW region, the RO (COREBOOT) region will be used to locate the file. - * - * This functionality makes it possible to avoid duplicate files in the RO - * and RW partitions while maintaining updateability. - * - * Files can be added to the RO_REGION_ONLY config option to use this feature. - */ - printk(BIOS_DEBUG, "Fall back to RO region for %s\n", name); + if (CONFIG(VBOOT_ENABLE_CBFS_FALLBACK) && err == CB_CBFS_NOT_FOUND) { + printk(BIOS_INFO, "CBFS: Fall back to RO region for %s\n", + name); if (fmap_locate_area_as_rdev("COREBOOT", &rdev)) - ERROR("RO region not found\n"); - else - ret = cbfs_locate(fh, &rdev, name, type); + return -1; + err = cbfs_lookup(&rdev, name, &fh->mdata, &data_offset, NULL); + } + if (err) + return -1; + + size_t msize = be32toh(fh->mdata.h.offset); + if (rdev_chain(&fh->metadata, &addrspace_32bit.rdev, + (uintptr_t)&fh->mdata, msize) || + rdev_chain(&fh->data, &rdev, data_offset, be32toh(fh->mdata.h.len))) + return -1; + if (type) { + if (!*type) + *type = be32toh(fh->mdata.h.type); + else if (*type != be32toh(fh->mdata.h.type)) + return -1; }
- if (!ret) - if (tspi_measure_cbfs_hook(fh, name)) - return -1; + if (tspi_measure_cbfs_hook(fh, name)) + return -1;
- return ret; + return 0; }
void *cbfs_boot_map_with_leak(const char *name, uint32_t type, size_t *size)