aboutsummaryrefslogtreecommitdiffstats
path: root/package/system/mtd/src/mtd.c
diff options
context:
space:
mode:
authorDavid Bauer <mail@david-bauer.net>2018-12-31 16:24:25 +0100
committerMathias Kresin <dev@kresin.me>2019-01-26 21:46:32 +0100
commit1e06482f7db284567b240ce6f59c644439ec813f (patch)
tree6671fac8711f91e3b37c746f6d4b9b6b6199cd90 /package/system/mtd/src/mtd.c
parent36a091cb076dda891e3b41ae3080f858f88697c3 (diff)
downloadupstream-1e06482f7db284567b240ce6f59c644439ec813f.tar.gz
upstream-1e06482f7db284567b240ce6f59c644439ec813f.tar.bz2
upstream-1e06482f7db284567b240ce6f59c644439ec813f.zip
mtd: add logic for TP-Link ramips recovery magic
This adds an option to set the recovery flag of newer TP-Link MediaTek boards and remove it after a successful write. To make use of this feature, add the '-t' option to mtd-write. The '-t' option takes the mtd partition containing the recovery flag (usually 'romfile') as an argument. Make sure this partition is not flagged as read-only! Example: > mtd -t romfile write owrt.bin firmware This command writes the recovery-flag before it begins writing the image to the firmware partition. After the image-write has been successful, the recovery flag is removed. This way, the TP-Link web-recovery is automatically enabled on an unsucessful flash (e.g. power loss). This option is only available if the mtd package is compiled for the ramips target. Signed-off-by: David Bauer <mail@david-bauer.net>
Diffstat (limited to 'package/system/mtd/src/mtd.c')
-rw-r--r--package/system/mtd/src/mtd.c33
1 files changed, 32 insertions, 1 deletions
diff --git a/package/system/mtd/src/mtd.c b/package/system/mtd/src/mtd.c
index fa04c0f95b..eccb4f6a1a 100644
--- a/package/system/mtd/src/mtd.c
+++ b/package/system/mtd/src/mtd.c
@@ -85,6 +85,7 @@ static char *buf = NULL;
static char *imagefile = NULL;
static enum mtd_image_format imageformat = MTD_IMAGE_FORMAT_UNKNOWN;
static char *jffs2file = NULL, *jffs2dir = JFFS2_DEFAULT_DIR;
+static char *tpl_uboot_args_part;
static int buflen = 0;
int quiet;
int no_erase;
@@ -554,6 +555,17 @@ resume:
lseek(fd, part_offset, SEEK_SET);
}
+ /* Write TP-Link recovery flag */
+ if (tpl_uboot_args_part && mtd_tpl_recoverflag_write) {
+ if (quiet < 2)
+ fprintf(stderr, "Writing recovery flag to %s\n", tpl_uboot_args_part);
+ result = mtd_tpl_recoverflag_write(tpl_uboot_args_part, true);
+ if (result < 0) {
+ fprintf(stderr, "Could not write TP-Link recovery flag to %s: %i", mtd, result);
+ exit(1);
+ }
+ }
+
indicate_writing(mtd);
w = e = 0;
@@ -716,6 +728,18 @@ resume:
#endif
close(fd);
+
+ /* Clear TP-Link recovery flag */
+ if (tpl_uboot_args_part && mtd_tpl_recoverflag_write) {
+ if (quiet < 2)
+ fprintf(stderr, "Removing recovery flag from %s\n", tpl_uboot_args_part);
+ result = mtd_tpl_recoverflag_write(tpl_uboot_args_part, false);
+ if (result < 0) {
+ fprintf(stderr, "Could not clear TP-Link recovery flag to %s: %i", mtd, result);
+ exit(1);
+ }
+ }
+
return 0;
}
@@ -771,6 +795,10 @@ static void usage(void)
fprintf(stderr,
" -c datasize amount of data to be used for checksum calculation (for fixtrx / fixseama / fixwrg / fixwrgg)\n");
}
+ if (mtd_tpl_recoverflag_write) {
+ fprintf(stderr,
+ " -t <partition> write TP-Link recovery-flag to <partition> (for write)\n");
+ }
fprintf(stderr,
#ifdef FIS_SUPPORT
" -F <part>[:<size>[:<entrypoint>]][,<part>...]\n"
@@ -828,7 +856,7 @@ int main (int argc, char **argv)
#ifdef FIS_SUPPORT
"F:"
#endif
- "frnqe:d:s:j:p:o:c:l:")) != -1)
+ "frnqe:d:s:j:p:o:c:t:l:")) != -1)
switch (ch) {
case 'f':
force = 1;
@@ -896,6 +924,9 @@ int main (int argc, char **argv)
usage();
}
break;
+ case 't':
+ tpl_uboot_args_part = optarg;
+ break;
#ifdef FIS_SUPPORT
case 'F':
fis_layout = optarg;