mirror of
https://github.com/coolsnowwolf/lede.git
synced 2025-04-16 04:13:31 +00:00
update kernel 4.9 patch
This commit is contained in:
parent
5c86f30c4a
commit
9e45351250
@ -1,65 +0,0 @@
|
||||
From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= <rafal@milecki.pl>
|
||||
Subject: [PATCH] mtd: bcm47xxpart: improve handling TRX partition size
|
||||
MIME-Version: 1.0
|
||||
Content-Type: text/plain; charset=UTF-8
|
||||
Content-Transfer-Encoding: 8bit
|
||||
|
||||
When bcm47xxpart finds a TRX partition (container) it's supposed to jump
|
||||
to the end of it and keep looking for more partitions. TRX and its
|
||||
subpartitions are handled be a separated parser.
|
||||
|
||||
The problem with old code was relying on the length specified in a TRX
|
||||
header. That isn't reliable as TRX is commonly modified to have checksum
|
||||
cover only non-changing subpartitions. Otherwise modifying e.g. a rootfs
|
||||
would result in CRC32 mismatch and bootloader refusing to boot a
|
||||
firmware.
|
||||
|
||||
Fix it by trying better to figure out a real TRX size. We can securely
|
||||
assume that TRX has to cover all subpartitions and the last one is at
|
||||
least of a block size in size. Then compare it with a length field.
|
||||
|
||||
This makes code more optimal & reliable thanks to skipping data that
|
||||
shouldn't be parsed.
|
||||
|
||||
Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
|
||||
---
|
||||
|
||||
--- a/drivers/mtd/bcm47xxpart.c
|
||||
+++ b/drivers/mtd/bcm47xxpart.c
|
||||
@@ -186,6 +186,8 @@ static int bcm47xxpart_parse(struct mtd_
|
||||
/* TRX */
|
||||
if (buf[0x000 / 4] == TRX_MAGIC) {
|
||||
struct trx_header *trx;
|
||||
+ uint32_t last_subpart;
|
||||
+ uint32_t trx_size;
|
||||
|
||||
if (trx_num >= ARRAY_SIZE(trx_parts))
|
||||
pr_warn("No enough space to store another TRX found at 0x%X\n",
|
||||
@@ -195,11 +197,23 @@ static int bcm47xxpart_parse(struct mtd_
|
||||
bcm47xxpart_add_part(&parts[curr_part++], "firmware",
|
||||
offset, 0);
|
||||
|
||||
- /* Jump to the end of TRX */
|
||||
+ /*
|
||||
+ * Try to find TRX size. The "length" field isn't fully
|
||||
+ * reliable as it could be decreased to make CRC32 cover
|
||||
+ * only part of TRX data. It's commonly used as checksum
|
||||
+ * can't cover e.g. ever-changing rootfs partition.
|
||||
+ * Use offsets as helpers for assuming min TRX size.
|
||||
+ */
|
||||
trx = (struct trx_header *)buf;
|
||||
- offset = roundup(offset + trx->length, blocksize);
|
||||
- /* Next loop iteration will increase the offset */
|
||||
- offset -= blocksize;
|
||||
+ last_subpart = max3(trx->offset[0], trx->offset[1],
|
||||
+ trx->offset[2]);
|
||||
+ trx_size = max(trx->length, last_subpart + blocksize);
|
||||
+
|
||||
+ /*
|
||||
+ * Skip the TRX data. Decrease offset by block size as
|
||||
+ * the next loop iteration will increase it.
|
||||
+ */
|
||||
+ offset += roundup(trx_size, blocksize) - blocksize;
|
||||
continue;
|
||||
}
|
||||
|
@ -114,7 +114,7 @@ Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
|
||||
#include <linux/err.h>
|
||||
#include <linux/of.h>
|
||||
|
||||
@@ -856,6 +857,42 @@ void deregister_mtd_parser(struct mtd_pa
|
||||
@@ -843,6 +844,42 @@ void deregister_mtd_parser(struct mtd_pa
|
||||
EXPORT_SYMBOL_GPL(deregister_mtd_parser);
|
||||
|
||||
/*
|
||||
@ -157,8 +157,8 @@ Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
|
||||
* Do not forget to update 'parse_mtd_partitions()' kerneldoc comment if you
|
||||
* are changing this array!
|
||||
*/
|
||||
@@ -999,6 +1036,13 @@ int parse_mtd_partitions(struct mtd_info
|
||||
{
|
||||
@@ -983,6 +1020,13 @@ int parse_mtd_partitions(struct mtd_info
|
||||
struct mtd_partitions pparts = { };
|
||||
struct mtd_part_parser *parser;
|
||||
int ret, err = 0;
|
||||
+ const char *const *types_of = NULL;
|
||||
@ -171,7 +171,7 @@ Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
|
||||
|
||||
if (!types)
|
||||
types = default_mtd_part_types;
|
||||
@@ -1035,6 +1079,7 @@ int parse_mtd_partitions(struct mtd_info
|
||||
@@ -1023,6 +1067,7 @@ int parse_mtd_partitions(struct mtd_info
|
||||
if (ret < 0 && !err)
|
||||
err = ret;
|
||||
}
|
||||
|
@ -60,7 +60,7 @@ Signed-off-by: Felix Fietkau <nbd@nbd.name>
|
||||
/*
|
||||
* Given a pointer to the MTD object in the mtd_part structure, we can retrieve
|
||||
* the pointer to that structure.
|
||||
@@ -679,6 +683,7 @@ int mtd_add_partition(struct mtd_info *p
|
||||
@@ -666,6 +670,7 @@ int mtd_add_partition(struct mtd_info *p
|
||||
mutex_unlock(&mtd_partitions_mutex);
|
||||
|
||||
add_mtd_device(&new->mtd);
|
||||
@ -68,7 +68,7 @@ Signed-off-by: Felix Fietkau <nbd@nbd.name>
|
||||
|
||||
mtd_add_partition_attrs(new);
|
||||
|
||||
@@ -757,6 +762,35 @@ int mtd_del_partition(struct mtd_info *m
|
||||
@@ -744,6 +749,35 @@ int mtd_del_partition(struct mtd_info *m
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(mtd_del_partition);
|
||||
|
||||
@ -104,7 +104,7 @@ Signed-off-by: Felix Fietkau <nbd@nbd.name>
|
||||
/*
|
||||
* This function, given a master MTD object and a partition table, creates
|
||||
* and registers slave MTD objects which are bound to the master according to
|
||||
@@ -788,6 +822,7 @@ int add_mtd_partitions(struct mtd_info *
|
||||
@@ -775,6 +809,7 @@ int add_mtd_partitions(struct mtd_info *
|
||||
mutex_unlock(&mtd_partitions_mutex);
|
||||
|
||||
add_mtd_device(&slave->mtd);
|
||||
|
@ -9,7 +9,7 @@ Signed-off-by: Gabor Juhos <juhosg@openwrt.org>
|
||||
|
||||
--- a/drivers/mtd/mtdpart.c
|
||||
+++ b/drivers/mtd/mtdpart.c
|
||||
@@ -1134,6 +1134,62 @@ void mtd_part_parser_cleanup(struct mtd_
|
||||
@@ -1122,6 +1122,62 @@ void mtd_part_parser_cleanup(struct mtd_
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -10,7 +10,7 @@ Signed-off-by: Gabor Juhos <juhosg@openwrt.org>
|
||||
|
||||
--- a/drivers/mtd/mtdpart.c
|
||||
+++ b/drivers/mtd/mtdpart.c
|
||||
@@ -762,6 +762,36 @@ int mtd_del_partition(struct mtd_info *m
|
||||
@@ -749,6 +749,36 @@ int mtd_del_partition(struct mtd_info *m
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(mtd_del_partition);
|
||||
|
||||
@ -47,7 +47,7 @@ Signed-off-by: Gabor Juhos <juhosg@openwrt.org>
|
||||
#ifdef CONFIG_MTD_SPLIT_FIRMWARE_NAME
|
||||
#define SPLIT_FIRMWARE_NAME CONFIG_MTD_SPLIT_FIRMWARE_NAME
|
||||
#else
|
||||
@@ -770,6 +800,7 @@ EXPORT_SYMBOL_GPL(mtd_del_partition);
|
||||
@@ -757,6 +787,7 @@ EXPORT_SYMBOL_GPL(mtd_del_partition);
|
||||
|
||||
static void split_firmware(struct mtd_info *master, struct mtd_part *part)
|
||||
{
|
||||
@ -55,7 +55,7 @@ Signed-off-by: Gabor Juhos <juhosg@openwrt.org>
|
||||
}
|
||||
|
||||
void __weak arch_split_mtd_part(struct mtd_info *master, const char *name,
|
||||
@@ -784,6 +815,12 @@ static void mtd_partition_split(struct m
|
||||
@@ -771,6 +802,12 @@ static void mtd_partition_split(struct m
|
||||
if (rootfs_found)
|
||||
return;
|
||||
|
||||
|
@ -11,7 +11,7 @@ Signed-off-by: Gabor Juhos <juhosg@openwrt.org>
|
||||
|
||||
--- a/drivers/mtd/mtdpart.c
|
||||
+++ b/drivers/mtd/mtdpart.c
|
||||
@@ -792,6 +792,17 @@ run_parsers_by_type(struct mtd_part *sla
|
||||
@@ -779,6 +779,17 @@ run_parsers_by_type(struct mtd_part *sla
|
||||
return nr_parts;
|
||||
}
|
||||
|
||||
@ -29,7 +29,7 @@ Signed-off-by: Gabor Juhos <juhosg@openwrt.org>
|
||||
#ifdef CONFIG_MTD_SPLIT_FIRMWARE_NAME
|
||||
#define SPLIT_FIRMWARE_NAME CONFIG_MTD_SPLIT_FIRMWARE_NAME
|
||||
#else
|
||||
@@ -1244,6 +1255,24 @@ int mtd_is_partition(const struct mtd_in
|
||||
@@ -1232,6 +1243,24 @@ int mtd_is_partition(const struct mtd_in
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(mtd_is_partition);
|
||||
|
||||
|
@ -107,7 +107,7 @@ Signed-off-by: Felix Fietkau <nbd@nbd.name>
|
||||
|
||||
if (instr->fail_addr != MTD_FAIL_ADDR_UNKNOWN)
|
||||
instr->fail_addr -= part->offset;
|
||||
@@ -591,19 +660,22 @@ static struct mtd_part *allocate_partiti
|
||||
@@ -578,19 +647,22 @@ static struct mtd_part *allocate_partiti
|
||||
remainder = do_div(tmp, wr_alignment);
|
||||
if ((slave->mtd.flags & MTD_WRITEABLE) && remainder) {
|
||||
/* Doesn't start on a boundary of major erase size */
|
||||
|
@ -0,0 +1,10 @@
|
||||
--- a/drivers/mtd/spi-nor/spi-nor.c
|
||||
+++ b/drivers/mtd/spi-nor/spi-nor.c
|
||||
@@ -1007,6 +1007,7 @@
|
||||
{ "en25p64", INFO(0x1c2017, 0, 64 * 1024, 128, 0) },
|
||||
{ "en25q64", INFO(0x1c3017, 0, 64 * 1024, 128, SECT_4K) },
|
||||
{ "en25q128", INFO(0x1c3018, 0, 64 * 1024, 256, SECT_4K) },
|
||||
+ { "en25qh32", INFO(0x1c7016, 0, 64 * 1024, 64, 0) },
|
||||
{ "en25qh128", INFO(0x1c7018, 0, 64 * 1024, 256, 0) },
|
||||
{ "en25qh256", INFO(0x1c7019, 0, 64 * 1024, 512, 0) },
|
||||
{ "en25s64", INFO(0x1c3817, 0, 64 * 1024, 128, SECT_4K) },
|
@ -171,7 +171,7 @@ Signed-off-by: Jonas Gorski <jogo@openwrt.org>
|
||||
/*
|
||||
* Allocate a dst for local (unicast / anycast) address.
|
||||
*/
|
||||
@@ -2848,7 +2881,8 @@ static int rtm_to_fib6_config(struct sk_
|
||||
@@ -2850,7 +2883,8 @@ static int rtm_to_fib6_config(struct sk_
|
||||
if (rtm->rtm_type == RTN_UNREACHABLE ||
|
||||
rtm->rtm_type == RTN_BLACKHOLE ||
|
||||
rtm->rtm_type == RTN_PROHIBIT ||
|
||||
@ -181,7 +181,7 @@ Signed-off-by: Jonas Gorski <jogo@openwrt.org>
|
||||
cfg->fc_flags |= RTF_REJECT;
|
||||
|
||||
if (rtm->rtm_type == RTN_LOCAL)
|
||||
@@ -3220,6 +3254,9 @@ static int rt6_fill_node(struct net *net
|
||||
@@ -3222,6 +3256,9 @@ static int rt6_fill_node(struct net *net
|
||||
case -EACCES:
|
||||
rtm->rtm_type = RTN_PROHIBIT;
|
||||
break;
|
||||
@ -191,7 +191,7 @@ Signed-off-by: Jonas Gorski <jogo@openwrt.org>
|
||||
case -EAGAIN:
|
||||
rtm->rtm_type = RTN_THROW;
|
||||
break;
|
||||
@@ -3496,6 +3533,8 @@ static int ip6_route_dev_notify(struct n
|
||||
@@ -3498,6 +3535,8 @@ static int ip6_route_dev_notify(struct n
|
||||
#ifdef CONFIG_IPV6_MULTIPLE_TABLES
|
||||
net->ipv6.ip6_prohibit_entry->dst.dev = dev;
|
||||
net->ipv6.ip6_prohibit_entry->rt6i_idev = in6_dev_get(dev);
|
||||
@ -200,7 +200,15 @@ Signed-off-by: Jonas Gorski <jogo@openwrt.org>
|
||||
net->ipv6.ip6_blk_hole_entry->dst.dev = dev;
|
||||
net->ipv6.ip6_blk_hole_entry->rt6i_idev = in6_dev_get(dev);
|
||||
#endif
|
||||
@@ -3722,6 +3761,17 @@ static int __net_init ip6_route_net_init
|
||||
@@ -3509,6 +3548,7 @@ static int ip6_route_dev_notify(struct n
|
||||
in6_dev_put(net->ipv6.ip6_null_entry->rt6i_idev);
|
||||
#ifdef CONFIG_IPV6_MULTIPLE_TABLES
|
||||
in6_dev_put(net->ipv6.ip6_prohibit_entry->rt6i_idev);
|
||||
+ in6_dev_put(net->ipv6.ip6_policy_failed_entry->rt6i_idev);
|
||||
in6_dev_put(net->ipv6.ip6_blk_hole_entry->rt6i_idev);
|
||||
#endif
|
||||
}
|
||||
@@ -3724,6 +3764,17 @@ static int __net_init ip6_route_net_init
|
||||
net->ipv6.ip6_blk_hole_entry->dst.ops = &net->ipv6.ip6_dst_ops;
|
||||
dst_init_metrics(&net->ipv6.ip6_blk_hole_entry->dst,
|
||||
ip6_template_metrics, true);
|
||||
@ -218,7 +226,7 @@ Signed-off-by: Jonas Gorski <jogo@openwrt.org>
|
||||
#endif
|
||||
|
||||
net->ipv6.sysctl.flush_delay = 0;
|
||||
@@ -3740,6 +3790,8 @@ out:
|
||||
@@ -3742,6 +3793,8 @@ out:
|
||||
return ret;
|
||||
|
||||
#ifdef CONFIG_IPV6_MULTIPLE_TABLES
|
||||
@ -227,7 +235,7 @@ Signed-off-by: Jonas Gorski <jogo@openwrt.org>
|
||||
out_ip6_prohibit_entry:
|
||||
kfree(net->ipv6.ip6_prohibit_entry);
|
||||
out_ip6_null_entry:
|
||||
@@ -3757,6 +3809,7 @@ static void __net_exit ip6_route_net_exi
|
||||
@@ -3759,6 +3812,7 @@ static void __net_exit ip6_route_net_exi
|
||||
#ifdef CONFIG_IPV6_MULTIPLE_TABLES
|
||||
kfree(net->ipv6.ip6_prohibit_entry);
|
||||
kfree(net->ipv6.ip6_blk_hole_entry);
|
||||
@ -235,7 +243,7 @@ Signed-off-by: Jonas Gorski <jogo@openwrt.org>
|
||||
#endif
|
||||
dst_entries_destroy(&net->ipv6.ip6_dst_ops);
|
||||
}
|
||||
@@ -3830,6 +3883,9 @@ void __init ip6_route_init_special_entri
|
||||
@@ -3832,6 +3886,9 @@ void __init ip6_route_init_special_entri
|
||||
init_net.ipv6.ip6_prohibit_entry->rt6i_idev = in6_dev_get(init_net.loopback_dev);
|
||||
init_net.ipv6.ip6_blk_hole_entry->dst.dev = init_net.loopback_dev;
|
||||
init_net.ipv6.ip6_blk_hole_entry->rt6i_idev = in6_dev_get(init_net.loopback_dev);
|
||||
|
Loading…
Reference in New Issue
Block a user