Nico Huber has uploaded this change for review. ( https://review.coreboot.org/c/flashrom/+/31017
Change subject: ifwi: Add definitions for the Integrated Firmware Image format
......................................................................
ifwi: Add definitions for the Integrated Firmware Image format
The Integrated Firmware Image (IFWI) is used as a partitioning format
on some Intel SoCs (e.g. Apollo Lake). It is not tied to NOR flashes,
rather to have a common format between different types of boot media.
Change-Id: I4bdf47637bfb68560e6d4269f89710572c1bb82a
Signed-off-by: Nico Huber <nico.h(a)gmx.de>
---
A ifwi.h
1 file changed, 80 insertions(+), 0 deletions(-)
git pull ssh://review.coreboot.org:29418/flashrom refs/changes/17/31017/1
diff --git a/ifwi.h b/ifwi.h
new file mode 100644
index 0000000..622fccf
--- /dev/null
+++ b/ifwi.h
@@ -0,0 +1,80 @@
+/*
+ * This file is part of the flashrom project.
+ *
+ * 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; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * 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.
+ */
+
+/*
+ * The Integrated Firmware Image (IFWI) is used as a partitioning
+ * format on some Intel SoCs (e.g. Apollo Lake). It is not tied to
+ * NOR flashes, rather to have a common format between different
+ * types of boot media.
+ */
+
+#ifndef __IFWI_H__
+#define __IFWI_H__ 1
+
+#include <stdint.h>
+
+#include "layout.h"
+
+int layout_from_ifwi_rom(struct flashrom_layout **, struct flashrom_flashctx *, const size_t flash_offset);
+
+/*********** Boot Partition Descriptor Table (BPDT) ***********/
+
+#define BPDT_ENTRY_LENGTH 12
+
+struct bpdt_entry { /* points to a Sub-Partition */
+ uint16_t type;
+ uint16_t flags;
+ uint32_t offset; /* from start of Logical Boot Partition */
+ uint32_t size;
+};
+
+#define BPDT_SIGNATURE 0x000055aa
+#define BPDT_HEADER_LENGTH 24
+
+struct bpdt {
+ uint32_t signature;
+ uint16_t desc_count;
+ uint16_t version;
+ uint32_t xorsum; /* covers BPDT to S-BPDT (inclusive), iff there is
+ a redundant Logical Boot Partition, otherwise 0 */
+ uint32_t ifwi_version; /* revision of this IFWI build */
+ struct bpdt_entry entries[];
+};
+
+/**************** Sub-Partition Directory (SPD) ***************/
+
+#define SPD_ENTRY_OFFSET_MASK 0x01ffffff
+#define SPD_ENTRY_LENGTH 24
+
+struct spd_entry {
+ char name[12 + 1]; /* serialized as 12 chars w/o terminator */
+ uint32_t offset; /* from start of the SPD header */
+ uint32_t length;
+};
+
+#define SPD_MARKER 0x44504324 /* $CPD */
+#define SPD_MIN_HEADER_LENGTH 16
+
+struct spd {
+ uint32_t marker;
+ uint32_t num_entries;
+ uint8_t header_version;
+ uint8_t entry_version;
+ uint8_t header_length;
+ uint8_t checksum; /* xor-sum covering header + entries */
+ char name[4 + 1]; /* serialized as 4 chars w/o terminator */
+ struct spd_entry entries[];
+};
+
+#endif /* __IFWI_H__ */
--
To view, visit https://review.coreboot.org/c/flashrom/+/31017
To unsubscribe, or for help writing mail filters, visit https://review.coreboot.org/settings
Gerrit-Project: flashrom
Gerrit-Branch: master
Gerrit-Change-Id: I4bdf47637bfb68560e6d4269f89710572c1bb82a
Gerrit-Change-Number: 31017
Gerrit-PatchSet: 1
Gerrit-Owner: Nico Huber <nico.h(a)gmx.de>
Gerrit-MessageType: newchange
Ryan O'Leary has uploaded this change for review. ( https://review.coreboot.org/c/flashrom/+/34160 )
Change subject: dediprog.c: Add id parameter to dediprog programmer
......................................................................
dediprog.c: Add id parameter to dediprog programmer
When multiple dediprog programmers are connected, the 'id' parameter
allows you to specify which one to use. The id is a string like SF012345
or DP012345. The value is printed on a sticker on the back of the dediprog.
This is an improvement over the 'device' parameter which is based on
enumeration order and changes when you plug/unplug devices or reboot the
machine.
To find the id without the sticker, run flashrom with the -V option.
This prints the ids as they are enumerated. Alternatively, with dpcmd,
you can use the --list-device-id and --fix-device commands to list and
write device ids respectively.
Note this only supports SF100 at the moment, but SF600 support is
possible with more work.
Change-Id: I4281213ab02131feb5d47bf66118a001cec0d219
Signed-off-by: Ryan O'Leary <ryanoleary(a)google.com>
---
M dediprog.c
1 file changed, 133 insertions(+), 19 deletions(-)
git pull ssh://review.coreboot.org:29418/flashrom refs/changes/60/34160/1
diff --git a/dediprog.c b/dediprog.c
index 8029b64..1d10b24 100644
--- a/dediprog.c
+++ b/dediprog.c
@@ -823,6 +823,46 @@
return 0;
}
+/* Read the id from the dediprog. This should return the numeric part of the
+ * serial number found on a sticker on the back of the dediprog. Note this
+ * number is stored in writable eeprom, so it could get out of sync. Also note,
+ * this function only supports SF100 at this time, but SF600 support is not too
+ * much different.
+ * @return the id on success, -1 on failure
+ */
+static int dediprog_read_id(void)
+{
+ int ret;
+ uint8_t buf[3];
+
+ ret = libusb_control_transfer(dediprog_handle, REQTYPE_OTHER_IN,
+ 0x7, /* request */
+ 0, /* value */
+ 0xEF00, /* index */
+ buf, sizeof(buf),
+ DEFAULT_TIMEOUT);
+ if (ret != sizeof(buf)) {
+ msg_perr("Failed to read dediprog id, error %d!\n", ret);
+ return -1;
+ }
+
+ return buf[0] << 16 | buf[1] << 8 | buf[2];
+}
+
+/* Return the prefix to display in front of the id. These two characters also
+ * appear on the sticker even though they can be derived from the numerical
+ * part.
+ * @id a dediprog's id
+ * @return either "DP" or "SF"
+ */
+static const char* dediprog_id_prefix(int id) {
+ /* This is so the id matches dpcmd. */
+ if (id < 600000) {
+ return "DP";
+ }
+ return "SF";
+}
+
/*
* This command presumably sets the voltage for the SF100 itself (not the
* SPI flash). Only use this command with firmware older than V6.0.0. Newer
@@ -997,9 +1037,11 @@
int dediprog_init(void)
{
- char *voltage, *device, *spispeed, *target_str;
+ char *voltage, *id_str, *device, *spispeed, *target_str;
int spispeed_idx = 1;
int millivolt = 3500;
+ int id = -1; /* -1 defaults to enumeration order */
+ int found_id;
long usedevice = 0;
long target = FLASH_TYPE_APPLICATION_FLASH_1;
int i, ret;
@@ -1029,9 +1071,37 @@
msg_pinfo("Setting voltage to %i mV\n", millivolt);
}
+ id_str = extract_programmer_param("id");
+ if (id_str) {
+ char prefix0, prefix1;
+ const char *prefix;
+ if (sscanf(id_str, "%c%c%d", &prefix0, &prefix1, &id) != 3) {
+ msg_perr("Error: Could not parse dediprog 'id'.\n");
+ msg_perr("Expected a string like SF012345 or DP012345.\n");
+ free(id_str);
+ return 1;
+ }
+ if (id < 0 || id >= 0x1000000) {
+ msg_perr("Error: id %s is out of range!\n", id_str);
+ free(id_str);
+ return 1;
+ }
+ prefix = dediprog_id_prefix(id);
+ if (strlen(prefix) != 2 || prefix[0] != prefix0 || prefix[1] != prefix1) {
+ msg_perr("Error: %s is an invalid id!\n", id_str);
+ free(id_str);
+ return 1;
+ }
+ msg_pinfo("Will search for dediprog id %s%06d.\n", dediprog_id_prefix(id), id);
+ }
+ free(id_str);
+
device = extract_programmer_param("device");
if (device) {
char *dev_suffix;
+ if (id != -1) {
+ msg_perr("Error: Cannot use 'id' and 'device'.\n");
+ }
errno = 0;
usedevice = strtol(device, &dev_suffix, 10);
if (errno != 0 || device == dev_suffix) {
@@ -1097,25 +1167,69 @@
const uint16_t vid = devs_dediprog[0].vendor_id;
const uint16_t pid = devs_dediprog[0].device_id;
- dediprog_handle = usb_dev_get_by_vid_pid_number(usb_ctx, vid, pid, (unsigned int) usedevice);
- if (!dediprog_handle) {
- msg_perr("Could not find a Dediprog programmer on USB.\n");
- libusb_exit(usb_ctx);
- return 1;
+ for (;;) {
+ /* Notice we can only call dediprog_read_id() after
+ * libusb_set_configuration() and libusb_claim_interface(). When
+ * searching by id and either configuration or claim fails
+ * (usually the device is in use by another instance of
+ * flashrom), the device is skipped and the next device is
+ * tried.
+ */
+ dediprog_handle = usb_dev_get_by_vid_pid_number(usb_ctx, vid, pid, (unsigned int) usedevice);
+ if (!dediprog_handle) {
+ msg_perr("Could not find a Dediprog programmer on USB.\n");
+ libusb_exit(usb_ctx);
+ return 1;
+ }
+ ret = libusb_set_configuration(dediprog_handle, 1);
+ if (ret != 0) {
+ msg_perr("Could not set USB device configuration: %i %s\n",
+ ret, libusb_error_name(ret));
+ libusb_close(dediprog_handle);
+ if (id != -1) {
+ usedevice++;
+ continue;
+ }
+ libusb_exit(usb_ctx);
+ return 1;
+ }
+ ret = libusb_claim_interface(dediprog_handle, 0);
+ if (ret < 0) {
+ msg_perr("Could not claim USB device interface %i: %i %s\n",
+ 0, ret, libusb_error_name(ret));
+ libusb_close(dediprog_handle);
+ if (id != -1) {
+ usedevice++;
+ continue;
+ }
+ libusb_exit(usb_ctx);
+ return 1;
+ }
+
+ /* Read the dediprog's id. The value is only used (besides
+ * logging) when searching by id.
+ */
+ found_id = dediprog_read_id();
+ if (id != -1) {
+ if (found_id < 0) {
+ msg_perr("Could not read id.\n");
+ libusb_release_interface(dediprog_handle, 0);
+ libusb_close(dediprog_handle);
+ usedevice++;
+ continue;
+ }
+ msg_pinfo("Found dediprog id %s%06d.\n", dediprog_id_prefix(found_id), found_id);
+ if (found_id != id) {
+ libusb_release_interface(dediprog_handle, 0);
+ libusb_close(dediprog_handle);
+ usedevice++;
+ continue;
+ }
+ }
+ break;
}
- ret = libusb_set_configuration(dediprog_handle, 1);
- if (ret != 0) {
- msg_perr("Could not set USB device configuration: %i %s\n", ret, libusb_error_name(ret));
- libusb_close(dediprog_handle);
- libusb_exit(usb_ctx);
- return 1;
- }
- ret = libusb_claim_interface(dediprog_handle, 0);
- if (ret < 0) {
- msg_perr("Could not claim USB device interface %i: %i %s\n", 0, ret, libusb_error_name(ret));
- libusb_close(dediprog_handle);
- libusb_exit(usb_ctx);
- return 1;
+ if (found_id >= 0) {
+ msg_pinfo("Using dediprog id %s%06d.\n", dediprog_id_prefix(found_id), found_id);
}
if (register_shutdown(dediprog_shutdown, NULL))
--
To view, visit https://review.coreboot.org/c/flashrom/+/34160
To unsubscribe, or for help writing mail filters, visit https://review.coreboot.org/settings
Gerrit-Project: flashrom
Gerrit-Branch: master
Gerrit-Change-Id: I4281213ab02131feb5d47bf66118a001cec0d219
Gerrit-Change-Number: 34160
Gerrit-PatchSet: 1
Gerrit-Owner: Ryan O'Leary
Gerrit-MessageType: newchange
Hello Mario Limonciello, Jacob Garber,
I'd like you to do a code review. Please visit
https://review.coreboot.org/c/flashrom/+/35561
to review the following change.
Change subject: util/getversion,meson: Add script to allow version info with Meson
......................................................................
util/getversion,meson: Add script to allow version info with Meson
Add `util/getversion.sh` that retrieves version information from a
`versioninfo.inc` (what we use for releases) if present or uses
`util/getrevision.sh` if not.
Let Meson use it for flashrom's version. It seems Meson doesn't
generate the manual page at all, so the `--man-date` command is
currently unused.
Change-Id: I401e5638509c4a573bc0cb17ebc5fa76df9700b5
Signed-off-by: Nico Huber <nico.h(a)gmx.de>
---
M meson.build
A util/getversion.sh
2 files changed, 72 insertions(+), 1 deletion(-)
git pull ssh://review.coreboot.org:29418/flashrom refs/changes/61/35561/1
diff --git a/meson.build b/meson.build
index e1b6c16..b475f64 100644
--- a/meson.build
+++ b/meson.build
@@ -1,5 +1,5 @@
project('flashromutils', 'c',
- version : '1.0',
+ version : run_command('util/getversion.sh', '-v').stdout().strip(),
license : 'GPL-2.0+',
meson_version : '>=0.47.0',
default_options : ['warning_level=2', 'c_std=c99'],
diff --git a/util/getversion.sh b/util/getversion.sh
new file mode 100755
index 0000000..d3810d2
--- /dev/null
+++ b/util/getversion.sh
@@ -0,0 +1,71 @@
+#!/bin/sh
+#
+# This file is part of the flashrom project.
+#
+# 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; either version 2 of the License, or
+# (at your option) any later version.
+#
+# 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.
+#
+
+version() {
+ if [ -r versioninfo.inc ]; then
+ v=$(sed -n 's/^VERSION = //p' versioninfo.inc)
+ else
+ v=$($(dirname ${0})/getrevision.sh --revision)
+ if [ $? -ne 0 ]; then
+ v='unknown'
+ fi
+ fi
+
+ echo ${v}
+}
+
+mandate() {
+ if [ -r versioninfo.inc ]; then
+ d=$(sed -n 's/^MAN_DATE = //p' versioninfo.inc)
+ else
+ d=$($(dirname ${0})/getrevision.sh --date flashrom.8.tmpl)
+ if [ $? -ne 0 ]; then
+ d='unknown'
+ fi
+ fi
+
+ echo ${d}
+}
+
+show_help() {
+ echo "Usage:
+ ${0} <command>
+
+Commands
+ -h or --help
+ this message
+ -v or --version
+ return current/release flashrom version
+ -m or --man-date
+ return current/release date of the manual page
+"
+}
+
+if [ $# -ne 1 ]; then
+ show_help
+ echo "Error: Only exactly one command allowed.">&2
+ exit 1
+fi
+
+case $1 in
+ -h|--help) show_help;;
+ -m|--man-date) mandate;;
+ -v|--version) version;;
+ *)
+ show_help
+ echo "Error: Invalid option: $1"
+ exit 1
+ ;;
+esac
--
To view, visit https://review.coreboot.org/c/flashrom/+/35561
To unsubscribe, or for help writing mail filters, visit https://review.coreboot.org/settings
Gerrit-Project: flashrom
Gerrit-Branch: master
Gerrit-Change-Id: I401e5638509c4a573bc0cb17ebc5fa76df9700b5
Gerrit-Change-Number: 35561
Gerrit-PatchSet: 1
Gerrit-Owner: Nico Huber <nico.h(a)gmx.de>
Gerrit-Reviewer: Jacob Garber <jgarber1(a)ualberta.ca>
Gerrit-Reviewer: Mario Limonciello <superm1(a)gmail.com>
Gerrit-MessageType: newchange