Commit Graph

54 Commits (e0ce80d42ace6feba509da16795ab0eb81cf5bf4)

Author SHA1 Message Date
Oldřich Jedlička e0ce80d42a kernel: Fix off-by-one error in FIT mtd partition search.
This fixes off-by-one error introduced in commit dc76900021
("kernel: Correctly search for the FIT image in mtd partition.")

Function `mtd_read` starts reading at `offset` and
needs `hdr_len` number of bytes to be available. Suppose
the easiest case when `offset` is `0` and `hdr_len` equals
to `mtd->size` - the `for` loop will not be entered even
when enough bytes are available to be read.

Same happens for any non-zero `offset`, when `hdr_len` is
just enough bytes to be read until `mtd->size` is reached.
Imagine that for example `mtd->size=5`, `offset=4` and
`hdr_len=1`. Then `offset+hdr_len=5` and the check has to
be `offset+hdr_len <= mtd->size`, i.e. `5 <= 5`. The
check for `offset + hdr_len` value needs to be inclusive,
therefore use `<=`.

Fixes: dc76900021 ("kernel: Correctly search for the FIT image in mtd partition.")
Signed-off-by: Oldřich Jedlička <oldium.pro@gmail.com>
[adjusted commit ref, fixes tag]
Signed-off-by: Petr Štetiar <ynezz@true.cz>
5 years ago
Fredrik Olofsson dc76900021 kernel: Correctly search for the FIT image in mtd partition.
Previously all iterations of the loop checked offset=0 in the partition.

Signed-off-by: Fredrik Olofsson <fredrik.olofsson@anyfinetworks.com>
5 years ago
Chuanhong Guo 1d6368ee73 kernel: mtdsplit_uimage: add support for okli image
This adds support for uImage used by OpenWrt kernel loader.
The parser searches for uImage header at flash eraseblock boundary
and it might attempt to split any firmware with loader, therefore
this entry doesn't have MTD_PARSER_TYPE_FIRMWARE so that this parser
is only used when explicitly defined in dts.

Signed-off-by: Chuanhong Guo <gch981213@gmail.com>
5 years ago
Rafał Miłecki c4492dd70e kernel: drop Fon(Foxconn) parser matching for the "firmware" partition
This parser's matching function appears to be too generic as it matches
e.g. Buffalo WZR-HP-G300NH. That results in incorrect parts parsing.

Luckily this parser is needed by Fon FON2601 only which uses DT-based
ramips target. It means we can depend on mtd subsystem matching of
"fonfxc,uimage" string.

That said triggering this parser based on the "firmware" (or whatever
MTD_SPLIT_FIRMWARE_NAME is) partiiton name is not needed. It can be
dropped which will automatically fix the Buffalo WZR-HP-G300NH case.

Fixes: a1c6a316d2 ("ramips: add support for Fon FON2601")
Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
5 years ago
Rafał Miłecki 4b755ce06a Revert "kernel: generic: fix fonfxc uimage parser"
This reverts commit e92a14709d.

mtdsplit_uimage_parse_fonfxc() gets called in two situations:
1) It was /requested/ from DT using "fonfxc,uimage" compatible string
2) It was called by parsing code after finding "firmware"
   (MTD_SPLIT_FIRMWARE_NAME) due to the parser's type

Code added in the /fix/ commit basically just disabled the second case.
If that's the real goal it could be achieved by simply dropping type
MTD_PARSER_TYPE_FIRMWARE. It may however require another solution as
it's possible that some non-DT target actually needs fonfxc uImage
parsing.

Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
5 years ago
NOGUCHI Hiroshi e92a14709d kernel: generic: fix fonfxc uimage parser
We cannot distinguish between fonfxc uImage and generic uImage because
fonfxc uImage header is almost same as generic uImage, except padding
length after image name.

The fonfxc uImage parser is available when specifying directly with DT
compatible property.  So this patch adds check if the partition DT node
is compatible with the parser.

Ref: https://bugs.openwrt.org/index.php?do=details&task_id=2413
Fixes: a1c6a316d2 ("ramips: add support for Fon FON2601")
Signed-off-by: NOGUCHI Hiroshi <drvlabo@gmail.com>
[commit light touches and removed C code comment]
Signed-off-by: Petr Štetiar <ynezz@true.cz>
5 years ago
NOGUCHI Hiroshi a1c6a316d2 ramips: add support for Fon FON2601
FON2601 is a wireless router.

Specification:
- SoC: Mediatek MT7620A (580MHz)
- RAM: 128 MiB
- ROM: 16 MiB SPI Flash
- Wireless:
   for 11b/g/n (upto 300 Mbps):  MT7620A built-in WMAC
   for 11a/n/ac (upto 867 Mbps): MT7662E
- Ethernet LAN: 1 port, upto 100 Mbps
- Ethernet WAN: 1 port, upto 1000 Mbps
- USB: 1 port (USB 2.0 host)
- LEDs: 4 (all can be controlled by SoC's GPIO)
- buttons: 1 (Displayed as "WPS" on enclosure)
- serial port: 57600n8
 pins: Vcc(3.3V), Rx, Tx, GND
(left to right, viewed from outside of board)

Installation (only available via UART):
  1. download sysupgrade binary image by wget command
  2. write sysupgrade binary image to Flash
     command is:
       mtd write sysupgrade.bin firmware
  3. reboot

Important Notice:
  Only one button is displayed as "WPS" on enclosure.
  However, it is configured as "reset" (factory resetting feature).

Signed-off-by: NOGUCHI Hiroshi <drvlabo@gmail.com>
[removed unrelated openwrt-keyring revert, missing -Wall for uimage_padhdr]
Signed-off-by: Petr Štetiar <ynezz@true.cz>
5 years ago
Hauke Mehrtens 8ef6240fa6 kernel: Add missing includes mtdsplit_*.c
This fixes the following compile problem with kernel 4.9 on lantiq:
drivers/mtd/mtdsplit/mtdsplit_uimage.c:244:34: error: array type has incomplete element type 'struct of_device_id'
 static const struct of_device_id mtdsplit_uimage_of_match_table[] = {
                                  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/mtd/mtdsplit/mtdsplit_uimage.c:245:4: error: field name not in record or union initializer
  { .compatible = "denx,uimage" },

Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
5 years ago
Linus Walleij b907097291 kernel: mtdsplit: wrgg: Support big and little endian
The WRGG images exist in both big and little endian variants,
as can be seen from the image generator in
tools/firmware-utils/src/mkwrggimg.c, you either pass
the "-b" flag or not. The D-Link DIR-685 is using little
endian images so we need to support splitting these.

Detect endianness like this: if the kernel entity size
gets silly big (bigger than the flash memory) we are
probably using the wrong endianness.

Example: my kernel of 0x0067ff64 was switched around by
wrong endianness and detected as 0x64ff67a0 (the actual
size in swapped endianness + header 0xa0).

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Christian Lamparter <chunkeey@gmail.com>
5 years ago
Mathias Kresin 116d0f276d kernel: add DT binding support to the Edimax uImage parser
It allows specifying those parsers directly in the DT.

Signed-off-by: Mathias Kresin <dev@kresin.me>
5 years ago
Christian Lamparter 40180b6305 kernel: add DT binding support to the fit parser
It allows specifying default and Netgear parsers directly in the DT.

Signed-off-by: Christian Lamparter <chunkeey@gmail.com>
6 years ago
Rafał Miłecki 816ae87709 kernel: drop unneeded LINUX_VERSION_CODE checks
All those parsers are used by 4.14 targets. They don't need that
backward compatibility code.

Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
6 years ago
Rafał Miłecki 2abb128f2e kernel: add DT binding support to the LZMA and WRG parsers
It allows specifying those parsers directly in the DT.

Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
6 years ago
Rafał Miłecki 4d3a53b9ef kernel: add DT binding support to the TRX and minor parsers
It allows specifying those parsers directly in the DT.

Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
6 years ago
David Bauer 68e59b61c6 kernel: add DT binding support to AVM EVA parser
It allows selecting split-firmware parser directly by
specifying image-format in the device-tree.

Signed-off-by: David Bauer <mail@david-bauer.net>
6 years ago
Pawel Dembicki b5597d5cc9 kernel: add DT binding support to the jimage parser
It allows specifying jimage parser directly in the DT.

Tested on LAVA LR-25G001

Signed-off-by: Pawel Dembicki <paweldembicki@gmail.com>
6 years ago
Rafał Miłecki f995e143ba kernel: add missing version.h include to the TP-LINK parser
Fixes: a29c8d685b ("kernel: add DT binding support to the TP-LINK parser")
Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
6 years ago
Rafał Miłecki a29c8d685b kernel: add DT binding support to the TP-LINK parser
It allows triggering it directly by specifying format in the DT.

Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
6 years ago
Rafał Miłecki a22311e6a6 kernel: add DT binding support to the uimage parsers
It allows specifying default and Netgear parsers directly in the DT.

Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
6 years ago
Rafał Miłecki dab5a93086 kernel: add DT binding support to the Seama parser
It allows specifying that parser directly in the DT.

Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
6 years ago
George Hopkins 5c7a58764e kernel: mtdsplit: split by WRG header
Support splitting WRG images, which can be found in older
D-Link devices.

Signed-off-by: George Hopkins <george-hopkins@null.net>
6 years ago
Pawel Dembicki 680e867d7f kernel: mtdsplit: Add support for D-link JBOOT
The D-Link devices with JBOOT bootloader use their own kernel
image header (stag + sch2 headers).

This driver find jImage header and set rootfs start after kernel file.

Signed-off-by: Pawel Dembicki <paweldembicki@gmail.com>
6 years ago
Thibaut VARÈNE 74f891752b generic: make mtdsplit-tplink.c honor rootfs offset
The splitter ignored the rootfs offset from the header, probably
because until c1e6e61 it was invalid.

This patch fixes the splitter to use the now correct header data.

Regarding target/linux/ar71xx/files/drivers/mtd/tplinkpart.c,
this particular splitter "falls back" to the correct rootfs offset
reading and as such it doesn't need to be updated, although it will
report a kernel partition length that can be larger than the actual
length as it assumes that partition fills the entire segment up to
the rootfs partition.

Tested-by: Mathias Kresin <dev@kresin.me>
Tested-by: Stefan Lippers-Hollmann <s.l-h@gmx.de>
Tested-by: Daniel Engberg <daniel.engberg.lists@pyret.net>
Tested-by: Henryk Heisig <hyniu@o2.pl>
Signed-off-by: Thibaut VARÈNE <hacks@slashdirt.org>
7 years ago
Thibaut VARENE 890daca9e2 kernel: mtdsplit: Add support for Mikrotik NOR firmware
The RouterBOOT bootloader does not care where the kernel lives in the SPI
flash, all that matters is that the kernel is wrapped in the custom yaffs
container as generated by kernel2minor.

This container has a fixed signature as follows:
00000000  00 00 00 01 00 00 00 01  ff ff 6b 65 72 6e 65 6c  |..........kernel|

This patch adds mtdsplit support for identifying that signature and
triggering the search for the rootfs. rootfs is expected at EB boundary since
we use wget mtd_find_rootfs_from(). We make no use of the yaffs file size
field because it contains invalid data in the image generated by kernel2minor.

Signed-off-by: Thibaut VARENE <hacks@slashdirt.org>
7 years ago
Koen Vandeputte 4339e5ddb1 kernel: fix build error in mtdsplit driver
Add missing parentheses.
Fixes kernel build issue when using this driver.

Signed-off-by: Koen Vandeputte <koen.vandeputte@ncentric.com>
7 years ago
Felix Fietkau 402193baa1 kernel: update mtdsplit for linux 4.9
add backport patches for older kernels

Signed-off-by: Felix Fietkau <nbd@nbd.name>
7 years ago
Huan Truong fd62fa752b ar71xx: Add support for Netgear WNR2000v1
This patch adds supports for the WNR2000v1 board with 4MB flash, and
produces device-specific factory, rootfs, and sysupgrade files for the
WNR2000v1. This board is errorneously claimed as supported on the OpenWRT
wiki as AP81, but AP81 image would not work because of APT81 image
requiring having 8MB of flash, while WNR2000v1 has only 4MB.

The image requires the u-boot bootloader to be modified to fuhry's
bootloader first.

Short specification:

- CPU: Atheros AR9132
- 4x 10/100 Mbps Ethernet, 1x WAN 10/100 Mbps
- 4 MB of Flash
- 32 MB of RAM
- UART header (J1) on board
- 1x button

Factory/Initial flash instructions:

- Set up a TFTP server on your local machine.
- Download the uImage for ar71xx-generic and the rootfs image for
  ar71xx-generic-wnr2000 and save in the tftp server root.
- Gain serial access to the router via the UART port (telnetenable over
  the network only won't work!).
- Upgrade the u-boot bootloader to fuhry's version by running the
  script: http://fuhry.com/b/wnr2000/install-repart.sh
- When the router restarts, interrupt u-boot and gain access to u-boot command line.
- Repartititon the board and flash initial uImage and rootfs as follow.

Commands to type in u-boot:

	# tells u-boot that we have a tftp server on 192.168.1.10
	setenv serverip 192.168.1.10

	# tells u-boot that the router should take the address 192.168.1.1
	setenv ipaddr 192.168.1.1

	# erase the region from 0x050000-0x3f0000
	erase 0xbf050000 +0x3A0000

	# loads sqfs.bin on TFTP server, and put it to memory address 0x81000000
	tftpboot 0x81000000 sqfs.bin
	# it will tell you the length of sqfs.bin in hex, let's say ZZZZZZ
	# copy bit by bit 0xZZZZZZ bytes from offset 0x050000
	cp.b 0x81000000 0xbf050000 0xZZZZZZ

	# same to the uImage.bin, write it right next to sqfs.bin
	# again, 0xYYYYYY is the length that tftpboot reports
	tftpboot 0x81000000 uImage.bin
	cp.b 0x81000000 0xbf2a0000 0xYYYYYY

	# We need to tell the kernel what board it is booting into, and where to find the partitions
	setenv bootargs "board=WNR2000 console=ttyS0,115200 mtdparts=spi0.0:256k(u-boot)ro,64k(u-boot-env)ro,3712k(firmware),64k(art)ro rootfstype=squashfs,jffs2 noinitrd"

	# Tell u-boot where to find the uImage
	setenv bootcmd "bootm 0xbf2a0000"

	# Tell u-boot to save parameters to the u-boot-env partitions
	saveenv

	# Reset the board
	reset

Tested on:

- WNR2000v1 board.
- Initial flash works.

Known bugs:

- I don't know why factory image doesn't work on initial flash on stock
  firmware in u-boot recovery mode while it should.
- Sysupgrade does not yet work, if you do -f it will mess up your
  installation (requiring a reinstall of sqfs and uImage).

Signed-off-by: Huan Truong <htruong@tnhh.net>
8 years ago
Stijn Tintel 136319e72d kernel: mtdsplit: add support for WRGG images
Support splitting WRGG images, found in some D-Link devices (e.g.
DAP-2695).

Signed-off-by: Stijn Tintel <stijn@linux-ipv6.be>
Acked-by: John Crispin <john@phrozen.org>
8 years ago
Mathias Kresin 634d690d74 kernel: mtdsplit_uimage: fix Edimax parser
According to the author the code was added to in preparation for adding
support for a new board. The patch for the board was never send and the
code never really tested.

The edimax header starting with the edimax magic is put in front of the
uImage header. There is no special uImage header used. Means, default
magic and the type field is set to kernel as usual.

Signed-off-by: Mathias Kresin <dev@kresin.me>

edimax parser fix
8 years ago
Mathias Kresin 35073d47bb kernel: mtdsplit_uimage: fix rootfs offset
The return value of the find_header function need to be added to the
uimage_size, otherwise mtd_find_rootfs_from() might search for a rootfs
within a custom header and fails.

Signed-off-by: Mathias Kresin <dev@kresin.me>
8 years ago
Felix Fietkau ea6a3be62e kernel: silence a false positive uninitialized variable warning
Signed-off-by: Felix Fietkau <nbd@nbd.name>
8 years ago
Rafał Miłecki 1aca291214 kernel: mtdsplit: calculate kernel partition precisely for Seama
So far "kernel" partition didn't contain just a kernel. It also included
Seama header and meta data. This was making kernel update complex and it
wasn't trivial to read kernel size.
Fix it by making "kernel" parition contain just a kernel image.

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 319863f60e kernel: mtdsplit: support uimage with UBI
This patch adds uimage firmware split support for ubi.

Signed-off-by: YounJae Rho <luxflow@live.com>

SVN-Revision: 48755
8 years ago
Rafał Miłecki 1a57ce0c03 kernel: mtdsplit: add missing digest field to Seama header
Seama format has 2 similar headers: container (seal) header and entity
header. The first one has size always set to 0 and doesn't contain MD5
digest.

When dealing with Seama on a flash we deal directly with an entity. You
can see mtdsplit_parse_seama reads from offset 0 and expects entity to
be there. Seama container is used by bootloader / interface only which
extract entity out of it and flash it.

That said we should fix our header struct. This is important as we
calculate possible rootfs offset assuming it may be placed right after
Seama entity. So far calculate offset was always 16B too low.

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

SVN-Revision: 48754
8 years ago
Rafał Miłecki 9220dd5d36 kernel: mtdsplit: support Seama entity with UBI
Some D-Link routers (e.g. DIR-885L) have NAND and use Seama format. It
means OpenWrt will want to have UBI in Sseama entity and should be able
to detect it.

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

SVN-Revision: 48600
8 years ago
Rafał Miłecki 4156f292c1 kernel: mtdsplit: detect UBI partition when looking for rootfs
This allows mtdsplit parsers work with UBI which is very popular on
NAND flases.

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

SVN-Revision: 48599
8 years ago
Rafał Miłecki e1491b341b kernel: mtdsplit: modify rootfs helpers to provide partition type
Our mtdsplit parsers may want to create partition with name choice based
on partition file system (e.g. SquashFS vs. JFFS2). This patch allows
passing extra argument pointing to variable that will be set properly.

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

SVN-Revision: 48598
8 years ago
Rafał Miłecki 02abeb3b0a kernel: mtdsplit: document Seama splitter a bit
Rename kernel_size variable as it includes whole entity size, not just a
kernel size. Also update comments to match it and describe better what
are we checking/looking for.

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

SVN-Revision: 48480
8 years ago
John Crispin ed72c5f846 ar71xx: add support for Netgear WPN824N
Add support for Netgear WPN824N.
Hardware specs:
  * AR7240, 4 LAN ports, 1 WAN port
  * AR9285 WLAN
  * 32 MB RAM
  * 4 MB Flash
  * 16 LEDs (LAN, WAN and Power/Status contain two LEDs for dual color
    effect)
  * 3 Buttons (not supported)

Signed-off-by: Hartmut Knaack <knaack.h@gmx.de>

SVN-Revision: 48356
9 years ago
Felix Fietkau 7703e14bc4 kernel: mtdsplit_squashfs: Align with the erase-block size
On most image types the rootfs ends at an erase-block. However, at least
with brnImages this is not the case: while the partitions are aligned
with the erase-block size there is a 12 byte footer at the end of the
partition which must not be touched by any filesystem. This lead to a
rootfs_data partition which was not aligned properly (and thus ended up
being readonly):
	0x000000480000-0x00000085a800 : "rootfs_data" (128 KiB EB)

Signed-off-by: Martin Blumenstingl <martin.blumenstingl@googlemail.com>

SVN-Revision: 48263
9 years ago
Felix Fietkau 651083bbd9 kernel: mtdsplit: add support for EVA images
This allows splitting EVA images (usually found in fritz devices). The
firmware will be split into a kernel and a separate rootfs partition.

Signed-off-by: Martin Blumenstingl <martin.blumenstingl@googlemail.com>

SVN-Revision: 48262
9 years ago
Felix Fietkau bdd2772f1d kernel: mtdsplit: add support for brnImages
This adds brnImage (used with the brnboot bootloader) firmware parsing
support. brnboot verifies the integrity of the firmware stored on the
"Code Image" partitions by looking at the 12 byte footer at the very end
of the partition. This footer contains the checksum of the original
brnImage (kernel + rootfs/squashfs) and must not be touched (by our JFFS2
rootfs_data - otherwise the image will not be bootable anymore).

Big thanks to Mathias Kresin for analyzing the brnImage structure and
finding out the information how to keep images valid even when adding a
nested rootfs_data partition.

Signed-off-by: Martin Blumenstingl <martin.blumenstingl@googlemail.com>

SVN-Revision: 48261
9 years ago
John Crispin 9a863f803e kernel: mtdsplit: add support for FIT image
If this option is enabled, the FIT image format will be detected and
split by the mtdsplit code. Detection is based upon the FDT magic, which
will trigger the parsing and detection of the rootfs, ending-up in the
creation of the 2 new partitions.

Signed-off-by: Mathieu Olivari <mathieu@codeaurora.org>

SVN-Revision: 44792
9 years ago
Rafał Miłecki 615909819d kernel: mtdsplit_uimage: fix passed info about buf size
We obviously can't use sizeof(*buf) which is always 1.

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

SVN-Revision: 44424
9 years ago
Rafał Miłecki 30d6bc1026 kernel: mtdsplit_uimage: read more data to match Edimax needs
Signed-off-by: Rafał Miłecki <zajec5@gmail.com>

SVN-Revision: 44415
9 years ago
Rafał Miłecki 072759ff39 kernel: mtdsplit_uimage: use separated buffer for reading data
We shouldn't read data directly into the header struct, as some devices
(e.g. Edimax) need more bytes due to some extra header.

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

SVN-Revision: 44414
9 years ago
Rafał Miłecki 5673e0b703 kernel: mtdsplit_uimage: add parser for Edimax devices
Signed-off-by: Rafał Miłecki <zajec5@gmail.com>

SVN-Revision: 44413
9 years ago
Rafał Miłecki 1aed104c80 mtdsplit_uimage: more generic header verify function
Some devices have uImage headers after some extra headers (e.g. Edimax
devices). To support such cases our verify callback function should be
allowed to return header offset, not just a boolean value.

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

SVN-Revision: 44412
9 years ago
John Crispin 31fd66f808 ar71xx: add Netgear WNR1000v2/WNR1000v2-VC support (#18633)
The board is already supported by OpenWrt. WNR1000v2/WNR1000v2-VC are
pretty much the same as WNR2000v3/WNR612v2, therefore the same
initialization code and flash layout is used.

Signed-off-by: Ștefan Rusu <saltwaterc@gmail.com>
Tested-by: Douglas Fraser <1dsfraser@gmail.com>

SVN-Revision: 44221
9 years ago