From 685760905a9037d044cc4b8d1cd0185d0660a2bb Mon Sep 17 00:00:00 2001 From: Shawn Nock Date: Mon, 13 Jan 2020 15:52:55 -0500 Subject: [PATCH] Adds readme, license and small program to dump mtd ioctl magic --- mtd-magic.c | 10 ++++++++++ readme.md | 22 ++++++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 mtd-magic.c create mode 100644 readme.md diff --git a/mtd-magic.c b/mtd-magic.c new file mode 100644 index 0000000..41c465f --- /dev/null +++ b/mtd-magic.c @@ -0,0 +1,10 @@ +#include +#include +#include + +int main(void) { + size_t e = MEMERASE, u = MEMUNLOCK; + printf("const MEMERASE = %lu;\n", e); + printf("const MEMUNLOCK = %lu;\n", u); + return 0; +} diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..f999a8b --- /dev/null +++ b/readme.md @@ -0,0 +1,22 @@ +# update-uboot: Self-contained, Online u-boot updater + +update-uboot is a completely self-contained way to update u-boot. The generated binary includes the updated u-boot binary *and* Linux kernel module to allow +rw access to the (often protected) /dev/mtd0 partition. + +## Installation + +1. Install zig (https://ziglang.org/download/) + + - Requires sentinel-terminated slices, only in master (as of 2020-01-13) or 0.6.0+ + +2. `git clone https://git.sr.ht/~monadnock/zig-mtd` + +3. zig build + +## Modification + +This code only currently supports mipsel out of the box. The only parts specific to mipsel are: + + - mtd-rw.ko; The embedded kernel module is compiled for mipsel. You can replace this file with a version compiled for your arch, or comment out the function if you don't require it. + - uboot-feb2019.bin: Same story. This is the version of u-boot I needed for mt7628 product. You'll almost certainly want to replace this file. Ask your doctor what version of u-boot is right for you + - The ioctl numbers used to ERASE and UNLOCK the mtd are arch specific: https://git.sr.ht/~monadnock/zig-mtd/tree/master/src/mtd.zig#L8 . zig couldn't grok the nested ioctl #define horrors from the mtd headers. The easiest way I've found to determine these magic numbers is to compile the mtd-magic.c file in the repo with your target toolchain and run it on the target. It'll print out the macro expansions (e.g. `mipsel-openwrt-linux-gcc -o mtd-magic mtd-magic.c`)