Commit Graph

68 Commits (1634461bd208f4bd108ea5c3d3f1cf9eb56d4a7e)

Author SHA1 Message Date
Stijn Tintel 4f02496c50 mtd: enable wrgg support for ath79
This is required for the D-Link DAP-2695-A1.

Signed-off-by: Stijn Tintel <stijn@linux-ipv6.be>
4 years ago
Davide Fioravanti c33ad81373 mtd: add linksys_bootcount for ramips
Reset bc is needed for Linksys EA7500 v2's dual boot.

Size impact (tested with Linksys EA7500 v2 @ mt7621):

mtd_25_mipsel_24kc.ipk: 13174 -> 13628 (454 bytes)
initramfs: 3660350 -> 3660688 (338 bytes)

Signed-off-by: Davide Fioravanti <pantanastyle@gmail.com>
[add size impact information]
Signed-off-by: Adrian Schmutzler <freifunk@adrianschmutzler.de>
4 years ago
Adrian Schmutzler e7bfda2c24 brcm63xx: rename target to bcm63xx
This change makes the names of Broadcom targets consistent by using
the common notation based on SoC/CPU ID (which is used internally
anyway), bcmXXXX instead of brcmXXXX.
This is even used for target TITLE in make menuconfig already,
only the short target name used brcm so far.

Signed-off-by: Adrian Schmutzler <freifunk@adrianschmutzler.de>
4 years ago
Adrian Schmutzler 8fe5ad5d33 brcm47xx: rename target to bcm47xx
This change makes the names of Broadcom targets consistent by using
the common notation based on SoC/CPU ID (which is used internally
anyway), bcmXXXX instead of brcmXXXX.
This is even used for target TITLE in make menuconfig already,
only the short target name used brcm so far.

Signed-off-by: Adrian Schmutzler <freifunk@adrianschmutzler.de>
4 years ago
Hauke Mehrtens 1eb34b7287 mtd: Activate LTO compile option
This decreases the size of the mtd application by 25% on MIPS BE.

old:
20,597 /sbin/mtd

new:
16,421 /sbin/mtd

Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
5 years ago
Petr Štetiar d6198d8625 mtd: cleanup unused code and variables in fis.c
While compile checking mtd changes in PR#1359 I've noticed following
compiler warnings and cleaned them up:

 fis.c: In function 'fis_remap':
 fis.c:143:25: warning: variable 'redboot' set but not used [-Wunused-but-set-variable]
   struct fis_image_desc *redboot = NULL;
                         ^~~~~~~
 fis.c:142:25: warning: variable 'fisdir' set but not used [-Wunused-but-set-variable]
   struct fis_image_desc *fisdir = NULL;
                         ^~~~~~

Signed-off-by: Petr Štetiar <ynezz@true.cz>
5 years ago
Daniel Gimpelevich fd104daa2f mtd: add CRC signature to RedBoot partition map
The code for calculating the CRC32 signatures for RedBoot FIS partitions
was already included, but for unknown reasons, it was never invoked. Some
bootloaders enforce checking these for loaded kernels, so they should be
written. This patch does so.

Tested-by: Brian Gonyer <bgonyer@gmail.com>
Signed-off-by: Daniel Gimpelevich <daniel@gimpelevich.san-francisco.ca.us>
5 years ago
Chuanhong Guo e2cd70d6b1 package: mtd: add fixseama command for ath79
This is needed by Qihoo C301.

Signed-off-by: Chuanhong Guo <gch981213@gmail.com>
5 years ago
Linus Walleij 76338fded0 gemini: Fix up firmware checksum on DIR-685
Using the same method as the D-Link DAP-2695 A1 we use
the "mtd" tool to augment the firmware checkum in flash
on first boot of a new firmware on the D-Link DIR-685.
We need to augment the Makefile for "mtd" to build in
the special WRGG fixup support for Gemini as well.

This works around the problem of the machine not booting
after factory install unless the sysupgrade is applied
immediately.

Based on commit e3875350f3
"ar71xx: add support for D-Link DAP-2695 rev. A1"

Cc: Stijn Tintel <stijn@linux-ipv6.be>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
5 years ago
Linus Walleij 30b4b7ee09 mtd: Make fixwrgg command work on DIR-685
The D-Link DIR-685 has the same problem as the
D-Link DAP-2695: when flashing the factory image, the
checksum includes the whole flashed image, even the
rootfs_data part with the end of filesystem mark.
Also the whole flashed image is stored in the flash,
so on the first boot, the whole rootfs image is loaded
into memory with the kernel.

This is fixed using the fixwrgg command to mtd, but
for this to work we need to make fixwrgg work with
the Little-Endian ARM DIR-685.

The code tries to be endian agnostic but this fails
because the WRGG image loader doesn't. On ARM, the
file size is stored in little endian format, and on
big-endian systems it is stored in big endian format,
so we can just drop all the friendly htonl() that
will make the shdr->size big endian: this will
actually break the little endian systems, and on
the big endian systems the native endianness will
still be correct.

The magic number is always stored in little endian
format however, so make sure this is always read
in LE32 format. I chose to create a straight-forward
le32_to_cpu() static inline that IMO is simple and
easy to read.

Cc: Stijn Tintel <stijn@linux-ipv6.be>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
5 years ago
Jeff Kletsky b3770eaca3 mtd: base-files: Unify dual-firmware devices (Linksys)
Consistently handle boot-count reset and upgrade across
ipq40xx, ipq806x, kirkwood, mvebu

Dual-firmware devices often utilize a specific MTD partition
to record the number of times the boot loader has initiated boot.

Most of these devices are NAND, typically with a 2k erase size.
When this code was ported to the ipq40xx platform, the device in hand
used NOR for this partition, with a 16-byte "record" size. As the
implementation of `mtd resetbc` is by-platform, the hard-coded nature
of this change prevented proper operation of a NAND-based device.

* Unified the "NOR" variant with the rest of the Linksys variants

* Added logging to indicate success and failure

* Provided a meaningful return value for scripting

* "Protected" the use of `mtd resetbc` in start-up scripts so that
   failure does not end the boot sequence

* Moved Linksys-specific actions into common `/etc/init.d/bootcount`

For upgrade, these devices need to determine which partition to flash,
as well as set certain U-Boot envirnment variables to change the next
boot to the newly flashed version.

* Moved upgrade-related environment changes out of bootcount

* Combined multiple flashes of environment into single one

* Current-partition detection now handles absence of `boot_part`

Runtime-tested: Linksys EA8300

Signed-off-by: Jeff Kletsky <git-commits@allycomm.com>
Signed-off-by: Christian Lamparter <chunkeey@gmail.com>
[checkpatch.pl fixes, traded split strings for 80+ chars per line]
5 years ago
David Bauer 1e06482f7d 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>
5 years ago
Oever González c43acdf342 mtd: add linksys_bootcount to the ipq40xx target
This commit adds the object 'linksys_bootcount_fix.o' to the ipq40xx
target.

This is needed for the Linksys EA6350v3 device. Without this patch, the
device will switch-back between the current and the last flashed firmware
every 3 (three) reboots. With this patch, the device works as expected.

Signed-off-by: Ryan Pannell <ryan@osukl.com>
Signed-off-by: Oever González <notengobattery@gmail.com>
5 years ago
Rafał Miłecki 82498a7f7a mtd: improve check for TRX header being already fixed
First of all lengths should be compared after checking all blocks for
being good/bad. It's because requested length may differ from a final
one if there were some bad blocks.

Secondly it makes sense to also compare crc32 since we already have a
new one calculated.

Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
6 years ago
Rafał Miłecki 0f54489f75 mtd: support bad blocks within the mtd_fixtrx()
Reading MTD data with (p)read doesn't return any error when accessing
bad block. As the result, with current code, CRC32 covers "data" stored
in bad blocks.

That behavior doesn't match CFE's one (bootloader simply skips bad
blocks) and may result in:
1) Invalid CRC32
2) CFE refusing to boot firmware with a following error:
Boot program checksum is invalid

Fix that problem by checking every block before reading its content.

Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
6 years ago
Mirko Parthey 46d7ced9d1 mtd: mark as nonshared to fix FS#484
The mtd tool is built with different configurations depending on the
target. For example, brcm47xx adds the fixtrx subcommand, without which
an image fails when booting the second time.

Mark the mtd package as nonshared to really fix FS#484.

Signed-off-by: Mirko Parthey <mirko.parthey@web.de>
6 years ago
Felix Fietkau d92ec071b2 mtd: fix erase handling with partition offset on write
When a partition offset is given, it is used in an lseek call, which
affects write, but not erase. Add it to the offset for erase calls as
well

Signed-off-by: Felix Fietkau <nbd@nbd.name>
6 years ago
George Hopkins 13f9e40602 ramips: add support for D-Link DAP-1522 A1
D-Link DAP-1522 is a wireless bridge/access point with 4 LAN
ports and a dual-band wireless chipset.

Specifications:
- Ralink RT2880
- 32 MB of RAM
- 4 MB of Flash
- 4x 10/100/1000 Mbps Ethernet (RTL8366SR)
- 802.11abgn (RT2850)

Flash Instructions:
1. Download lede-ramips-rt288x-dap-1522-a1-squashfs-factory.bin
2. Open the web interface and upload the image

Signed-off-by: George Hopkins <george-hopkins@null.net>
6 years ago
George Hopkins 5203355062 mtd: add fixwrg command
Add a command to fix WRG headers, based on wrgg.c.

Signed-off-by: George Hopkins <george-hopkins@null.net>
6 years ago
Stijn Tintel 9dfed03c35 mtd: add fixwrgg command
Based on fixseama.

Signed-off-by: Stijn Tintel <stijn@linux-ipv6.be>
Acked-by: John Crispin <john@phrozen.org>
8 years ago
Stijn Tintel dec29082e0 mtd: fix endianness detection on musl
Signed-off-by: Stijn Tintel <stijn@linux-ipv6.be>
Acked-by: John Crispin <john@phrozen.org>
8 years ago
Paul Wassi da1b33fc4d package/system/mtd: fix usage message
Minor fix in the usage message on the explanation of the -p option.

Signed-off-by: Paul Wassi <p.wassi@gmx.at>
8 years ago
Alexandru Ardelean 8ecf7443a4 system/mtd: drop Build/Prepare rule in favor of default one
Signed-off-by: Alexandru Ardelean <ardeleanalex@gmail.com>
8 years ago
John Crispin c66658441b mtd: fix up error messages
remove the "Error fixing up TRX header" message which is misleading.

Signed-off-by: John Crispin <john@phrozen.org>
8 years ago
Josua Mayer 1e71fca777 mtd: fix building with glibc
src/linksys_bootcount.c misses to include stdint.h.
Apparently musl doesn't mind and includes this header by default,
but glibc does not and causes the build to fail.

Signed-off-by: Josua Mayer <josua.mayer97@gmail.com>
8 years ago
Rafał Miłecki 7e08f2ccbd mtd: support -c (datasize) option for fixseama command
Signed-off-by: Rafał Miłecki <zajec5@gmail.com>
8 years ago
Adrian Panella 2177a2a8cb mtd: add linksys_bootcount for ipq806x
Reset bc is needed for Linksys EA8500's dual boot.

Signed-off-by: Adrian Panella <ianchi74@outlook.com>
8 years ago
Rafał Miłecki 4b03e4ac3b mtd: fix typo in error message for 'c' option
Signed-off-by: Rafał Miłecki <zajec5@gmail.com>
8 years ago
Felix Fietkau 7eeb254cc4 treewide: replace nbd@openwrt.org with nbd@nbd.name
Signed-off-by: Felix Fietkau <nbd@nbd.name>
8 years ago
Rafał Miłecki b9afc86b5c mtd: imagetag: fix compilation with changed mtd_fixtrx call
Function mtd_fixtrx was changed during trx improvements.

Signed-off-by: Rafał Miłecki <zajec5@gmail.com>
8 years ago
Rafał Miłecki df8ca9a5c4 mtd: add -c option for specifying amount of data to be used for checksum
So far fixtrx was calculating checksum over amount of data matching
partition erase size. It was mostly a workaround of checksum problem
after changing anything in initial TRX content (e.g. formatting JFFS2).
Its main purpose was to make bootloader accept modified TRX. This didn't
provide much protection of flash data against corruption.

This new option lets caller request calculating checksum over a bigger
amount of data. It may be used e.g. to include whole kernel data for
checksum and hopefully make bootloader go info failsafe mode if
something goes wrong.

Signed-off-by: Rafał Miłecki <zajec5@gmail.com>
8 years ago
Rafał Miłecki 2dd125048d mtd: trx: use separated buffer for TRX header
We plan to adjust usage of the main buffer to allow reading custom
amount of data for CRC32. This means we need another buffer that will be
always block aligned.

Signed-off-by: Rafał Miłecki <zajec5@gmail.com>
8 years ago
rmilecki 6de401b1f8 mtd: seama: exit with error if Seama header wasn't found
Signed-off-by: Rafał Miłecki <zajec5@gmail.com>
8 years ago
rmilecki 06a3241c27 mtd: seama: fix image data handling
1) Put sanity checks in one place
2) Respect provided offset
3) Read only as much data as needed for MD5 calculation

Thanks to the last change this is a great speedup and memory saver. On
devices with NAND flash we were allocating & reading about 128 MiB while
something about 8 MiB is enough.

Signed-off-by: Rafał Miłecki <zajec5@gmail.com>
8 years ago
rmilecki 30edc32888 mtd: seama: move buf allocation to the MD5 function
This buf is only used in this function now, so lets move it there.

Signed-off-by: Rafał Miłecki <zajec5@gmail.com>
8 years ago
rmilecki 1d628f0cbe mtd: seama: update MD5 using header in the first block buffer
This will allow separating first block buffer from a buffer used for MD5
calculation.

Signed-off-by: Rafał Miłecki <zajec5@gmail.com>
8 years ago
rmilecki bcccb03200 mtd: seama: add md5 to header struct
This allows us to drop some extra offset calculations and simplifies
code a bit.

Signed-off-by: Rafał Miłecki <zajec5@gmail.com>
8 years ago
rmilecki 8632d89fa0 mtd: check for Seama magic early when fixing MD5
This avoid long (and unneeded) process of reading all data in case of
running on MTD not containig Seama entity.

Signed-off-by: Rafał Miłecki <zajec5@gmail.com>
8 years ago
rmilecki 320641585b mtd: add missing breaks in a switch
On platforms supporting both: TRX and Seama calling "fixtrx" was
resulting in trying to fix Seama as well.

Signed-off-by: Rafał Miłecki <zajec5@gmail.com>
8 years ago
rmilecki 8a60a41951 mtd: use tabs for indents
This makes code style consistent across the whole file.

Signed-off-by: Rafał Miłecki <zajec5@gmail.com>
8 years ago
John Crispin 4a4c324cd2 mtd: fix reading of image magic bytes in smaller chunks
The image_check currently fails when it cannot read all magic bytes in a
single chunk. But this can happen when the data are read from a pipe. This
currently breaks the openmesh.sh upgrade script with musl because it uses
dd with a blocksize of 1 to copy the image file to the mtd process.

The read can simply be repeated until enough bytes are read for the magic
byte check. It only stops when either an error was returned or 0 bytes were
read.

Signed-off-by: Sven Eckelmann <sven.eckelmann@open-mesh.com>

SVN-Revision: 48891
8 years ago
Rafał Miłecki 358ae42152 mtd: fix Seama format after replacing EOF with sysupgrade data
Seama header has MD5 similarly to TRX and its CRC32. We need to update
it after replacing anything in Seama entity content to make bootloader
accept it.

Signed-off-by: Rafał Miłecki <zajec5@gmail.com>

SVN-Revision: 48688
8 years ago
Rafał Miłecki b5c41ad28c mtd: detect image format when writing
Recently TRX checking code was changed to detect Seama format and don't
abort whole writing operation because of it. This isn't a good long-term
solution. It's a poor idea to teach every format handler recognizing all
possible formats. Instead it should be handled in a generic code which
should run check depending on the detected format.

This will also allow further improvements like fixing formats other than
TRX after replacing JFFS2.

Signed-off-by: Rafał Miłecki <zajec5@gmail.com>

SVN-Revision: 48639
8 years ago
Rafał Miłecki b4468a0d61 mtd: allow writing Seama files to "firmware" on Broadcom targets
Signed-off-by: Rafał Miłecki <zajec5@gmail.com>

SVN-Revision: 48534
8 years ago
Rafał Miłecki 60ef46b903 mtd: enable "fixseama" on bcm53xx
There are D-Link bcm53xx devices using Seama format.

Signed-off-by: Rafał Miłecki <zajec5@gmail.com>

SVN-Revision: 48521
8 years ago
Luka Perkov ea8ac0999c kirkwood: support Linksys boot counter on EA[34]500
This is done with existing code from the WRT1900AC port.
It makes sure the "auto_recovery" bootloader option is set,
and resets the s_env boot counter after a successful boot.

This gives users without a serial console connection some
measure of safety.

Signed-off-by: Claudio Leite <leitec@staticky.com>

SVN-Revision: 47433
9 years ago
Imre Kaloz 20fac016e4 mvebu: add support for the Linksys boot counter
The u-boot boot counter was never reset after a successful boot,
which sometimes could make some variables become out of sync.
This patch adds support for the boot counter and enables
auto_recovery unconditionally.

Signed-off-by: Jonas Gorski <jogo@openwrt.org>
Signed-off-by: Rob Mosher <nyt-openwrt@countercultured.net>
Signed-off-by: Imre Kaloz <kaloz@openwrt.org>

SVN-Revision: 46690
9 years ago
Felix Fietkau 9e233fb241 mtd: add missing <endian.h> include
trx.c in mtd would not include endian.h, so on systems that do not have
this header implicitly included from the other headers (like musl), both
__BYTE_ORDER and __BIG_ENDIAN would be undefined and thus 0, leading to
it always presuming a big-endian system. this would lead to issues when
running mtd fixtrx on little-endian systems, as it would never recognize
the TRX magic as result of the broken STORE32_LE() macro.

Signed-off-by: Shiz <hi@shiz.me>
Tested-by: Shiz <hi@shiz.me>

SVN-Revision: 45896
9 years ago
John Crispin b48b7a7689 mtd: fix md5sum error checking
In mtd_verify(), the return value of md5sum() has been
interpreted as error if nonzero, while the function
returns number of processed bytes, which caused
mtd_verify() to always fail.

This patch fixes error checking to interpret only
negative values as errors.

Signed-off-by: Zefir Kurtisi <zefir.kurtisi@neratec.com>

SVN-Revision: 44605
9 years ago
Jonas Gorski 92eb27f56d package: mtd: move bcm963xx_tag definition into source code
Remove the need for the header file to be exported - we don't need most
of it anyway; all we care about are the offset of the rootfs length and
header crc fields.

Signed-off-by: Jonas Gorski <jogo@openwrt.org>

SVN-Revision: 44557
9 years ago