[Skiboot] [PATCH stable] pflash: Add --skip option for reading
Joel Stanley
joel at jms.id.au
Tue Nov 13 09:53:27 AEDT 2018
From: Adriana Kobylak <anoo at linux.ibm.com>
Add a --skip=N option to pflash to skip N number of bytes when reading.
This would allow users to print the VERSION partition without the STB
header by specifying the --skip=4096 argument, and it's a more generic
solution rather than making pflash depend on secure/trusted boot code.
Signed-off-by: Adriana Kobylak <anoo at linux.ibm.com>
Reviewed-by: Samuel Mendoza-Jonas <sam at mendozajonas.com>
[stewart: fix up pflash test]
Signed-off-by: Stewart Smith <stewart at linux.ibm.com>
(cherry picked from commit b6ebee077d915916989aa3057239a985981edb07)
Signed-off-by: Joel Stanley <joel at jms.id.au>
---
external/pflash/pflash.c | 26 ++++++++++++++++---
external/pflash/test/results/00-usage.out | 3 +++
.../pflash/test/results/05-bad-numbers.out | 3 +++
3 files changed, 29 insertions(+), 3 deletions(-)
diff --git a/external/pflash/pflash.c b/external/pflash/pflash.c
index 72b90fc895d2..c81520cb9039 100644
--- a/external/pflash/pflash.c
+++ b/external/pflash/pflash.c
@@ -471,7 +471,7 @@ out:
}
static int do_read_file(struct blocklevel_device *bl, const char *file,
- uint32_t start, uint32_t size)
+ uint32_t start, uint32_t size, uint32_t skip_size)
{
int fd, rc = 0;
uint32_t done = 0;
@@ -481,6 +481,9 @@ static int do_read_file(struct blocklevel_device *bl, const char *file,
perror("Failed to open file");
return 1;
}
+ start += skip_size;
+ size -= skip_size;
+
printf("Reading to \"%s\" from 0x%08x..0x%08x !\n",
file, start, start + size);
@@ -644,6 +647,8 @@ static void print_help(const char *pname)
printf("\t\tTarget filename instead of actual flash.\n\n");
printf("\t-S, --side\n");
printf("\t\tSide of the flash on which to operate, 0 (default) or 1\n\n");
+ printf("\t--skip=N\n");
+ printf("\t\tSkip N number of bytes from the start when reading\n\n");
printf("\t-T, --toc\n");
printf("\t\tlibffs TOC on which to operate, defaults to 0.\n");
printf("\t\tleading 0x is required for interpretation of a hex value\n\n");
@@ -709,7 +714,7 @@ int main(int argc, char *argv[])
bool no_action = false, tune = false;
char *write_file = NULL, *read_file = NULL, *part_name = NULL;
bool ffs_toc_seen = false, direct = false, print_detail = false;
- int flash_side = 0;
+ int flash_side = 0, skip_size = 0;
int rc = 0;
while(1) {
@@ -735,6 +740,7 @@ int main(int argc, char *argv[])
{"version", no_argument, NULL, 'v'},
{"debug", no_argument, NULL, 'g'},
{"side", required_argument, NULL, 'S'},
+ {"skip", required_argument, NULL, 'k'},
{"toc", required_argument, NULL, 'T'},
{"clear", no_argument, NULL, 'c'},
{NULL, 0, NULL, 0 }
@@ -826,6 +832,13 @@ int main(int argc, char *argv[])
case 'S':
flash_side = atoi(optarg);
break;
+ case 'k':
+ skip_size = strtoul(optarg, &endptr, 0);
+ if (*endptr != '\0') {
+ rc = 1;
+ no_action = true;
+ }
+ break;
case 'T':
if (!optarg)
break;
@@ -935,6 +948,13 @@ int main(int argc, char *argv[])
goto out;
}
+ /* Skip only supported on read */
+ if (skip_size && !do_read) {
+ fprintf(stderr, "--skip requires a --read command !\n");
+ rc = 1;
+ goto out;
+ }
+
/* Program command should always come with a file */
if (program && !write_file) {
fprintf(stderr, "Program with no file specified !\n");
@@ -1142,7 +1162,7 @@ int main(int argc, char *argv[])
}
rc = 0;
if (do_read)
- rc = do_read_file(flash.bl, read_file, address, read_size);
+ rc = do_read_file(flash.bl, read_file, address, read_size, skip_size);
if (!rc && erase_all)
rc = erase_chip(&flash);
else if (!rc && erase)
diff --git a/external/pflash/test/results/00-usage.out b/external/pflash/test/results/00-usage.out
index 3b54f456c534..caf7b8d8d580 100644
--- a/external/pflash/test/results/00-usage.out
+++ b/external/pflash/test/results/00-usage.out
@@ -43,6 +43,9 @@ Usage: ./pflash [options] commands...
-S, --side
Side of the flash on which to operate, 0 (default) or 1
+ --skip=N
+ Skip N number of bytes from the start when reading
+
-T, --toc
libffs TOC on which to operate, defaults to 0.
leading 0x is required for interpretation of a hex value
diff --git a/external/pflash/test/results/05-bad-numbers.out b/external/pflash/test/results/05-bad-numbers.out
index 211bd6a01d3c..17db6650f591 100644
--- a/external/pflash/test/results/05-bad-numbers.out
+++ b/external/pflash/test/results/05-bad-numbers.out
@@ -43,6 +43,9 @@ Usage: ./pflash [options] commands...
-S, --side
Side of the flash on which to operate, 0 (default) or 1
+ --skip=N
+ Skip N number of bytes from the start when reading
+
-T, --toc
libffs TOC on which to operate, defaults to 0.
leading 0x is required for interpretation of a hex value
--
2.19.1
More information about the Skiboot
mailing list