From patchwork Sat Dec 13 23:41:06 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= X-Patchwork-Id: 420804 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from arrakis.dune.hu (arrakis.dune.hu [78.24.191.176]) (using TLSv1.1 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 0950F1400E9 for ; Sun, 14 Dec 2014 10:41:31 +1100 (AEDT) Received: from arrakis.dune.hu (localhost [127.0.0.1]) by arrakis.dune.hu (Postfix) with ESMTP id 3788F289C76; Sun, 14 Dec 2014 00:39:35 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on arrakis.dune.hu X-Spam-Level: X-Spam-Status: No, score=-1.2 required=5.0 tests=BAYES_00, FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM, T_DKIM_INVALID autolearn=no version=3.3.2 Received: from arrakis.dune.hu (localhost [127.0.0.1]) by arrakis.dune.hu (Postfix) with ESMTP id 16400289C76 for ; Sun, 14 Dec 2014 00:39:33 +0100 (CET) X-policyd-weight: using cached result; rate: -8.5 Received: from mail-wi0-f177.google.com (mail-wi0-f177.google.com [209.85.212.177]) by arrakis.dune.hu (Postfix) with ESMTPS for ; Sun, 14 Dec 2014 00:39:30 +0100 (CET) Received: by mail-wi0-f177.google.com with SMTP id l15so5772319wiw.16 for ; Sat, 13 Dec 2014 15:41:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:mime-version:content-type :content-transfer-encoding; bh=GvJO3l5H40J2RokYITQ3sRJNq/u8qoddljXzlZGMqPQ=; b=VO2H/gyNHxYNSNE+8hWSXI8kR4CabGfqARt/x+jvwGhwrVBa4X/q0FcFcVoCfDod+k tmnWGa9sh2xHv9DE8CLLg+uEsQKQJw7g7U8MPy43iGCxjRhfJIZwYuW2JleileaVmNn0 OyPKZPZz3U0vSMy8cExMP/QirJqAAtawyJ8GqUKz/3voijxmeNWo+/+X9Lhttcdex896 0gBv/8vCfDnJo5nXqGSlHDCuLQWiF+WtGLe7v5iewW4m44czrWOsSHxqF9ZPh/rJlrwX bq6Zl+xCWJYB7BRjfHnJGmcT/sLdXqpoCjtpZMngmWCSurKRq6At1ne3m7pvONDZw8HB HVtw== X-Received: by 10.180.208.112 with SMTP id md16mr18906489wic.37.1418514077568; Sat, 13 Dec 2014 15:41:17 -0800 (PST) Received: from linux-tdhb.lan (ip-194-187-74-233.konfederacka.maverick.com.pl. [194.187.74.233]) by mx.google.com with ESMTPSA id j9sm7152730wjb.38.2014.12.13.15.41.15 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 13 Dec 2014 15:41:16 -0800 (PST) From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= To: Gabor Juhos , openwrt-devel@lists.openwrt.org Date: Sun, 14 Dec 2014 00:41:06 +0100 Message-Id: <1418514066-6934-1-git-send-email-zajec5@gmail.com> X-Mailer: git-send-email 1.8.4.5 MIME-Version: 1.0 Subject: [OpenWrt-Devel] [PATCH] kernel: mtdsplit_uimage: use more generic header verify function X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: OpenWrt Development List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: openwrt-devel-bounces@lists.openwrt.org Sender: "openwrt-devel" 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 --- Hi Tomasz, I was looking at the patch you submitted PATCH [kernel]: proper support for Edimax uimages http://patchwork.openwrt.org/patch/6555/ and was thinking about some better solution. I didn't like the fact that you added Edimax specific workaround to the supposed-to-be-generic __mtdsplit_parse_uimage. So I came with the idea of modifying our callback function. With this patch you should be able to re-write your uimage_verify_edimax to simply return 20 instead of true. Of course we will also need to do something like: header_offset = find_header(buf, buf_size); header = offset + header_offset; --- .../generic/files/drivers/mtd/mtdsplit_uimage.c | 37 +++++++++++++++------- 1 file changed, 26 insertions(+), 11 deletions(-) diff --git a/target/linux/generic/files/drivers/mtd/mtdsplit_uimage.c b/target/linux/generic/files/drivers/mtd/mtdsplit_uimage.c index 7dad63c..2f723bd 100644 --- a/target/linux/generic/files/drivers/mtd/mtdsplit_uimage.c +++ b/target/linux/generic/files/drivers/mtd/mtdsplit_uimage.c @@ -71,10 +71,16 @@ read_uimage_header(struct mtd_info *mtd, size_t offset, return 0; } +/** + * __mtdsplit_parse_uimage - scan partition and create kernel + rootfs parts + * + * @find_header: function to call for a block of data that will return offset + * of a valid uImage header if found + */ static int __mtdsplit_parse_uimage(struct mtd_info *master, struct mtd_partition **pparts, struct mtd_part_parser_data *data, - bool (*verify)(struct uimage_header *hdr)) + size_t (*find_header)(u_char *buf, size_t len)) { struct mtd_partition *parts; struct uimage_header *header; @@ -106,11 +112,16 @@ static int __mtdsplit_parse_uimage(struct mtd_info *master, if (ret) continue; - if (!verify(header)) { + ret = find_header((u_char *)header, sizeof(*header)); + if (ret < 0) { pr_debug("no valid uImage found in \"%s\" at offset %llx\n", master->name, (unsigned long long) offset); continue; } + if (ret > 0) { + pr_warn("extra header offsets are not supported yet\n"); + continue; + } uimage_size = sizeof(*header) + be32_to_cpu(header->ih_size); if ((offset + uimage_size) > master->size) { @@ -189,28 +200,30 @@ err_free_parts: return ret; } -static bool uimage_verify_default(struct uimage_header *header) +static size_t uimage_verify_default(u_char *buf, size_t len) { + struct uimage_header *header = (struct uimage_header *)buf; + /* default sanity checks */ if (be32_to_cpu(header->ih_magic) != IH_MAGIC) { pr_debug("invalid uImage magic: %08x\n", be32_to_cpu(header->ih_magic)); - return false; + return -EINVAL; } if (header->ih_os != IH_OS_LINUX) { pr_debug("invalid uImage OS: %08x\n", be32_to_cpu(header->ih_os)); - return false; + return -EINVAL; } if (header->ih_type != IH_TYPE_KERNEL) { pr_debug("invalid uImage type: %08x\n", be32_to_cpu(header->ih_type)); - return false; + return -EINVAL; } - return true; + return 0; } static int @@ -236,9 +249,11 @@ static struct mtd_part_parser uimage_generic_parser = { #define FW_MAGIC_WNDR3700 0x33373030 #define FW_MAGIC_WNDR3700V2 0x33373031 -static bool uimage_verify_wndr3700(struct uimage_header *header) +static size_t uimage_verify_wndr3700(u_char *buf, size_t len) { + struct uimage_header *header = (struct uimage_header *)buf; uint8_t expected_type = IH_TYPE_FILESYSTEM; + switch be32_to_cpu(header->ih_magic) { case FW_MAGIC_WNR612V2: case FW_MAGIC_WNR2000V3: @@ -250,14 +265,14 @@ static bool uimage_verify_wndr3700(struct uimage_header *header) expected_type = IH_TYPE_KERNEL; break; default: - return false; + return -EINVAL; } if (header->ih_os != IH_OS_LINUX || header->ih_type != expected_type) - return false; + return -EINVAL; - return true; + return 0; } static int