From 977aa1ef5fa6d5645edaf72a3167638a46f89486 Mon Sep 17 00:00:00 2001 From: Adriana Kobylak Date: Tue, 13 Nov 2018 09:23:27 +1030 Subject: pflash: Add --skip option for reading 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 Reviewed-by: Samuel Mendoza-Jonas [stewart: fix up pflash test] Signed-off-by: Stewart Smith (cherry picked from commit b6ebee077d915916989aa3057239a985981edb07) Signed-off-by: Joel Stanley Signed-off-by: Stewart Smith --- external/pflash/pflash.c | 26 ++++++++++++++++++++++--- external/pflash/test/results/00-usage.out | 3 +++ external/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 72b90fc..c81520c 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 3b54f45..caf7b8d 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 211bd6a..17db665 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 -- cgit v1.1