Attention is currently required from: Nico Huber, Angel Pons, Sergii Dmytruk.
Hello build bot (Jenkins), Nico Huber, Edward O'Callaghan, Angel Pons, Anastasia Klimchuk, Sergii Dmytruk,
I'd like you to reexamine a change. Please visit
https://review.coreboot.org/c/flashrom/+/58481
to look at the new patch set (#44).
Change subject: libflashrom,writeprotect: add flashrom_wp_get_available_ranges()
......................................................................
libflashrom,writeprotect: add flashrom_wp_get_available_ranges()
Generate list of available ranges by enumerating all possible values
that range bits (BPx, TB, ...) can take and using the chip's range
decoding function to get the range that is selected by each one.
BUG=b:195381327,b:153800563
TEST=flashrom --wp-list
BRANCH=none
Change-Id: Id51f038f03305c8536d80313e52f77d27835f34d
Signed-off-by: Nikolai Artemiev <nartemiev(a)google.com>
---
M libflashrom.c
M libflashrom.h
M writeprotect.c
M writeprotect.h
4 files changed, 285 insertions(+), 0 deletions(-)
git pull ssh://review.coreboot.org:29418/flashrom refs/changes/81/58481/44
--
To view, visit https://review.coreboot.org/c/flashrom/+/58481
To unsubscribe, or for help writing mail filters, visit https://review.coreboot.org/settings
Gerrit-Project: flashrom
Gerrit-Branch: master
Gerrit-Change-Id: Id51f038f03305c8536d80313e52f77d27835f34d
Gerrit-Change-Number: 58481
Gerrit-PatchSet: 44
Gerrit-Owner: Nikolai Artemiev <nartemiev(a)google.com>
Gerrit-Reviewer: Anastasia Klimchuk <aklm(a)chromium.org>
Gerrit-Reviewer: Angel Pons <th3fanbus(a)gmail.com>
Gerrit-Reviewer: Edward O'Callaghan <quasisec(a)chromium.org>
Gerrit-Reviewer: Nico Huber <nico.h(a)gmx.de>
Gerrit-Reviewer: Sergii Dmytruk <sergii.dmytruk(a)3mdeb.com>
Gerrit-Reviewer: build bot (Jenkins) <no-reply(a)coreboot.org>
Gerrit-CC: Paul Menzel <paulepanter(a)mailbox.org>
Gerrit-Attention: Nico Huber <nico.h(a)gmx.de>
Gerrit-Attention: Angel Pons <th3fanbus(a)gmail.com>
Gerrit-Attention: Sergii Dmytruk <sergii.dmytruk(a)3mdeb.com>
Gerrit-MessageType: newpatchset
Attention is currently required from: Nico Huber, Angel Pons, Nikolai Artemiev, Sergii Dmytruk.
Hello build bot (Jenkins), Nico Huber, Edward O'Callaghan, Angel Pons, Anastasia Klimchuk, Sergii Dmytruk,
I'd like you to reexamine a change. Please visit
https://review.coreboot.org/c/flashrom/+/58480
to look at the new patch set (#39).
Change subject: flashchips,writeprotect_ranges: add range decoding function
......................................................................
flashchips,writeprotect_ranges: add range decoding function
Allow chips to specify functions that map status register bits to
protection ranges. These are used to enumerate available ranges and
determine the protection state of chips. The patch also adds a range
decoding function for the example chips. Many other chips can also be
handled by it, though some will require different functions (e.g.
MX25L6406 and related chips).
Another approach that has been tried in cros flashrom is maintaining
tables of range data, but it quickly becomes error prone and hard to
validate.
Using a function to interpret the ranges allows compact encoding with
most chips and is flexible enough to allow chips with less predictable
ranges to be handled as well.
BUG=b:195381327,b:153800563
TEST=dumped range tables, checked against datasheets
BRANCH=none
Change-Id: Id163ed80938a946a502ed116e48e8236e36eb203
Signed-off-by: Nikolai Artemiev <nartemiev(a)google.com>
---
M Makefile
M chipdrivers.h
M flash.h
M flashchips.c
M meson.build
A writeprotect_ranges.c
6 files changed, 107 insertions(+), 1 deletion(-)
git pull ssh://review.coreboot.org:29418/flashrom refs/changes/80/58480/39
--
To view, visit https://review.coreboot.org/c/flashrom/+/58480
To unsubscribe, or for help writing mail filters, visit https://review.coreboot.org/settings
Gerrit-Project: flashrom
Gerrit-Branch: master
Gerrit-Change-Id: Id163ed80938a946a502ed116e48e8236e36eb203
Gerrit-Change-Number: 58480
Gerrit-PatchSet: 39
Gerrit-Owner: Nikolai Artemiev <nartemiev(a)google.com>
Gerrit-Reviewer: Anastasia Klimchuk <aklm(a)chromium.org>
Gerrit-Reviewer: Angel Pons <th3fanbus(a)gmail.com>
Gerrit-Reviewer: Edward O'Callaghan <quasisec(a)chromium.org>
Gerrit-Reviewer: Nico Huber <nico.h(a)gmx.de>
Gerrit-Reviewer: Sergii Dmytruk <sergii.dmytruk(a)3mdeb.com>
Gerrit-Reviewer: build bot (Jenkins) <no-reply(a)coreboot.org>
Gerrit-CC: Paul Menzel <paulepanter(a)mailbox.org>
Gerrit-Attention: Nico Huber <nico.h(a)gmx.de>
Gerrit-Attention: Angel Pons <th3fanbus(a)gmail.com>
Gerrit-Attention: Nikolai Artemiev <nartemiev(a)google.com>
Gerrit-Attention: Sergii Dmytruk <sergii.dmytruk(a)3mdeb.com>
Gerrit-MessageType: newpatchset
Attention is currently required from: Edward O'Callaghan.
Edward O'Callaghan has posted comments on this change. ( https://review.coreboot.org/c/flashrom/+/62213 )
Change subject: flashrom.c: Implement file-based locking semantics
......................................................................
Patch Set 1:
(1 comment)
Patchset:
PS1:
aklm could you take a look at the unit-test aspect of this please?
--
To view, visit https://review.coreboot.org/c/flashrom/+/62213
To unsubscribe, or for help writing mail filters, visit https://review.coreboot.org/settings
Gerrit-Project: flashrom
Gerrit-Branch: master
Gerrit-Change-Id: I19cb4e3bf14caeb67c3e8100a20395b264c5113a
Gerrit-Change-Number: 62213
Gerrit-PatchSet: 1
Gerrit-Owner: Edward O'Callaghan <quasisec(a)chromium.org>
Gerrit-Reviewer: build bot (Jenkins) <no-reply(a)coreboot.org>
Gerrit-CC: Anastasia Klimchuk <aklm(a)chromium.org>
Gerrit-Attention: Edward O'Callaghan <quasisec(a)chromium.org>
Gerrit-Comment-Date: Mon, 21 Feb 2022 00:08:38 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Gerrit-MessageType: comment
Edward O'Callaghan has uploaded this change for review. ( https://review.coreboot.org/c/flashrom/+/62213 )
Change subject: flashrom.c: Implement file-based locking semantics
......................................................................
flashrom.c: Implement file-based locking semantics
This upstreams the ChromiumOS implementation of file-based locking
for multiple instances of flashrom that could be spawned either
from libflashrom (perhaps by fwupd for example) and user cli
as another example. Since flashrom is programming singleton state
of hardware from userspace there is no way to exclusively own
the address space and therefore a file-based locking semantic
is considered here.
BUG=b:217629892,b:215255210
BRANCH=none
TEST=nm -gD /build/brya/usr/lib64/libflashrom.so | grep "flock"
Test futility update with multiple instances of flashrom running.
Change-Id: I19cb4e3bf14caeb67c3e8100a20395b264c5113a
Signed-off-by: Edward O'Callaghan <quasisec(a)google.com>
---
M Makefile
A big_lock.c
A big_lock.h
A file_lock.c
M flashrom.c
A ipc_lock.h
M meson.build
7 files changed, 441 insertions(+), 0 deletions(-)
git pull ssh://review.coreboot.org:29418/flashrom refs/changes/13/62213/1
diff --git a/Makefile b/Makefile
index 7628142..365c282 100644
--- a/Makefile
+++ b/Makefile
@@ -388,6 +388,7 @@
# Library code.
LIB_OBJS = libflashrom.o layout.o flashrom.o udelay.o programmer.o programmer_table.o helpers.o ich_descriptors.o fmap.o
+LIB_OBJS += big_lock.o file_lock.o
###############################################################################
# Frontend related stuff.
diff --git a/big_lock.c b/big_lock.c
new file mode 100644
index 0000000..7b83f3e
--- /dev/null
+++ b/big_lock.c
@@ -0,0 +1,45 @@
+/* Copyright 2012, Google Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided
+ * with the distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "big_lock.h"
+#include "ipc_lock.h"
+
+#define LOCKFILE_NAME "firmware_utility_lock"
+static struct ipc_lock big_lock = LOCKFILE_INIT(LOCKFILE_NAME);
+
+int acquire_big_lock(int timeout_secs)
+{
+ return acquire_lock(&big_lock, timeout_secs * 1000);
+}
+
+int release_big_lock(void)
+{
+ return release_lock(&big_lock);
+}
diff --git a/big_lock.h b/big_lock.h
new file mode 100644
index 0000000..a28fe44
--- /dev/null
+++ b/big_lock.h
@@ -0,0 +1,51 @@
+/* Copyright 2012, Google Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided
+ * with the distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef BIG_LOCK_H__
+#define BIG_LOCK_H__
+
+/*
+ * acquire_big_lock - acquire global lock
+ *
+ * returns 0 to indicate lock acquired
+ * returns >0 to indicate lock was already held
+ * returns <0 to indicate failed to acquire lock
+ */
+extern int acquire_big_lock(int timeout_secs);
+
+/*
+ * release_big_lock - release global lock
+ *
+ * returns 0 if lock was released successfully
+ * returns -1 if lock had not been held before the call
+ */
+extern int release_big_lock(void);
+
+#endif /* BIG_LOCK_H__ */
diff --git a/file_lock.c b/file_lock.c
new file mode 100644
index 0000000..4bcfeb2
--- /dev/null
+++ b/file_lock.c
@@ -0,0 +1,247 @@
+/* Copyright 2016, Google Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided
+ * with the distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * Alternatively, this software may be distributed under the terms of the
+ * GNU General Public License ("GPL") version 2 as published by the Free
+ * Software Foundation.
+ *
+ * file_lock.c: Implementation for a binary semaphore using a file lock.
+ *
+ * Warning: This relies on flock() which is known to be broken on NFS.
+ *
+ * The file will remain persistent once the lock has been used. Unfortunately,
+ * unlinking the file can introduce a race condition so we leave the file
+ * in place.
+ *
+ * The current process's PID will be written to the file for debug purposes.
+ */
+
+#include <errno.h>
+#include <fcntl.h>
+#include <inttypes.h>
+#include <limits.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <time.h>
+#include <unistd.h>
+#include <sys/file.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+
+#include "flash.h"
+#include "ipc_lock.h"
+
+#define SLEEP_INTERVAL_MS 50
+
+static void msecs_to_timespec(int msecs, struct timespec *tmspec)
+{
+ tmspec->tv_sec = msecs / 1000;
+ tmspec->tv_nsec = (msecs % 1000) * 1000 * 1000;
+}
+
+static int lock_is_held(struct ipc_lock *lock)
+{
+ return lock->is_held;
+}
+
+static int test_dir(const char *path)
+{
+ struct stat s;
+
+ if (lstat(path, &s) < 0) {
+ msg_gerr("Cannot stat %s.\n", path);
+ return -1;
+ }
+
+ if (!S_ISDIR(s.st_mode)) {
+ msg_gerr("%s is not a directory.\n", path);
+ return -1;
+ }
+
+ return 0;
+}
+
+#define SYSTEM_LOCKFILE_DIR "/run/lock"
+static int file_lock_open_or_create(struct ipc_lock *lock)
+{
+ char path[PATH_MAX];
+ const char *dir = SYSTEM_LOCKFILE_DIR;
+ const char fallback[] = "/tmp";
+
+ if (test_dir(dir)) {
+ dir = fallback;
+ msg_gerr("Trying fallback directory: %s\n", dir);
+ if (test_dir(dir))
+ return -1;
+ }
+
+ if (snprintf(path, sizeof(path), "%s/%s", dir, lock->filename) < 0)
+ return -1;
+
+ lock->fd = open(path, O_RDWR | O_CREAT, 0600);
+ if (lock->fd < 0) {
+ msg_gerr("Cannot open lockfile %s", path);
+ return -1;
+ }
+
+ msg_gdbg("Opened file lock \"%s\"\n", path);
+ return 0;
+}
+
+static int file_lock_get(struct ipc_lock *lock, int timeout_msecs)
+{
+ int msecs_remaining = timeout_msecs;
+ struct timespec sleep_interval, rem;
+ int ret = -1;
+
+ if (timeout_msecs == 0)
+ return flock(lock->fd, LOCK_EX | LOCK_NB);
+
+ msecs_to_timespec(SLEEP_INTERVAL_MS, &sleep_interval);
+
+ while ((ret = flock(lock->fd, LOCK_EX | LOCK_NB)) != 0) {
+ if (errno != EWOULDBLOCK) {
+ msg_gerr("Error obtaining lock");
+ return -1;
+ }
+
+ if (msecs_remaining < SLEEP_INTERVAL_MS)
+ msecs_to_timespec(msecs_remaining, &sleep_interval);
+
+ while (nanosleep(&sleep_interval, &rem) != 0) {
+ if (errno == EINTR) {
+ sleep_interval = rem;
+ continue;
+ } else {
+ msg_gerr("nanosleep() failed");
+ return ret;
+ }
+ }
+
+ if (timeout_msecs < 0)
+ continue;
+
+ msecs_remaining -= SLEEP_INTERVAL_MS;
+ if (msecs_remaining < 0)
+ break;
+ }
+
+ if (ret != 0) {
+ msg_gerr("Timed out waiting for file lock.\n");
+ return -1;
+ }
+
+ return 0;
+}
+
+static int file_lock_write_pid(struct ipc_lock *lock)
+{
+ ssize_t len;
+ /* PIDs are usually 5 digits, but we'll reserve enough room for
+ a value of 2^32 (10 digits) out of paranoia. */
+ char pid_str[11];
+
+ if (ftruncate(lock->fd, 0) < 0) {
+ msg_gerr("Cannot truncate lockfile");
+ return -1;
+ }
+
+ snprintf(pid_str, sizeof(pid_str), "%lu", (unsigned long)getpid());
+ len = write(lock->fd, pid_str, strlen(pid_str));
+ if (len < 0) {
+ msg_gerr("Cannot write PID to lockfile");
+ return -1;
+ }
+
+ return 0;
+}
+
+static void file_lock_release(struct ipc_lock *lock)
+{
+ if (flock(lock->fd, LOCK_UN) < 0)
+ msg_gerr("Cannot release lock");
+
+ if (close(lock->fd) < 0)
+ msg_gerr("Cannot close lockfile");
+}
+
+/*
+ * timeout <0 = no timeout (try forever)
+ * timeout 0 = do not wait (return immediately)
+ * timeout >0 = wait up to $timeout milliseconds
+ *
+ * returns 0 to indicate lock acquired
+ * returns >0 to indicate lock was already held
+ * returns <0 to indicate failed to acquire lock
+ */
+int acquire_lock(struct ipc_lock *lock, int timeout_msecs)
+{
+ /* check if it is already held */
+ if (lock_is_held(lock))
+ return 1;
+
+ if (file_lock_open_or_create(lock))
+ return -1;
+
+ if (file_lock_get(lock, timeout_msecs)) {
+ lock->is_held = 0;
+ close(lock->fd);
+ return -1;
+ } else {
+ lock->is_held = 1;
+ }
+
+ /*
+ * Write PID to lockfile for debug purposes. Failure to write to
+ * the file should not be considered fatal. There might be something
+ * bad happening with the filesystem, but the lock has already been
+ * obtained and we may need our tools for diagnostics and repairs
+ * so we should continue anyway.
+ */
+ file_lock_write_pid(lock);
+ return 0;
+}
+
+/*
+ * returns 0 if lock was released successfully
+ * returns -1 if lock had not been held before the call
+ */
+int release_lock(struct ipc_lock *lock)
+{
+ if (lock_is_held(lock)) {
+ file_lock_release(lock);
+ lock->is_held = 0;
+ return 0;
+ }
+
+ msg_ginfo("%s called but lock was not held on %s.\n",
+ __func__, lock->filename);
+ return -1;
+}
diff --git a/flashrom.c b/flashrom.c
index ac61259..672b378 100644
--- a/flashrom.c
+++ b/flashrom.c
@@ -34,6 +34,8 @@
#if HAVE_UTSNAME == 1
#include <sys/utsname.h>
#endif
+
+#include "big_lock.h"
#include "flash.h"
#include "flashchips.h"
#include "programmer.h"
@@ -46,6 +48,15 @@
static const struct programmer_entry *programmer = NULL;
static const char *programmer_param = NULL;
+#ifndef USE_BIG_LOCK
+#define USE_BIG_LOCK 0
+#endif
+
+#define LOCK_TIMEOUT_SECS 180
+
+/** Big lock acquisition status. */
+static bool big_lock_acquired = false;
+
/*
* Programmers supporting multiple buses can have differing size limits on
* each bus. Store the limits for each bus in a common struct.
@@ -136,6 +147,16 @@
msg_perr("Invalid programmer specified!\n");
return -1;
}
+
+ /* Get big lock before doing any work that touches hardware. */
+ msg_gdbg("Acquiring lock (timeout=%d sec)...\n", LOCK_TIMEOUT_SECS);
+ if (acquire_big_lock(LOCK_TIMEOUT_SECS) < 0) {
+ msg_gerr("Could not acquire lock.\n");
+ return -1;
+ }
+ big_lock_acquired = true;
+ msg_gdbg("Lock acquired.\n");
+
programmer = prog;
/* Initialize all programmer specific data. */
/* Default to unlimited decode sizes. */
@@ -193,6 +214,11 @@
programmer_param = NULL;
registered_master_count = 0;
+ if (big_lock_acquired) {
+ release_big_lock();
+ big_lock_acquired = false;
+ }
+
return ret;
}
diff --git a/ipc_lock.h b/ipc_lock.h
new file mode 100644
index 0000000..7b53ffe
--- /dev/null
+++ b/ipc_lock.h
@@ -0,0 +1,69 @@
+/* Copyright 2012, Google Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided
+ * with the distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef IPC_LOCK_H__
+#define IPC_LOCK_H__
+
+struct ipc_lock {
+ int is_held; /* internal */
+ const char *filename; /* provided by the developer */
+ int fd; /* internal */
+};
+
+/* don't use C99 initializers here, so this can be used in C++ code */
+#define LOCKFILE_INIT(lockfile) \
+ { \
+ 0, /* is_held */ \
+ lockfile, /* filename */ \
+ -1, /* fd */ \
+ }
+
+/*
+ * acquire_lock: acquire a lock
+ *
+ * timeout <0 = no timeout (try forever)
+ * timeout 0 = do not wait (return immediately)
+ * timeout >0 = wait up to $timeout milliseconds (subject to kernel scheduling)
+ *
+ * return 0 = lock acquired
+ * return >0 = lock was already held
+ * return <0 = failed to acquire lock
+ */
+extern int acquire_lock(struct ipc_lock *lock, int timeout_msecs);
+
+/*
+ * release_lock: release a lock
+ *
+ * returns 0 if lock was released successfully
+ * returns -1 if lock had not been held before the call
+ */
+extern int release_lock(struct ipc_lock *lock);
+
+#endif /* IPC_LOCK_H__ */
diff --git a/meson.build b/meson.build
index cd9f9fb..69ceb06 100644
--- a/meson.build
+++ b/meson.build
@@ -401,11 +401,13 @@
# core modules needed by both the library and the CLI
srcs += '82802ab.c'
srcs += 'at45db.c'
+srcs += 'big_lock.c'
srcs += 'edi.c'
srcs += 'en29lv640b.c'
srcs += 'flashchips.c'
srcs += 'flashrom.c'
srcs += 'fmap.c'
+srcs += 'file_lock.c'
srcs += 'helpers.c'
srcs += 'ich_descriptors.c'
srcs += 'jedec.c'
--
To view, visit https://review.coreboot.org/c/flashrom/+/62213
To unsubscribe, or for help writing mail filters, visit https://review.coreboot.org/settings
Gerrit-Project: flashrom
Gerrit-Branch: master
Gerrit-Change-Id: I19cb4e3bf14caeb67c3e8100a20395b264c5113a
Gerrit-Change-Number: 62213
Gerrit-PatchSet: 1
Gerrit-Owner: Edward O'Callaghan <quasisec(a)chromium.org>
Gerrit-MessageType: newchange
Attention is currently required from: Nico Huber, Angel Pons, Nikolai Artemiev, Sergii Dmytruk.
Anastasia Klimchuk has posted comments on this change. ( https://review.coreboot.org/c/flashrom/+/58480 )
Change subject: flashchips,writeprotect_ranges: add range decoding function
......................................................................
Patch Set 38:
(1 comment)
File writeprotect_ranges.c:
https://review.coreboot.org/c/flashrom/+/58480/comment/92bd3bfe_76945c53
PS35, Line 8: * the Free Software Foundation; version 2 of the License.
> Done
This still says "version 2", was the intention to have "version 2+"?
--
To view, visit https://review.coreboot.org/c/flashrom/+/58480
To unsubscribe, or for help writing mail filters, visit https://review.coreboot.org/settings
Gerrit-Project: flashrom
Gerrit-Branch: master
Gerrit-Change-Id: Id163ed80938a946a502ed116e48e8236e36eb203
Gerrit-Change-Number: 58480
Gerrit-PatchSet: 38
Gerrit-Owner: Nikolai Artemiev <nartemiev(a)google.com>
Gerrit-Reviewer: Anastasia Klimchuk <aklm(a)chromium.org>
Gerrit-Reviewer: Angel Pons <th3fanbus(a)gmail.com>
Gerrit-Reviewer: Edward O'Callaghan <quasisec(a)chromium.org>
Gerrit-Reviewer: Nico Huber <nico.h(a)gmx.de>
Gerrit-Reviewer: Sergii Dmytruk <sergii.dmytruk(a)3mdeb.com>
Gerrit-Reviewer: build bot (Jenkins) <no-reply(a)coreboot.org>
Gerrit-CC: Paul Menzel <paulepanter(a)mailbox.org>
Gerrit-Attention: Nico Huber <nico.h(a)gmx.de>
Gerrit-Attention: Angel Pons <th3fanbus(a)gmail.com>
Gerrit-Attention: Nikolai Artemiev <nartemiev(a)google.com>
Gerrit-Attention: Sergii Dmytruk <sergii.dmytruk(a)3mdeb.com>
Gerrit-Comment-Date: Sun, 20 Feb 2022 23:47:45 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: Nico Huber <nico.h(a)gmx.de>
Comment-In-Reply-To: Nikolai Artemiev <nartemiev(a)google.com>
Gerrit-MessageType: comment
Edward O'Callaghan has submitted this change. ( https://review.coreboot.org/c/flashrom/+/61943 )
Change subject: libflashrom/fmap: Don't use off_t for flash offsets
......................................................................
libflashrom/fmap: Don't use off_t for flash offsets
off_t is a special POSIX type that is used to represent file offsets in
certain APIs (e.g. lseek(), mmap()), and should not be reused to
represent anything else (such as flash offsets). In particular, the
width of the type may change based on the definition of the
_FILE_OFFSET_BITS macro. Using such a type at the libflashrom interface
is particularly dangerous, because if a program is built with a
different _FILE_OFFSET_BITS value than libflashrom, the resulting ABI
corruption will cause very very nasty and confusing bugs. This patch
replaces all instances of off_t that are not related to file offsets
with (s)size_t.
BUG=b:219811851
TEST=`elogtool list` on cherry.
Signed-off-by: Julius Werner <jwerner(a)chromium.org>
Change-Id: I68a386973f79ea634f63dfcd7d95a63400e1fdee
Reviewed-on: https://review.coreboot.org/c/flashrom/+/61943
Reviewed-by: Nico Huber <nico.h(a)gmx.de>
Reviewed-by: Angel Pons <th3fanbus(a)gmail.com>
Reviewed-by: Edward O'Callaghan <quasisec(a)chromium.org>
Reviewed-by: Nikolai Artemiev <nartemiev(a)google.com>
Tested-by: build bot (Jenkins) <no-reply(a)coreboot.org>
---
M fmap.c
M libflashrom.c
M libflashrom.h
3 files changed, 6 insertions(+), 6 deletions(-)
Approvals:
build bot (Jenkins): Verified
Nico Huber: Looks good to me, but someone else must approve
Angel Pons: Looks good to me, but someone else must approve
Edward O'Callaghan: Looks good to me, approved
Nikolai Artemiev: Looks good to me, but someone else must approve
diff --git a/fmap.c b/fmap.c
index 0236b62..bd847bd 100644
--- a/fmap.c
+++ b/fmap.c
@@ -91,15 +91,15 @@
* -1 to indicate that fmap was not found
* -2 to indicate fmap is truncated or exceeds buffer + len
*/
-static off_t fmap_lsearch(const uint8_t *buf, size_t len)
+static ssize_t fmap_lsearch(const uint8_t *buf, size_t len)
{
- off_t offset;
+ ssize_t offset;
bool fmap_found = 0;
if (len < sizeof(struct fmap))
return -1;
- for (offset = 0; offset <= (off_t)(len - sizeof(struct fmap)); offset++) {
+ for (offset = 0; offset <= (ssize_t)(len - sizeof(struct fmap)); offset++) {
if (is_valid_fmap((struct fmap *)&buf[offset])) {
fmap_found = 1;
break;
@@ -131,7 +131,7 @@
*/
int fmap_read_from_buffer(struct fmap **fmap_out, const uint8_t *const buf, size_t len)
{
- off_t offset = fmap_lsearch(buf, len);
+ ssize_t offset = fmap_lsearch(buf, len);
if (offset < 0) {
msg_gdbg("Unable to find fmap in provided buffer.\n");
return 2;
diff --git a/libflashrom.c b/libflashrom.c
index fb70934..d66c295 100644
--- a/libflashrom.c
+++ b/libflashrom.c
@@ -534,7 +534,7 @@
* 1 on any other error.
*/
int flashrom_layout_read_fmap_from_rom(struct flashrom_layout **const layout,
- struct flashctx *const flashctx, off_t offset, size_t len)
+ struct flashctx *const flashctx, size_t offset, size_t len)
{
#ifndef __FLASHROM_LITTLE_ENDIAN__
return 3;
diff --git a/libflashrom.h b/libflashrom.h
index 557978d..1c9498e 100644
--- a/libflashrom.h
+++ b/libflashrom.h
@@ -109,7 +109,7 @@
int flashrom_layout_new(struct flashrom_layout **);
int flashrom_layout_read_from_ifd(struct flashrom_layout **, struct flashrom_flashctx *, const void *dump, size_t len);
int flashrom_layout_read_fmap_from_rom(struct flashrom_layout **,
- struct flashrom_flashctx *, off_t offset, size_t length);
+ struct flashrom_flashctx *, size_t offset, size_t length);
int flashrom_layout_read_fmap_from_buffer(struct flashrom_layout **layout,
struct flashrom_flashctx *, const uint8_t *buf, size_t len);
int flashrom_layout_add_region(struct flashrom_layout *, size_t start, size_t end, const char *name);
2 is the latest approved patch-set.
No files were changed between the latest approved patch-set and the submitted one.
--
To view, visit https://review.coreboot.org/c/flashrom/+/61943
To unsubscribe, or for help writing mail filters, visit https://review.coreboot.org/settings
Gerrit-Project: flashrom
Gerrit-Branch: master
Gerrit-Change-Id: I68a386973f79ea634f63dfcd7d95a63400e1fdee
Gerrit-Change-Number: 61943
Gerrit-PatchSet: 4
Gerrit-Owner: Julius Werner <jwerner(a)chromium.org>
Gerrit-Reviewer: Angel Pons <th3fanbus(a)gmail.com>
Gerrit-Reviewer: Arthur Heymans <arthur(a)aheymans.xyz>
Gerrit-Reviewer: David Hendricks <david.hendricks(a)gmail.com>
Gerrit-Reviewer: Edward O'Callaghan <quasisec(a)chromium.org>
Gerrit-Reviewer: Nico Huber <nico.h(a)gmx.de>
Gerrit-Reviewer: Nikolai Artemiev <nartemiev(a)google.com>
Gerrit-Reviewer: build bot (Jenkins) <no-reply(a)coreboot.org>
Gerrit-CC: Paul Menzel <paulepanter(a)mailbox.org>
Gerrit-MessageType: merged
Attention is currently required from: Nico Huber, Thomas Heijligen.
Felix Singer has posted comments on this change. ( https://review.coreboot.org/c/flashrom/+/62197 )
Change subject: Makefile: use the HAS_ USE_ scheme for linux i2c dependend programmer
......................................................................
Patch Set 1: Code-Review+1
(1 comment)
File Makefile:
https://review.coreboot.org/c/flashrom/+/62197/comment/2e0fa717_cdbb3ca5
PS1, Line 795: ,$(DEPENDS_ON_LINUX_I2C)),yes,no)
add missing spaces
--
To view, visit https://review.coreboot.org/c/flashrom/+/62197
To unsubscribe, or for help writing mail filters, visit https://review.coreboot.org/settings
Gerrit-Project: flashrom
Gerrit-Branch: master
Gerrit-Change-Id: I47acdf89a369441b9fc664352c27c43b461545b1
Gerrit-Change-Number: 62197
Gerrit-PatchSet: 1
Gerrit-Owner: Thomas Heijligen <src(a)posteo.de>
Gerrit-Reviewer: Felix Singer <felixsinger(a)posteo.net>
Gerrit-Reviewer: Nico Huber <nico.h(a)gmx.de>
Gerrit-Reviewer: build bot (Jenkins) <no-reply(a)coreboot.org>
Gerrit-Attention: Nico Huber <nico.h(a)gmx.de>
Gerrit-Attention: Thomas Heijligen <src(a)posteo.de>
Gerrit-Comment-Date: Sun, 20 Feb 2022 21:32:47 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment