Attention is currently required from: Edward O'Callaghan.
Nikolai Artemiev has posted comments on this change. ( https://review.coreboot.org/c/flashrom/+/70517 )
Change subject: flashrom: Check for flash access restricitons erase path
......................................................................
Patch Set 1:
(1 comment)
Commit Message:
https://review.coreboot.org/c/flashrom/+/70517/comment/f3e5f60a_b42bcfce
PS1, Line 11: will not erase anythin
This isn't implemented yet. We will need to iterate regions and check for any protected regions before we start writing so we can bail out before we change anythibng.
--
To view, visit https://review.coreboot.org/c/flashrom/+/70517
To unsubscribe, or for help writing mail filters, visit https://review.coreboot.org/settings
Gerrit-Project: flashrom
Gerrit-Branch: master
Gerrit-Change-Id: If027a96a024782c7707c6d38680709a1a117f3ef
Gerrit-Change-Number: 70517
Gerrit-PatchSet: 1
Gerrit-Owner: Nikolai Artemiev <nartemiev(a)google.com>
Gerrit-Reviewer: Edward O'Callaghan <quasisec(a)chromium.org>
Gerrit-Attention: Edward O'Callaghan <quasisec(a)chromium.org>
Gerrit-Comment-Date: Fri, 09 Dec 2022 04:43:10 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Gerrit-MessageType: comment
Attention is currently required from: Edward O'Callaghan.
Hello Edward O'Callaghan,
I'd like you to do a code review.
Please visit
https://review.coreboot.org/c/flashrom/+/70515
to review the following change.
Change subject: flashrom: Check for flash access restricitons in verify_range()
......................................................................
flashrom: Check for flash access restricitons in verify_range()
Make verify_flash() skip read/write-protected regions based on the
FLASHROM_FLAG_SKIP_UNREADABLE and FLASHROM_FLAG_SKIP_UNWRITABLE flags.
If FLASHROM_FLAG_SKIP_UNREADABLE is false, read-protected regions will cause
verification to fail.
If FLASHROM_FLAG_SKIP_UNWRITABLE is false, read-only regions will still
be verified and any mismatch will cause verification to fail. It can be
useful to set the flag to true so that expected mismatches in read-only
regions are ignored by verify_range() after flashing.
BUG=b:260440773
BRANCH=none
TEST=flashrom -v on dedede (JSL)
Change-Id: I61dfadd3c75365f2e55abeea75f673ab791ca5cc
CoAuthored-by: Edward O'Callaghan <quasisec(a)google.com>
Signed-off-by: Edward O'Callaghan <quasisec(a)google.com>
Signed-off-by: Nikolai Artemiev <nartemiev(a)google.com>
---
M flashrom.c
1 file changed, 68 insertions(+), 7 deletions(-)
git pull ssh://review.coreboot.org:29418/flashrom refs/changes/15/70515/1
diff --git a/flashrom.c b/flashrom.c
index 19068a7..76a2801 100644
--- a/flashrom.c
+++ b/flashrom.c
@@ -582,15 +582,49 @@
return -1;
}
- int ret = read_flash(flash, readbuf, start, len);
- if (ret) {
- msg_gerr("Verification impossible because read failed "
- "at 0x%x (len 0x%x)\n", start, len);
- ret = -1;
- goto out_free;
+ int ret = 0;
+
+ msg_gdbg("%#06x..%#06x ", start, start + len - 1);
+
+ unsigned int read_len;
+ for (size_t addr = start; addr < start + len; addr += read_len) {
+ struct flash_region region;
+ get_flash_region(flash, addr, ®ion);
+ read_len = min(start + len, region.end) - addr;
+
+ if ((region.write_prot && flash->flags.skip_unwritable_regions) ||
+ (region.read_prot && flash->flags.skip_unreadable_regions)) {
+ msg_gdbg("%s: Skipping verification of %s region (%#08x..%#08x)\n",
+ __func__, region.name, region.start, region.end - 1);
+ free(region.name);
+ continue;
+ }
+
+ if (region.read_prot) {
+ msg_gerr("%s: Verification imposible because %s region (%#08x..%#08x) is unreadable.\n",
+ __func__, region.name, region.start, region.end - 1);
+ free(region.name);
+ goto out_free;
+ }
+
+ msg_gdbg("%s: Verifying %s region (%#08x..%#08x)\n",
+ __func__, region.name, region.start, region.end - 1);
+ free(region.name);
+
+ ret = read_flash(flash, readbuf, addr, read_len);
+ if (ret) {
+ msg_gerr("Verification impossible because read failed "
+ "at 0x%x (len 0x%x)\n", start, len);
+ ret = -1;
+ goto out_free;
+ }
+
+ ret = compare_range(cmpbuf + (addr - start), readbuf, addr, read_len);
+ if (ret)
+ goto out_free;
+
}
- ret = compare_range(cmpbuf, readbuf, start, len);
out_free:
free(readbuf);
return ret;
--
To view, visit https://review.coreboot.org/c/flashrom/+/70515
To unsubscribe, or for help writing mail filters, visit https://review.coreboot.org/settings
Gerrit-Project: flashrom
Gerrit-Branch: master
Gerrit-Change-Id: I61dfadd3c75365f2e55abeea75f673ab791ca5cc
Gerrit-Change-Number: 70515
Gerrit-PatchSet: 1
Gerrit-Owner: Nikolai Artemiev <nartemiev(a)google.com>
Gerrit-Reviewer: Edward O'Callaghan <quasisec(a)chromium.org>
Gerrit-Attention: Edward O'Callaghan <quasisec(a)chromium.org>
Gerrit-MessageType: newchange
Attention is currently required from: Edward O'Callaghan, Angel Pons, Nikolai Artemiev.
Hello build bot (Jenkins), Edward O'Callaghan,
I'd like you to reexamine a change. Please visit
https://review.coreboot.org/c/flashrom/+/70128
to look at the new patch set (#21).
Change subject: libflashrom: Add flags to skup unreadable and unwritable regions
......................................................................
libflashrom: Add flags to skup unreadable and unwritable regions
Add flags to allow libflashrom users to configure how operations that
include unreadable or unwritable regions should be behave.
If the flags are set to true, a read/write operation will just skip the
inaccessible region and will still be executed in other regions.
If the flags are set to false, the inaccessible region will cause the
entire operation to fail.
BUG=b:260440773
BRANCH=none
TEST=builds
Change-Id: I9b96fb04b863625d2c9f9a00b97c35b3ddb0871b
CoAuthored-by: Edward O'Callaghan <quasisec(a)google.com>
Signed-off-by: Edward O'Callaghan <quasisec(a)google.com>
Signed-off-by: Nikolai Artemiev <nartemiev(a)google.com>
---
M include/flash.h
M include/libflashrom.h
M libflashrom.c
3 files changed, 42 insertions(+), 9 deletions(-)
git pull ssh://review.coreboot.org:29418/flashrom refs/changes/28/70128/21
--
To view, visit https://review.coreboot.org/c/flashrom/+/70128
To unsubscribe, or for help writing mail filters, visit https://review.coreboot.org/settings
Gerrit-Project: flashrom
Gerrit-Branch: master
Gerrit-Change-Id: I9b96fb04b863625d2c9f9a00b97c35b3ddb0871b
Gerrit-Change-Number: 70128
Gerrit-PatchSet: 21
Gerrit-Owner: Nikolai Artemiev <nartemiev(a)google.com>
Gerrit-Reviewer: Edward O'Callaghan <quasisec(a)chromium.org>
Gerrit-Reviewer: build bot (Jenkins) <no-reply(a)coreboot.org>
Gerrit-CC: Angel Pons <th3fanbus(a)gmail.com>
Gerrit-Attention: Edward O'Callaghan <quasisec(a)chromium.org>
Gerrit-Attention: Angel Pons <th3fanbus(a)gmail.com>
Gerrit-Attention: Nikolai Artemiev <nartemiev(a)google.com>
Gerrit-MessageType: newpatchset
Attention is currently required from: Thomas Heijligen, Evan Benn.
Hello build bot (Jenkins), Thomas Heijligen, Edward O'Callaghan, Anastasia Klimchuk,
I'd like you to reexamine a change. Please visit
https://review.coreboot.org/c/flashrom/+/69268
to look at the new patch set (#18).
Change subject: tests: Add llvm-cov option and run target for code coverage
......................................................................
tests: Add llvm-cov option and run target for code coverage
Code coverage can be requested with -Dllvm_cov and run with ninja
llvm-cov-tests or llvm-cov-cli.
BUG=b:187647884
BRANCH=None
TEST=meson test; ninja llvm-cov-tests
TEST=ran test_build.sh with coverage enabled
TEST=jenkins ran test_build.sh with coverage disabled
Change-Id: Id6c73bff46e7b88d425956a80def97082b201f56
Signed-off-by: Evan Benn <evanbenn(a)chromium.org>
---
M Documentation/building.md
M meson.build
M meson_options.txt
A scripts/llvm-cov
M tests/meson.build
5 files changed, 46 insertions(+), 9 deletions(-)
git pull ssh://review.coreboot.org:29418/flashrom refs/changes/68/69268/18
--
To view, visit https://review.coreboot.org/c/flashrom/+/69268
To unsubscribe, or for help writing mail filters, visit https://review.coreboot.org/settings
Gerrit-Project: flashrom
Gerrit-Branch: master
Gerrit-Change-Id: Id6c73bff46e7b88d425956a80def97082b201f56
Gerrit-Change-Number: 69268
Gerrit-PatchSet: 18
Gerrit-Owner: Evan Benn <evanbenn(a)google.com>
Gerrit-Reviewer: Anastasia Klimchuk <aklm(a)chromium.org>
Gerrit-Reviewer: Edward O'Callaghan <quasisec(a)chromium.org>
Gerrit-Reviewer: Thomas Heijligen <src(a)posteo.de>
Gerrit-Reviewer: build bot (Jenkins) <no-reply(a)coreboot.org>
Gerrit-CC: Felix Singer <felixsinger(a)posteo.net>
Gerrit-Attention: Thomas Heijligen <src(a)posteo.de>
Gerrit-Attention: Evan Benn <evanbenn(a)google.com>
Gerrit-MessageType: newpatchset
Anastasia Klimchuk has submitted this change. ( https://review.coreboot.org/c/flashrom/+/69266 )
(
13 is the latest approved patch-set.
No files were changed between the latest approved patch-set and the submitted one.
)Change subject: tests: Detect gcov run and redirect to real I/O functions
......................................................................
tests: Detect gcov run and redirect to real I/O functions
Code coverage writes data to disk, we need to use real io functions at
this point so that the data is really written.
BUG=b:187647884
BRANCH=None
TEST=meson test
TEST=ninja coverage
Change-Id: If06053ecd78e886c8f7fc55813f4b5635be78c6b
Signed-off-by: Evan Benn <evanbenn(a)chromium.org>
Reviewed-on: https://review.coreboot.org/c/flashrom/+/69266
Reviewed-by: Anastasia Klimchuk <aklm(a)chromium.org>
Tested-by: build bot (Jenkins) <no-reply(a)coreboot.org>
---
M Documentation/building.md
M tests/tests.c
2 files changed, 35 insertions(+), 0 deletions(-)
Approvals:
build bot (Jenkins): Verified
Anastasia Klimchuk: Looks good to me, approved
diff --git a/Documentation/building.md b/Documentation/building.md
index aabb45b..81daeb0 100644
--- a/Documentation/building.md
+++ b/Documentation/building.md
@@ -48,6 +48,18 @@
ninja -C builddir test
```
+### Run unit tests with code coverage
+#### gcov
+Due to a bug in lcov, the html file will only be correct if lcov is not
+installed and gcovr is installed. See
+https://github.com/linux-test-project/lcov/issues/168
+https://github.com/mesonbuild/meson/issues/6747
+```
+meson setup buildcov -Db_coverage=true
+ninja -C buildcov test
+ninja -C buildcov coverage
+```
+
## System specific information
### Ubuntu / Debian (Linux)
* __linux-headers__ are version specific
diff --git a/tests/tests.c b/tests/tests.c
index 41972ba..b11f642 100644
--- a/tests/tests.c
+++ b/tests/tests.c
@@ -17,6 +17,7 @@
#include "io_mock.h"
#include "tests.h"
#include "wraps.h"
+#include "io_real.h"
#include <stdio.h>
#include <string.h>
@@ -77,6 +78,7 @@
static int mock_open(const char *pathname, int flags, mode_t mode)
{
+ maybe_unmock_io(pathname);
if (get_io() && get_io()->iom_open)
return get_io()->iom_open(get_io()->state, pathname, flags, mode);
--
To view, visit https://review.coreboot.org/c/flashrom/+/69266
To unsubscribe, or for help writing mail filters, visit https://review.coreboot.org/settings
Gerrit-Project: flashrom
Gerrit-Branch: master
Gerrit-Change-Id: If06053ecd78e886c8f7fc55813f4b5635be78c6b
Gerrit-Change-Number: 69266
Gerrit-PatchSet: 15
Gerrit-Owner: Evan Benn <evanbenn(a)google.com>
Gerrit-Reviewer: Anastasia Klimchuk <aklm(a)chromium.org>
Gerrit-Reviewer: Thomas Heijligen <src(a)posteo.de>
Gerrit-Reviewer: build bot (Jenkins) <no-reply(a)coreboot.org>
Gerrit-CC: Felix Singer <felixsinger(a)posteo.net>
Gerrit-MessageType: merged
Anastasia Klimchuk has submitted this change. ( https://review.coreboot.org/c/flashrom/+/69539 )
Change subject: tests: Redirect to real I/O to support coverage run
......................................................................
tests: Redirect to real I/O to support coverage run
Implement a check that redirects mock io functions to the real
implementations. Real I/O functions are needed for the coverage tool to
be able to create and write files.
BUG=None
BRANCH=None
TEST=None
Change-Id: I0817fce6ea0f53a4c127794a0d8246504675f805
Signed-off-by: Evan Benn <evanbenn(a)chromium.org>
Reviewed-on: https://review.coreboot.org/c/flashrom/+/69539
Tested-by: build bot (Jenkins) <no-reply(a)coreboot.org>
Reviewed-by: Anastasia Klimchuk <aklm(a)chromium.org>
---
A tests/io_real.c
A tests/io_real.h
M tests/meson.build
M tests/wraps.h
4 files changed, 112 insertions(+), 0 deletions(-)
Approvals:
build bot (Jenkins): Verified
Anastasia Klimchuk: Looks good to me, approved
diff --git a/tests/io_real.c b/tests/io_real.c
new file mode 100644
index 0000000..9f9e9d6
--- /dev/null
+++ b/tests/io_real.c
@@ -0,0 +1,63 @@
+/*
+ * This file is part of the flashrom project.
+ *
+ * Copyright 2022 Google LLC
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
+#include "io_mock.h"
+#include "wraps.h"
+
+#include "io_real.h"
+#include <string.h>
+
+static int io_real_open(void *state, const char *pathname, int flags, mode_t mode)
+{
+ LOG_ME;
+ return __real_open(pathname, flags, mode);
+}
+
+static FILE *io_real_fdopen(void *state, int fd, const char *mode)
+{
+ LOG_ME;
+ return __real_fdopen(fd, mode);
+}
+
+static size_t io_real_fwrite(void *state, const void *ptr, size_t size, size_t nmemb, FILE *fp)
+{
+ return __real_fwrite(ptr, size, nmemb, fp);
+}
+
+/* Mock ios that defer to the real io functions.
+ * These exist so that code coverage can print to real files on disk.
+ */
+static const struct io_mock real_io = {
+ .iom_open = io_real_open,
+ .iom_fwrite = io_real_fwrite,
+ .iom_fdopen = io_real_fdopen,
+};
+
+/* Return 0 if string ends with suffix. */
+static int check_suffix(const char *string, const char *suffix)
+{
+ int len_l = strlen(string);
+ int len_r = strlen(suffix);
+ if (len_l > len_r)
+ return strcmp(string + len_l - len_r, suffix);
+ return 1;
+}
+
+void maybe_unmock_io(const char *pathname)
+{
+ const char *gcov_suffix = ".gcda";
+ if (!check_suffix(pathname, gcov_suffix))
+ io_mock_register(&real_io);
+}
diff --git a/tests/io_real.h b/tests/io_real.h
new file mode 100644
index 0000000..f2491c3
--- /dev/null
+++ b/tests/io_real.h
@@ -0,0 +1,24 @@
+/*
+ * This file is part of the flashrom project.
+ *
+ * Copyright 2022 Google LLC
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
+#ifndef IO_REAL_H
+#define IO_REAL_H
+
+/* Detect file io that should not be mocked, for example code coverage writing
+ * gcda files. Call io_mock_register with functions that defer to real io.
+ */
+void maybe_unmock_io(const char* pathname);
+
+#endif /* IO_REAL_H */
diff --git a/tests/meson.build b/tests/meson.build
index b8a5ba8..0d605d2 100644
--- a/tests/meson.build
+++ b/tests/meson.build
@@ -23,6 +23,7 @@
'chip.c',
'chip_wp.c',
'selfcheck.c',
+ 'io_real.c',
)
if not programmer.get('dummy').get('active')
diff --git a/tests/wraps.h b/tests/wraps.h
index e224d79..92b0c42 100644
--- a/tests/wraps.h
+++ b/tests/wraps.h
@@ -29,6 +29,7 @@
void __wrap_sio_write(uint16_t port, uint8_t reg, uint8_t data);
uint8_t __wrap_sio_read(uint16_t port, uint8_t reg);
int __wrap_open(const char *pathname, int flags, ...);
+int __real_open(const char *pathname, int flags, ...);
int __wrap_open64(const char *pathname, int flags, ...);
int __wrap___open64_2(const char *pathname, int flags, ...);
int __wrap_ioctl(int fd, unsigned long int request, ...);
@@ -37,6 +38,7 @@
FILE *__wrap_fopen(const char *pathname, const char *mode);
FILE *__wrap_fopen64(const char *pathname, const char *mode);
FILE *__wrap_fdopen(int fd, const char *mode);
+FILE *__real_fdopen(int fd, const char *mode);
int __wrap_stat(const char *path, void *buf);
int __wrap_stat64(const char *path, void *buf);
int __wrap___xstat(const char *path, void *buf);
@@ -49,6 +51,7 @@
char *__wrap___fgets_chk(char *buf, int len, FILE *fp);
size_t __wrap_fread(void *ptr, size_t size, size_t nmemb, FILE *fp);
size_t __wrap_fwrite(const void *ptr, size_t size, size_t nmemb, FILE *fp);
+size_t __real_fwrite(const void *ptr, size_t size, size_t nmemb, FILE *fp);
int __wrap_fflush(FILE *fp);
int __wrap_fileno(FILE *fp);
int __wrap_fsync(int fd);
--
To view, visit https://review.coreboot.org/c/flashrom/+/69539
To unsubscribe, or for help writing mail filters, visit https://review.coreboot.org/settings
Gerrit-Project: flashrom
Gerrit-Branch: master
Gerrit-Change-Id: I0817fce6ea0f53a4c127794a0d8246504675f805
Gerrit-Change-Number: 69539
Gerrit-PatchSet: 6
Gerrit-Owner: Evan Benn <evanbenn(a)google.com>
Gerrit-Reviewer: Anastasia Klimchuk <aklm(a)chromium.org>
Gerrit-Reviewer: Edward O'Callaghan <quasisec(a)chromium.org>
Gerrit-Reviewer: Thomas Heijligen <src(a)posteo.de>
Gerrit-Reviewer: build bot (Jenkins) <no-reply(a)coreboot.org>
Gerrit-CC: Felix Singer <felixsinger(a)posteo.net>
Gerrit-MessageType: merged