X-Git-Url: https://git.rohieb.name/openwrt.git/blobdiff_plain/053826c1ef378f54fdc45240a7c622f6610756c7..76389a5662973443eb024ca5ee452fa48c810fa4:/package/mtd/src/mtd.c diff --git a/package/mtd/src/mtd.c b/package/mtd/src/mtd.c index f5acb1eff..9025240e1 100644 --- a/package/mtd/src/mtd.c +++ b/package/mtd/src/mtd.c @@ -28,19 +28,22 @@ #include #include #include +#include +#include #include #include #include #include +#include #include #include #include #include #include #include -#include +#include -#include +#include "mtd.h" #define TRX_MAGIC 0x30524448 /* "HDR0" */ #define BUFSIZE (16 * 1024) @@ -81,22 +84,11 @@ image_check_brcm(int imagefd, const char *mtd) return 0; } - switch(trx->magic) { - case 0x47343557: /* W54G */ - case 0x53343557: /* W54S */ - case 0x73343557: /* W54s */ - case 0x46343557: /* W54F */ - case 0x55343557: /* W54U */ - /* ignore the first 32 bytes */ - buflen = read(imagefd, buf, sizeof(struct trx_header)); - break; - } - if (trx->magic != TRX_MAGIC || trx->len < sizeof(struct trx_header)) { if (quiet < 2) { fprintf(stderr, "Bad trx header\n"); - fprintf(stderr, "If this is a firmware in bin format, like some of the\n" - "original firmware files are, you need to convert it to trx.\n"); + fprintf(stderr, "This is not the correct file format; refusing to flash.\n" + "Please specify the correct file or use -f to force.\n"); } return 0; } @@ -194,13 +186,18 @@ mtd_open(const char *mtd, int flags) FILE *fp; char dev[PATH_MAX]; int i; + int ret; if ((fp = fopen("/proc/mtd", "r"))) { while (fgets(dev, sizeof(dev), fp)) { if (sscanf(dev, "mtd%d:", &i) && strstr(dev, mtd)) { snprintf(dev, sizeof(dev), "/dev/mtd/%d", i); + if ((ret=open(dev, flags))<0) { + snprintf(dev, sizeof(dev), "/dev/mtd%d", i); + ret=open(dev, flags); + } fclose(fp); - return open(dev, flags); + return ret; } } fclose(fp); @@ -458,8 +455,10 @@ int main (int argc, char **argv) sync(); - if (boot) - kill(1, 15); // send SIGTERM to init for reboot - + if (boot) { + fprintf(stderr, "Rebooting ...\n"); + fflush(stderr); + syscall(SYS_reboot,LINUX_REBOOT_MAGIC1,LINUX_REBOOT_MAGIC2,LINUX_REBOOT_CMD_RESTART,NULL); + } return 0; }