From patchwork Tue Jan 19 20:51:59 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tal Keren X-Patchwork-Id: 570130 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.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 368B7140273 for ; Wed, 20 Jan 2016 07:52:26 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b=KnLxpc1x; dkim-atps=neutral Received: from arrakis.dune.hu (localhost [127.0.0.1]) by arrakis.dune.hu (Postfix) with ESMTP id 2AE5728C7F7; Tue, 19 Jan 2016 21:51:38 +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.5 required=5.0 tests=BAYES_00,FREEMAIL_FROM, T_DKIM_INVALID autolearn=unavailable version=3.3.2 Received: from arrakis.dune.hu (localhost [127.0.0.1]) by arrakis.dune.hu (Postfix) with ESMTP id D384A28C7F8 for ; Tue, 19 Jan 2016 21:51:31 +0100 (CET) X-policyd-weight: using cached result; rate: -8.5 Received: from mail-wm0-f65.google.com (mail-wm0-f65.google.com [74.125.82.65]) by arrakis.dune.hu (Postfix) with ESMTPS for ; Tue, 19 Jan 2016 21:51:29 +0100 (CET) Received: by mail-wm0-f65.google.com with SMTP id b14so25921316wmb.1 for ; Tue, 19 Jan 2016 12:52:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:subject:to:references:message-id:date:user-agent:mime-version :in-reply-to:content-type:content-transfer-encoding; bh=UIOTjwLDix/h/YTvZt7L6GyYUksB6S8hzcWyM3VHhno=; b=KnLxpc1xNpSGAuPQYR9CayYva++BiQydJUiGX5YttvbEp67TWA4MmxWmTVP10soukP ygsCgRguDrJl/TzE82bqGuR+5+cKieu/OVneQU3mv5MtGfs0U+3IgE5jmwo/yFp4dB7v 37xbgJi0rKIYWEVwu9dr3uQWGHQhu/a4RvBLWnS85hDlckTxwTRr3tPjw3iC2Uj5ooX2 UR+wFVwOKT434l7dyt7OSwiZb0O9sL/7EvaQmllxxeuKSXBzPXoT7OMJg9RtYTzOVuCZ Fcuc261HLixrRBGFLrT7exyLwjkVxSQm0HESQREqb1Zc50YI2EDkQom6V+n94araWKrw KR0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:subject:to:references:message-id:date :user-agent:mime-version:in-reply-to:content-type :content-transfer-encoding; bh=UIOTjwLDix/h/YTvZt7L6GyYUksB6S8hzcWyM3VHhno=; b=FCbip4mDaMA9zoUxm7Snz3xcEefYffpWEfxkN7j508Yv5so6WQFH/K9LX82/cVOPAD bEdzQHlqd4LK84MnABjtKDDF4cvtSJAWTmSUc3iWuLAu5mAGdek4sRvQ8QL3pwdJVYWv 3TCYKi2OqfC7JZn/K+1G/FjO7VyVjubLP8m60Nyp/gIi0qX21OxuSStMa4lfe83vLid9 f0f7b2HgbOpJzH+59muDnIZZPjHfTbbDUiZpQ95hXrQOJw+qFEFN0faLBVppVlNcpXQL E3U+09KIMVqnGKJ6/gWpsyvtVKaLm+ngtYbbXVx7bsY4zeeZxvJD7NdZrscgeK0S5iZG +VwQ== X-Gm-Message-State: AG10YOT4fKe7s56BEnHd/pG0q4PntKZf9BJQX5XyeY41+CvYrhTXiBoIXjDM+A1gBce7nA== X-Received: by 10.28.72.68 with SMTP id v65mr19682wma.41.1453236728652; Tue, 19 Jan 2016 12:52:08 -0800 (PST) Received: from [192.168.1.100] (bzq-79-177-216-202.red.bezeqint.net. [79.177.216.202]) by smtp.gmail.com with ESMTPSA id ft4sm30166103wjb.37.2016.01.19.12.52.07 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 19 Jan 2016 12:52:07 -0800 (PST) From: Tal Keren To: John Crispin , openwrt-devel@lists.openwrt.org References: <1452127248-21017-1-git-send-email-kooolk@gmail.com> <1452127248-21017-3-git-send-email-kooolk@gmail.com> <569E024D.8030606@openwrt.org> Message-ID: <569EA1EF.9030009@gmail.com> Date: Tue, 19 Jan 2016 22:51:59 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.5.0 MIME-Version: 1.0 In-Reply-To: <569E024D.8030606@openwrt.org> Subject: Re: [OpenWrt-Devel] [PATCH 3/4] firmware-utils: kernel image generator for TP-Link RE450 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" On 19/01/2016 11:30, John Crispin wrote: > can this not be merged into one of the other tplink tools ? > > That is what I initially did, add a flag for this case. But then I had to disable about 3/4 of the original code with if/else for this case. It doesn't use most of the functionally that mktplinkfw provides (It doesn't search for and use the flash layout, it doesn't write the jffs section, it doesn't write most of the fields in the header, it ignores some of the flags because they are irrelevant for it). So I think that creating a new and (very) stripped down version of it is simpler. For reference, this is my original patch. What do you think that is better? --- a/tools/firmware-utils/src/mktplinkfw.c +++ b/tools/firmware-utils/src/mktplinkfw.c @@ -154,6 +154,7 @@ static uint32_t rootfs_ofs = 0; static uint32_t rootfs_align; static struct file_info boot_info; static int combined; +static int kernel_only; static int strip_padding; static int ignore_size; static int add_jffs2_eof; @@ -518,6 +519,7 @@ static void usage(int status) "Options:\n" " -B create image for the board specified with \n" " -c use combined kernel image\n" +" -K make image with only kernel\n" " -E overwrite kernel entry point with (hexval prefixed with 0x)\n" " -L overwrite kernel load address with (hexval prefixed with 0x)\n" " -H use hardware id specified with \n" @@ -613,54 +615,61 @@ static int check_options(void) return -1; } - if (board_id == NULL && opt_hw_id == NULL) { - ERR("either board or hardware id must be specified"); - return -1; - } - - if (board_id) { - board = find_board(board_id); - if (board == NULL) { - ERR("unknown/unsupported board id \"%s\"", board_id); + if (kernel_only) { + if (!kernel_la || !kernel_ep) { + ERR("kernel loading address and entry point must be specified"); return -1; } - if (layout_id == NULL) - layout_id = board->layout_id; - - hw_id = board->hw_id; - hw_rev = board->hw_rev; } else { - if (layout_id == NULL) { - ERR("flash layout is not specified"); + if (board_id == NULL && opt_hw_id == NULL) { + ERR("either board or hardware id must be specified"); return -1; } - hw_id = strtoul(opt_hw_id, NULL, 0); - if (opt_hw_rev) - hw_rev = strtoul(opt_hw_rev, NULL, 0); - else - hw_rev = 1; - } + if (board_id) { + board = find_board(board_id); + if (board == NULL) { + ERR("unknown/unsupported board id \"%s\"", board_id); + return -1; + } + if (layout_id == NULL) + layout_id = board->layout_id; - layout = find_layout(layout_id); - if (layout == NULL) { - ERR("unknown flash layout \"%s\"", layout_id); - return -1; - } + hw_id = board->hw_id; + hw_rev = board->hw_rev; + } else { + if (layout_id == NULL) { + ERR("flash layout is not specified"); + return -1; + } + hw_id = strtoul(opt_hw_id, NULL, 0); - if (!kernel_la) - kernel_la = layout->kernel_la; - if (!kernel_ep) - kernel_ep = layout->kernel_ep; - if (!rootfs_ofs) - rootfs_ofs = layout->rootfs_ofs; + if (opt_hw_rev) + hw_rev = strtoul(opt_hw_rev, NULL, 0); + else + hw_rev = 1; + } - if (reserved_space > layout->fw_max_len) { - ERR("reserved space is not valid"); - return -1; - } + layout = find_layout(layout_id); + if (layout == NULL) { + ERR("unknown flash layout \"%s\"", layout_id); + return -1; + } - fw_max_len = layout->fw_max_len - reserved_space; + if (!kernel_la) + kernel_la = layout->kernel_la; + if (!kernel_ep) + kernel_ep = layout->kernel_ep; + if (!rootfs_ofs) + rootfs_ofs = layout->rootfs_ofs; + + if (reserved_space > layout->fw_max_len) { + ERR("reserved space is not valid"); + return -1; + } + + fw_max_len = layout->fw_max_len - reserved_space; + } if (kernel_info.file_name == NULL) { ERR("no kernel image specified"); @@ -673,50 +682,52 @@ static int check_options(void) kernel_len = kernel_info.file_size; - if (combined) { - exceed_bytes = kernel_info.file_size - (fw_max_len - sizeof(struct fw_header)); - if (exceed_bytes > 0) { - if (!ignore_size) { - ERR("kernel image is too big by %i bytes", exceed_bytes); - return -1; - } - layout->fw_max_len = sizeof(struct fw_header) + - kernel_info.file_size + - reserved_space; - } - } else { - if (rootfs_info.file_name == NULL) { - ERR("no rootfs image specified"); - return -1; - } - - ret = get_file_stat(&rootfs_info); - if (ret) - return ret; - - if (rootfs_align) { - kernel_len += sizeof(struct fw_header); - kernel_len = ALIGN(kernel_len, rootfs_align); - kernel_len -= sizeof(struct fw_header); - - DBG("kernel length aligned to %u", kernel_len); - - exceed_bytes = kernel_len + rootfs_info.file_size - (fw_max_len - sizeof(struct fw_header)); + if (!kernel_only) { + if (combined) { + exceed_bytes = kernel_info.file_size - (fw_max_len - sizeof(struct fw_header)); if (exceed_bytes > 0) { - ERR("images are too big by %i bytes", exceed_bytes); - return -1; + if (!ignore_size) { + ERR("kernel image is too big by %i bytes", exceed_bytes); + return -1; + } + layout->fw_max_len = sizeof(struct fw_header) + + kernel_info.file_size + + reserved_space; } } else { - exceed_bytes = kernel_info.file_size - (rootfs_ofs - sizeof(struct fw_header)); - if (exceed_bytes > 0) { - ERR("kernel image is too big by %i bytes", exceed_bytes); + if (rootfs_info.file_name == NULL) { + ERR("no rootfs image specified"); return -1; } - exceed_bytes = rootfs_info.file_size - (fw_max_len - rootfs_ofs); - if (exceed_bytes > 0) { - ERR("rootfs image is too big by %i bytes", exceed_bytes); - return -1; + ret = get_file_stat(&rootfs_info); + if (ret) + return ret; + + if (rootfs_align) { + kernel_len += sizeof(struct fw_header); + kernel_len = ALIGN(kernel_len, rootfs_align); + kernel_len -= sizeof(struct fw_header); + + DBG("kernel length aligned to %u", kernel_len); + + exceed_bytes = kernel_len + rootfs_info.file_size - (fw_max_len - sizeof(struct fw_header)); + if (exceed_bytes > 0) { + ERR("images are too big by %i bytes", exceed_bytes); + return -1; + } + } else { + exceed_bytes = kernel_info.file_size - (rootfs_ofs - sizeof(struct fw_header)); + if (exceed_bytes > 0) { + ERR("kernel image is too big by %i bytes", exceed_bytes); + return -1; + } + + exceed_bytes = rootfs_info.file_size - (fw_max_len - rootfs_ofs); + if (exceed_bytes > 0) { + ERR("rootfs image is too big by %i bytes", exceed_bytes); + return -1; + } } } } @@ -753,29 +764,35 @@ static void fill_header(char *buf, int len) hdr->version = htonl(hdr_ver); strncpy(hdr->vendor_name, vendor, sizeof(hdr->vendor_name)); strncpy(hdr->fw_version, version, sizeof(hdr->fw_version)); - hdr->hw_id = htonl(hw_id); - hdr->hw_rev = htonl(hw_rev); + if (!kernel_only) { + hdr->hw_id = htonl(hw_id); + hdr->hw_rev = htonl(hw_rev); - if (boot_info.file_size == 0) - memcpy(hdr->md5sum1, md5salt_normal, sizeof(hdr->md5sum1)); - else - memcpy(hdr->md5sum1, md5salt_boot, sizeof(hdr->md5sum1)); + if (boot_info.file_size == 0) + memcpy(hdr->md5sum1, md5salt_normal, sizeof(hdr->md5sum1)); + else + memcpy(hdr->md5sum1, md5salt_boot, sizeof(hdr->md5sum1)); + } hdr->kernel_la = htonl(kernel_la); hdr->kernel_ep = htonl(kernel_ep); - hdr->fw_length = htonl(layout->fw_max_len); + if (!kernel_only) { + hdr->fw_length = htonl(layout->fw_max_len); + } hdr->kernel_ofs = htonl(sizeof(struct fw_header)); hdr->kernel_len = htonl(kernel_len); - if (!combined) { + if (!combined && !kernel_only) { hdr->rootfs_ofs = htonl(rootfs_ofs); hdr->rootfs_len = htonl(rootfs_info.file_size); } - hdr->ver_hi = htons(fw_ver_hi); - hdr->ver_mid = htons(fw_ver_mid); - hdr->ver_lo = htons(fw_ver_lo); + if (!kernel_only) { + hdr->ver_hi = htons(fw_ver_hi); + hdr->ver_mid = htons(fw_ver_mid); + hdr->ver_lo = htons(fw_ver_lo); - get_md5(buf, len, hdr->md5sum1); + get_md5(buf, len, hdr->md5sum1); + } } static int pad_jffs2(char *buf, int currlen) @@ -852,7 +869,12 @@ static int build_fw(void) int ret = EXIT_FAILURE; int writelen = 0; - buflen = layout->fw_max_len; + if (kernel_only) { + buflen = sizeof(struct fw_header) + kernel_len; + buflen = ALIGN(buflen, 0x4); + } else { + buflen = layout->fw_max_len; + } buf = malloc(buflen); if (!buf) { @@ -868,7 +890,7 @@ static int build_fw(void) writelen = sizeof(struct fw_header) + kernel_len; - if (!combined) { + if (!combined && !kernel_only) { if (rootfs_align) p = buf + writelen; else @@ -1127,7 +1149,7 @@ int main(int argc, char *argv[]) while ( 1 ) { int c; - c = getopt(argc, argv, "a:B:H:E:F:L:m:V:N:W:ci:k:r:R:o:xX:hsSjv:"); + c = getopt(argc, argv, "a:B:H:E:F:L:m:V:N:W:cKi:k:r:R:o:xX:hsSjv:"); if (c == -1) break; @@ -1168,6 +1190,9 @@ int main(int argc, char *argv[]) case 'c': combined++; break; + case 'K': + kernel_only++; + break; case 'k': kernel_info.file_name = optarg; break;