From patchwork Wed Jan 29 22:36:27 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonas Karlman X-Patchwork-Id: 2040407 X-Patchwork-Delegate: u-boot@0leil.net Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=kwiboo.se header.i=@kwiboo.se header.a=rsa-sha256 header.s=fe-e1b5cab7be header.b=t9JiIvSS; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=patchwork.ozlabs.org) Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Yjxq40pC8z1ycb for ; Thu, 30 Jan 2025 09:37:04 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 39B9280C99; Wed, 29 Jan 2025 23:36:58 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=kwiboo.se Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; secure) header.d=kwiboo.se header.i=@kwiboo.se header.b="t9JiIvSS"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 1AC7580C69; Wed, 29 Jan 2025 23:36:57 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED,RCVD_IN_VALIDITY_RPBL_BLOCKED, SPF_HELO_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 Received: from smtp.forwardemail.net (smtp.forwardemail.net [149.28.215.223]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id AEDEC809D2 for ; Wed, 29 Jan 2025 23:36:54 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=kwiboo.se Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=SRS0=e4db=UW=kwiboo.se=jonas@fe-bounces.kwiboo.se DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kwiboo.se; h=Content-Transfer-Encoding: MIME-Version: References: In-Reply-To: Message-ID: Date: Subject: Cc: To: From; q=dns/txt; s=fe-e1b5cab7be; t=1738190213; bh=J0R8dCTR8fEOicrf9y2YeucMPm++wng/KvzofLpZb+U=; b=t9JiIvSSZkBgHRYWc7YNDUDor7N5X6HEHtry2tnjdk+98xQa/wabu+budIyBLUbIpRgNhZBd4 uUxhuiXAgg6Z5nnMu2fU1lkHgvnrKM4VqplQwTp1+6gvRPZkZRrAW355Y6AhZtQ1moKN00MBWw1 KUS/MveNHiCCgc9gseaKRYrzL2SnSj3YBs4EE6zo6A55crijE+kTMNZ0poZCm1DyKfauHH31iB9 yFy7Kpx1C05CKVtm4i8gsZqq9fm1ddhAV1Rfyb6rGFstKMYMHTzYWJ9l0ObrztbEiubtGWPVX2u ZJ+bGyTiNb4S6RtHbTnURBNSo8jzMunNkvjs3KxdcHvg== X-Forward-Email-ID: 679aad813590a80aa97f8e07 X-Forward-Email-Sender: rfc822; jonas@kwiboo.se, smtp.forwardemail.net, 149.28.215.223 X-Forward-Email-Version: 0.4.40 X-Forward-Email-Website: https://forwardemail.net X-Complaints-To: abuse@forwardemail.net X-Report-Abuse: abuse@forwardemail.net X-Report-Abuse-To: abuse@forwardemail.net From: Jonas Karlman To: Kever Yang , Simon Glass , Philipp Tomsich , Tom Rini Cc: u-boot@lists.denx.de, Jonas Karlman Subject: [PATCH 1/6] rockchip: mkimage: Split size_and_off and size_and_nimage Date: Wed, 29 Jan 2025 22:36:27 +0000 Message-ID: <20250129223641.1888833-2-jonas@kwiboo.se> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250129223641.1888833-1-jonas@kwiboo.se> References: <20250129223641.1888833-1-jonas@kwiboo.se> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean Split 32-bit size_and_off and size_and_nimage fields of the v2 image format header into their own 16-bit size, offset and num_images fields. Set num_images based on number of images passed by the datafile parameter and size based on the offset to the hash field to fix using a single init data file and no boot data file for the v2 image format. Signed-off-by: Jonas Karlman --- tools/rkcommon.c | 44 ++++++++++++++++++++++++-------------------- 1 file changed, 24 insertions(+), 20 deletions(-) diff --git a/tools/rkcommon.c b/tools/rkcommon.c index 3e52236b15a8..de3fd2d3f3c2 100644 --- a/tools/rkcommon.c +++ b/tools/rkcommon.c @@ -34,15 +34,16 @@ enum hash_type { /** * struct image_entry * - * @size_and_off: [31:16]image size;[15:0]image offset - * @address: default as 0xFFFFFFFF + * @offset: image offset (unit as 512 byte blocks) + * @size: image size (unit as 512 byte blocks) + * @address: load address (default as 0xFFFFFFFF) * @flag: no use * @counter: no use * @hash: hash of image - * */ struct image_entry { - uint32_t size_and_off; + uint16_t offset; + uint16_t size; uint32_t address; uint32_t flag; uint32_t counter; @@ -56,16 +57,17 @@ struct image_entry { * This is stored at SD card block 64 (where each block is 512 bytes) * * @magic: Magic (must be RK_MAGIC_V2) - * @size_and_nimage: [31:16]number of images;[15:0] - * offset to hash field of header(unit as 4Byte) - * @boot_flag: [3:0]hash type(0:none,1:sha256,2:sha512) - * @signature: hash or signature for header info - * + * @size: offset to hash field of header (unit as 4 bytes) + * @num_images: number of images + * @boot_flag: [3:0] hash type (0:none, 1:sha256, 2:sha512) + * @images: images + * @hash: hash or signature for header info */ struct header0_info_v2 { uint32_t magic; uint8_t reserved[4]; - uint32_t size_and_nimage; + uint16_t size; + uint16_t num_images; uint32_t boot_flag; uint8_t reserved1[104]; struct image_entry images[4]; @@ -332,17 +334,18 @@ static void rkcommon_set_header0_v2(void *buf, struct image_tool_params *params) printf("Image Type: Rockchip %s boot image\n", rkcommon_get_spl_hdr(params)); memset(buf, '\0', RK_INIT_OFFSET * RK_BLK_SIZE); - hdr->magic = cpu_to_le32(RK_MAGIC_V2); - hdr->size_and_nimage = cpu_to_le32((2 << 16) + 384); + hdr->magic = cpu_to_le32(RK_MAGIC_V2); hdr->boot_flag = cpu_to_le32(HASH_SHA256); sector_offset = 4; image_size_array[0] = spl_params.init_size; image_size_array[1] = spl_params.boot_size; for (i = 0; i < 2; i++) { + if (!image_size_array[i]) + break; image_sector_count = image_size_array[i] / RK_BLK_SIZE; - hdr->images[i].size_and_off = cpu_to_le32((image_sector_count - << 16) + sector_offset); + hdr->images[i].offset = cpu_to_le16(sector_offset); + hdr->images[i].size = cpu_to_le16(image_sector_count); hdr->images[i].address = 0xFFFFFFFF; hdr->images[i].counter = cpu_to_le32(i + 1); image_ptr = buf + sector_offset * RK_BLK_SIZE; @@ -351,6 +354,8 @@ static void rkcommon_set_header0_v2(void *buf, struct image_tool_params *params) sector_offset = sector_offset + image_sector_count; } + hdr->num_images = cpu_to_le16(i); + hdr->size = cpu_to_le16(offsetof(typeof(*hdr), hash) / sizeof(uint32_t)); do_sha256_hash(buf, (void *)hdr->hash - buf, hdr->hash); } @@ -497,10 +502,8 @@ void rkcommon_print_header(const void *buf, struct image_tool_params *params) return; } - init_size = header0_v2.images[0].size_and_off >> 16; - init_size = init_size * RK_BLK_SIZE; - boot_size = header0_v2.images[1].size_and_off >> 16; - boot_size = boot_size * RK_BLK_SIZE; + init_size = le16_to_cpu(header0_v2.images[0].size) * RK_BLK_SIZE; + boot_size = le16_to_cpu(header0_v2.images[1].size) * RK_BLK_SIZE; } else { ret = rkcommon_parse_header(buf, &header0, &spl_info); @@ -514,8 +517,9 @@ void rkcommon_print_header(const void *buf, struct image_tool_params *params) } image_type = ret; - init_size = header0.init_size * RK_BLK_SIZE; - boot_size = header0.init_boot_size * RK_BLK_SIZE - init_size; + init_size = le16_to_cpu(header0.init_size) * RK_BLK_SIZE; + boot_size = le16_to_cpu(header0.init_boot_size) * RK_BLK_SIZE - + init_size; printf("Image Type: Rockchip %s (%s) boot image\n", spl_info->spl_hdr, From patchwork Wed Jan 29 22:36:28 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonas Karlman X-Patchwork-Id: 2040408 X-Patchwork-Delegate: u-boot@0leil.net Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=kwiboo.se header.i=@kwiboo.se header.a=rsa-sha256 header.s=fe-e1b5cab7be header.b=LOmWw3wE; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=patchwork.ozlabs.org) Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4YjxqD62g6z1ycb for ; Thu, 30 Jan 2025 09:37:12 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 88B4981F4D; Wed, 29 Jan 2025 23:36:58 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=kwiboo.se Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; secure) header.d=kwiboo.se header.i=@kwiboo.se header.b="LOmWw3wE"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 2BA90809D2; Wed, 29 Jan 2025 23:36:57 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED,RCVD_IN_VALIDITY_RPBL_BLOCKED, SPF_HELO_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 Received: from smtp.forwardemail.net (smtp.forwardemail.net [149.28.215.223]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id C58A880AE5 for ; Wed, 29 Jan 2025 23:36:54 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=kwiboo.se Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=SRS0=e4db=UW=kwiboo.se=jonas@fe-bounces.kwiboo.se DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kwiboo.se; h=Content-Transfer-Encoding: MIME-Version: References: In-Reply-To: Message-ID: Date: Subject: Cc: To: From; q=dns/txt; s=fe-e1b5cab7be; t=1738190213; bh=t+4UWt9ntc0rYKA7O0cqJy2J8IPygyERE8lmo5CPUck=; b=LOmWw3wErgus+CicI8aG95EgjZyfY2mTv+XUCOgf1SGvYMOiR7SAIpNI53F2CP5T+nbcnhJ3c 2XIhP0JKqcZmIWDRRjt2+P4kLSxc7pfffA0IanBP6nz+/eTBS1j9x+38xK1qeWiCngjQbD/LO+S o2z2ApqmyRLRN2T9cRWxwMpfomrgoD2afaWmx8NI35fl+l484m6tMIHzXa13YO/sinYT+zeQ71z dNe6IOrCTID1/Qxj/I5rYLbC6LQVvynD8GwsSAwc4xVDXJznHJbRzMzd+B+ZarA3NNMbNjAZgtG cbJ2f60HglivGCqCScm98N9E0Xy/+xU1srP8iBV8LizQ== X-Forward-Email-ID: 679aad843590a80aa97f8e18 X-Forward-Email-Sender: rfc822; jonas@kwiboo.se, smtp.forwardemail.net, 149.28.215.223 X-Forward-Email-Version: 0.4.40 X-Forward-Email-Website: https://forwardemail.net X-Complaints-To: abuse@forwardemail.net X-Report-Abuse: abuse@forwardemail.net X-Report-Abuse-To: abuse@forwardemail.net From: Jonas Karlman To: Kever Yang , Simon Glass , Philipp Tomsich , Tom Rini Cc: u-boot@lists.denx.de, Jonas Karlman Subject: [PATCH 2/6] rockchip: mkimage: Print image information for all embedded images Date: Wed, 29 Jan 2025 22:36:28 +0000 Message-ID: <20250129223641.1888833-3-jonas@kwiboo.se> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250129223641.1888833-1-jonas@kwiboo.se> References: <20250129223641.1888833-1-jonas@kwiboo.se> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean The v2 image format can embed up to 4 data files compared to the two init and boot data files using the older image format. Add support for displaying more of the image header information that exists in the v2 image format, e.g. image load address and flag. Example for v2 image format: > tools/mkimage -l rk3576_idblock_v1.09.107.img Rockchip Boot Image (v2) Image 1: 4096 @ 0x1000 - Load address: 0x3ffc0000 Image 2: 77824 @ 0x2000 - Load address: 0x3ff81000 Image 3: 262144 @ 0x15000 Example for older image format: > tools/mkimage -l u-boot-rockchip.bin Rockchip RK32 (SD/MMC) Boot Image Init Data: 20480 @ 0x800 Boot Data: 112640 @ 0x5800 Signed-off-by: Jonas Karlman --- tools/rkcommon.c | 41 +++++++++++++++++++++++++++++++---------- 1 file changed, 31 insertions(+), 10 deletions(-) diff --git a/tools/rkcommon.c b/tools/rkcommon.c index de3fd2d3f3c2..ad239917d2bd 100644 --- a/tools/rkcommon.c +++ b/tools/rkcommon.c @@ -331,8 +331,6 @@ static void rkcommon_set_header0_v2(void *buf, struct image_tool_params *params) uint8_t *image_ptr = NULL; int i; - printf("Image Type: Rockchip %s boot image\n", - rkcommon_get_spl_hdr(params)); memset(buf, '\0', RK_INIT_OFFSET * RK_BLK_SIZE); hdr->magic = cpu_to_le32(RK_MAGIC_V2); hdr->boot_flag = cpu_to_le32(HASH_SHA256); @@ -486,6 +484,29 @@ int rkcommon_verify_header(unsigned char *buf, int size, return -ENOENT; } +static void rkcommon_print_header_v2(const struct header0_info_v2 *hdr) +{ + uint32_t val; + int i; + + printf("Rockchip Boot Image (v2)\n"); + + for (i = 0; i < le16_to_cpu(hdr->num_images); i++) { + printf("Image %u: %u @ 0x%x\n", + le32_to_cpu(hdr->images[i].counter), + le16_to_cpu(hdr->images[i].size) * RK_BLK_SIZE, + le16_to_cpu(hdr->images[i].offset) * RK_BLK_SIZE); + + val = le32_to_cpu(hdr->images[i].address); + if (val != 0xFFFFFFFF) + printf("- Load address: 0x%x\n", val); + + val = le32_to_cpu(hdr->images[i].flag); + if (val) + printf("- Flag: 0x%x\n", val); + } +} + void rkcommon_print_header(const void *buf, struct image_tool_params *params) { struct header0_info header0; @@ -502,8 +523,7 @@ void rkcommon_print_header(const void *buf, struct image_tool_params *params) return; } - init_size = le16_to_cpu(header0_v2.images[0].size) * RK_BLK_SIZE; - boot_size = le16_to_cpu(header0_v2.images[1].size) * RK_BLK_SIZE; + rkcommon_print_header_v2(&header0_v2); } else { ret = rkcommon_parse_header(buf, &header0, &spl_info); @@ -521,15 +541,16 @@ void rkcommon_print_header(const void *buf, struct image_tool_params *params) boot_size = le16_to_cpu(header0.init_boot_size) * RK_BLK_SIZE - init_size; - printf("Image Type: Rockchip %s (%s) boot image\n", - spl_info->spl_hdr, + printf("Rockchip %s (%s) Boot Image\n", spl_info->spl_hdr, (image_type == IH_TYPE_RKSD) ? "SD/MMC" : "SPI"); - } - printf("Init Data Size: %d bytes\n", init_size); + printf("Init Data: %d @ 0x%x\n", init_size, + le16_to_cpu(header0.init_offset) * RK_BLK_SIZE); - if (boot_size != RK_MAX_BOOT_SIZE) - printf("Boot Data Size: %d bytes\n", boot_size); + if (boot_size != RK_MAX_BOOT_SIZE) + printf("Boot Data: %d @ 0x%x\n", boot_size, init_size + + le16_to_cpu(header0.init_offset) * RK_BLK_SIZE); + } } void rkcommon_rc4_encode_spl(void *buf, unsigned int offset, unsigned int size) From patchwork Wed Jan 29 22:36:29 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonas Karlman X-Patchwork-Id: 2040409 X-Patchwork-Delegate: u-boot@0leil.net Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=kwiboo.se header.i=@kwiboo.se header.a=rsa-sha256 header.s=fe-e1b5cab7be header.b=zBRAvKn9; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=patchwork.ozlabs.org) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4YjxqR4w4Gz1ycb for ; Thu, 30 Jan 2025 09:37:20 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id D158D80C67; Wed, 29 Jan 2025 23:37:02 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=kwiboo.se Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; secure) header.d=kwiboo.se header.i=@kwiboo.se header.b="zBRAvKn9"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 27E8A80C69; Wed, 29 Jan 2025 23:37:02 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED,RCVD_IN_VALIDITY_RPBL_BLOCKED, SPF_HELO_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 Received: from smtp.forwardemail.net (smtp.forwardemail.net [149.28.215.223]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id C291E81F69 for ; Wed, 29 Jan 2025 23:36:59 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=kwiboo.se Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=SRS0=e4db=UW=kwiboo.se=jonas@fe-bounces.kwiboo.se DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kwiboo.se; h=Content-Transfer-Encoding: MIME-Version: References: In-Reply-To: Message-ID: Date: Subject: Cc: To: From; q=dns/txt; s=fe-e1b5cab7be; t=1738190218; bh=820QW0A6oQZ8PRk4GXhTAT53GgYhbgbrcyS8DUYFUoo=; b=zBRAvKn9Le/3YCPDj4MTea00UKZ04vYpyv86NeKzq0BWbAdkgllhdEvXd9HAoc4X5/KDMd4K7 pJv7GZBqXaEDe9UACM70eHPlnbOjf7EaHq0r1IE2r86lc9biqWmbRAHVajYgg+rDEWOleLWfEFu IKw86bQVWc2xePrS8zkxbyyQVh2JZ4KZ9uuLyY0LgVA9nYeCwpMdhFdze8NxTkR6beEqUnyQ6s+ 5PowJX9WTdweXBeFoWgXpQ4psJMypi2QhDwVl5q6fA40tzYvyMMFzRhNczQ1OyWJ51otnQq1COx hc5DkiSxzrepUbnjeow3g2njhOJ6C99WpsZHKy5LslgA== X-Forward-Email-ID: 679aad873590a80aa97f8e27 X-Forward-Email-Sender: rfc822; jonas@kwiboo.se, smtp.forwardemail.net, 149.28.215.223 X-Forward-Email-Version: 0.4.40 X-Forward-Email-Website: https://forwardemail.net X-Complaints-To: abuse@forwardemail.net X-Report-Abuse: abuse@forwardemail.net X-Report-Abuse-To: abuse@forwardemail.net From: Jonas Karlman To: Kever Yang , Simon Glass , Philipp Tomsich , Tom Rini Cc: u-boot@lists.denx.de, Jonas Karlman Subject: [PATCH 3/6] rockchip: mkimage: Print boot0 and boot1 parameters Date: Wed, 29 Jan 2025 22:36:29 +0000 Message-ID: <20250129223641.1888833-4-jonas@kwiboo.se> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250129223641.1888833-1-jonas@kwiboo.se> References: <20250129223641.1888833-1-jonas@kwiboo.se> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean The v2 image format embeds boot0 and boot1 parameters, the vendor tool boot_merger may write these parameters based on the rkboot miniall.ini files. E.g. a RK3576 boot image may contain a boot1 parameter that signals BootROM or vendor blobs to use 1 GHz instead of the regular 24 MHz rate for the high precision timer. Add support for printing boot0 and boot1 parameters, e.g.: > tools/mkimage -l rk3576_idblock_v1.09.107.img Rockchip Boot Image (v2) Boot1 2: 0x100 Image 1: 4096 @ 0x1000 - Load address: 0x3ffc0000 Image 2: 77824 @ 0x2000 - Load address: 0x3ff81000 Image 3: 262144 @ 0x15000 Signed-off-by: Jonas Karlman Reviewed-by: Quentin Schulz --- tools/rkcommon.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/tools/rkcommon.c b/tools/rkcommon.c index ad239917d2bd..324820717663 100644 --- a/tools/rkcommon.c +++ b/tools/rkcommon.c @@ -62,6 +62,8 @@ struct image_entry { * @boot_flag: [3:0] hash type (0:none, 1:sha256, 2:sha512) * @images: images * @hash: hash or signature for header info + * + * Other fields are not used by U-Boot */ struct header0_info_v2 { uint32_t magic; @@ -69,7 +71,9 @@ struct header0_info_v2 { uint16_t size; uint16_t num_images; uint32_t boot_flag; - uint8_t reserved1[104]; + uint8_t reserved1[32]; + uint32_t boot0_param[10]; + uint32_t boot1_param[8]; struct image_entry images[4]; uint8_t reserved2[1064]; uint8_t hash[512]; @@ -491,6 +495,18 @@ static void rkcommon_print_header_v2(const struct header0_info_v2 *hdr) printf("Rockchip Boot Image (v2)\n"); + for (i = 0; i < ARRAY_SIZE(hdr->boot0_param); i++) { + val = le32_to_cpu(hdr->boot0_param[i]); + if (val) + printf("Boot0 %d: 0x%x\n", i, val); + } + + for (i = 0; i < ARRAY_SIZE(hdr->boot1_param); i++) { + val = le32_to_cpu(hdr->boot1_param[i]); + if (val) + printf("Boot1 %d: 0x%x\n", i, val); + } + for (i = 0; i < le16_to_cpu(hdr->num_images); i++) { printf("Image %u: %u @ 0x%x\n", le32_to_cpu(hdr->images[i].counter), From patchwork Wed Jan 29 22:36:30 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonas Karlman X-Patchwork-Id: 2040410 X-Patchwork-Delegate: u-boot@0leil.net Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=kwiboo.se header.i=@kwiboo.se header.a=rsa-sha256 header.s=fe-e1b5cab7be header.b=itJ3Z0+1; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=patchwork.ozlabs.org) Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4YjxqY2q4Jz1ycb for ; Thu, 30 Jan 2025 09:37:29 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 4EC7181FAB; Wed, 29 Jan 2025 23:37:07 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=kwiboo.se Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; secure) header.d=kwiboo.se header.i=@kwiboo.se header.b="itJ3Z0+1"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 249FD81EEF; Wed, 29 Jan 2025 23:37:06 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED,RCVD_IN_VALIDITY_RPBL_BLOCKED, SPF_HELO_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 Received: from smtp.forwardemail.net (smtp.forwardemail.net [207.246.76.47]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id D9F8F80C83 for ; Wed, 29 Jan 2025 23:37:03 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=kwiboo.se Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=SRS0=e4db=UW=kwiboo.se=jonas@fe-bounces.kwiboo.se DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kwiboo.se; h=Content-Transfer-Encoding: MIME-Version: References: In-Reply-To: Message-ID: Date: Subject: Cc: To: From; q=dns/txt; s=fe-e1b5cab7be; t=1738190222; bh=rg8KenFfh653m71UBkTMbTY2ML1aT3VJ51ChxlWbx7E=; b=itJ3Z0+1SwIfAxbKsWXUtzq9ZiD6sHrHNuhDG4IhL5OHxDG7bk8FzNc3DfXETjKemZRcKGzXA Wf09khii0/GMy8M5rLDlP0i8l47i4aQtd6jglyELKdu2ZhEnZAMnesi1ZegbUzkXSdqyPJ5p3Az iqrMHMB/IvOIWff7K6TmWqppd8sXje1q3KZr1ScOQOGUplo6lB551Wp5ecc2cadoNwKRjv3NRep 4wvWjPsKhleS9ya3oWD0Rwt9K27MHk2FyUgWJ/KrUqlqgWTu4W2muBgCrW779qAfsow8t3Z6kgn UIC6CRZpEtAGA9a2CLPDYTtBlyk1MbaHshyAl48+yUeQ== X-Forward-Email-ID: 679aad8a3590a80aa97f8e38 X-Forward-Email-Sender: rfc822; jonas@kwiboo.se, smtp.forwardemail.net, 207.246.76.47 X-Forward-Email-Version: 0.4.40 X-Forward-Email-Website: https://forwardemail.net X-Complaints-To: abuse@forwardemail.net X-Report-Abuse: abuse@forwardemail.net X-Report-Abuse-To: abuse@forwardemail.net From: Jonas Karlman To: Kever Yang , Simon Glass , Philipp Tomsich , Tom Rini Cc: u-boot@lists.denx.de, Jonas Karlman Subject: [PATCH 4/6] rockchip: mkimage: Add option to change image offset alignment Date: Wed, 29 Jan 2025 22:36:30 +0000 Message-ID: <20250129223641.1888833-5-jonas@kwiboo.se> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250129223641.1888833-1-jonas@kwiboo.se> References: <20250129223641.1888833-1-jonas@kwiboo.se> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean The vendor boot_merger tool support a ALIGN parameter that is used to define offset alignment of the embedded images. Vendor use this for RK3576 to change offset alignment from the common 2 KiB to 4 KiB, presumably it may have something to do with UFS. Testing with eMMC has shown that using a 512-byte alignment also work. Add support for overriding offset alignment in case this is needed for e.g. RK3576 in the future. Signed-off-by: Jonas Karlman --- tools/rkcommon.c | 75 +++++++++++++++++++++++++++++++----------------- tools/rkcommon.h | 2 -- 2 files changed, 49 insertions(+), 28 deletions(-) diff --git a/tools/rkcommon.c b/tools/rkcommon.c index 324820717663..542aca931693 100644 --- a/tools/rkcommon.c +++ b/tools/rkcommon.c @@ -124,6 +124,7 @@ struct spl_info { const uint32_t spl_size; const bool spl_rc4; const uint32_t header_ver; + const uint32_t align; }; static struct spl_info spl_infos[] = { @@ -181,14 +182,19 @@ static struct spl_info *rkcommon_get_spl_info(char *imagename) return NULL; } -static int rkcommon_get_aligned_size(struct image_tool_params *params, - const char *fname) +static bool rkcommon_is_header_v2(struct image_tool_params *params) { - int size; + struct spl_info *info = rkcommon_get_spl_info(params->imagename); - size = imagetool_get_filesize(params, fname); - if (size < 0) - return -1; + return (info->header_ver == RK_HEADER_V2); +} + +static int rkcommon_get_aligned_size(struct image_tool_params *params, int size) +{ + struct spl_info *info = rkcommon_get_spl_info(params->imagename); + + if (info->align) + return ROUND(size, info->align * RK_BLK_SIZE); /* * Pad to a 2KB alignment, as required for init/boot size by the ROM @@ -197,6 +203,27 @@ static int rkcommon_get_aligned_size(struct image_tool_params *params, return ROUND(size, RK_SIZE_ALIGN); } +static int rkcommon_get_header_size(struct image_tool_params *params) +{ + int header_size = rkcommon_is_header_v2(params) ? + sizeof(struct header0_info_v2) : + sizeof(struct header0_info); + + return rkcommon_get_aligned_size(params, header_size); +} + +static int rkcommon_get_aligned_filesize(struct image_tool_params *params, + const char *fname) +{ + int size; + + size = imagetool_get_filesize(params, fname); + if (size < 0) + return -1; + + return rkcommon_get_aligned_size(params, size); +} + int rkcommon_check_params(struct image_tool_params *params) { int i, size; @@ -219,14 +246,14 @@ int rkcommon_check_params(struct image_tool_params *params) spl_params.boot_file += 1; } - size = rkcommon_get_aligned_size(params, spl_params.init_file); + size = rkcommon_get_aligned_filesize(params, spl_params.init_file); if (size < 0) return EXIT_FAILURE; spl_params.init_size = size; /* Boot file is optional, and only for back-to-bootrom functionality. */ if (spl_params.boot_file) { - size = rkcommon_get_aligned_size(params, spl_params.boot_file); + size = rkcommon_get_aligned_filesize(params, spl_params.boot_file); if (size < 0) return EXIT_FAILURE; spl_params.boot_size = size; @@ -283,13 +310,6 @@ bool rkcommon_need_rc4_spl(struct image_tool_params *params) return info->spl_rc4; } -bool rkcommon_is_header_v2(struct image_tool_params *params) -{ - struct spl_info *info = rkcommon_get_spl_info(params->imagename); - - return (info->header_ver == RK_HEADER_V2); -} - static void do_sha256_hash(uint8_t *buf, uint32_t size, uint8_t *out) { sha256_context ctx; @@ -302,12 +322,13 @@ static void do_sha256_hash(uint8_t *buf, uint32_t size, uint8_t *out) static void rkcommon_set_header0(void *buf, struct image_tool_params *params) { struct header0_info *hdr = buf; - uint32_t init_boot_size; + uint32_t init_boot_size, init_offset; - memset(buf, '\0', RK_INIT_OFFSET * RK_BLK_SIZE); + init_offset = rkcommon_get_header_size(params) / RK_BLK_SIZE; + memset(buf, '\0', init_offset * RK_BLK_SIZE); hdr->magic = cpu_to_le32(RK_MAGIC); hdr->disable_rc4 = cpu_to_le32(!rkcommon_need_rc4_spl(params)); - hdr->init_offset = cpu_to_le16(RK_INIT_OFFSET); + hdr->init_offset = cpu_to_le16(init_offset); hdr->init_size = cpu_to_le16(spl_params.init_size / RK_BLK_SIZE); /* @@ -335,10 +356,10 @@ static void rkcommon_set_header0_v2(void *buf, struct image_tool_params *params) uint8_t *image_ptr = NULL; int i; - memset(buf, '\0', RK_INIT_OFFSET * RK_BLK_SIZE); + sector_offset = rkcommon_get_header_size(params) / RK_BLK_SIZE; + memset(buf, '\0', sector_offset * RK_BLK_SIZE); hdr->magic = cpu_to_le32(RK_MAGIC_V2); hdr->boot_flag = cpu_to_le32(HASH_SHA256); - sector_offset = 4; image_size_array[0] = spl_params.init_size; image_size_array[1] = spl_params.boot_size; @@ -364,11 +385,12 @@ static void rkcommon_set_header0_v2(void *buf, struct image_tool_params *params) void rkcommon_set_header(void *buf, struct stat *sbuf, int ifd, struct image_tool_params *params) { - struct header1_info *hdr = buf + RK_SPL_HDR_START; - if (rkcommon_is_header_v2(params)) { rkcommon_set_header0_v2(buf, params); } else { + int header_size = rkcommon_get_header_size(params); + struct header1_info *hdr = buf + header_size; + rkcommon_set_header0(buf, params); /* Set up the SPL name (i.e. copy spl_hdr over) */ @@ -376,12 +398,12 @@ void rkcommon_set_header(void *buf, struct stat *sbuf, int ifd, memcpy(&hdr->magic, rkcommon_get_spl_hdr(params), RK_SPL_HDR_SIZE); if (rkcommon_need_rc4_spl(params)) - rkcommon_rc4_encode_spl(buf, RK_SPL_HDR_START, + rkcommon_rc4_encode_spl(buf, header_size, spl_params.init_size); if (spl_params.boot_file) { if (rkcommon_need_rc4_spl(params)) - rkcommon_rc4_encode_spl(buf + RK_SPL_HDR_START, + rkcommon_rc4_encode_spl(buf + header_size, spl_params.init_size, spl_params.boot_size); } @@ -606,7 +628,7 @@ int rkcommon_vrec_header(struct image_tool_params *params, * 4 bytes of these images can safely be overwritten using the * boot magic. */ - tparams->header_size = RK_SPL_HDR_START; + tparams->header_size = rkcommon_get_header_size(params); /* Allocate, clear and install the header */ tparams->hdr = malloc(tparams->header_size); @@ -624,7 +646,8 @@ int rkcommon_vrec_header(struct image_tool_params *params, params->orig_file_size = tparams->header_size + spl_params.init_size + spl_params.boot_size; - params->file_size = ROUND(params->orig_file_size, RK_SIZE_ALIGN); + params->file_size = rkcommon_get_aligned_size(params, + params->orig_file_size); /* Ignoring pad len, since we are using our own copy_image() */ return 0; diff --git a/tools/rkcommon.h b/tools/rkcommon.h index 5d2770a80f1c..c887a659a953 100644 --- a/tools/rkcommon.h +++ b/tools/rkcommon.h @@ -10,9 +10,7 @@ enum { RK_BLK_SIZE = 512, RK_SIZE_ALIGN = 2048, - RK_INIT_OFFSET = 4, RK_MAX_BOOT_SIZE = 512 << 10, - RK_SPL_HDR_START = RK_INIT_OFFSET * RK_BLK_SIZE, RK_SPL_HDR_SIZE = 4, }; From patchwork Wed Jan 29 22:36:31 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonas Karlman X-Patchwork-Id: 2040411 X-Patchwork-Delegate: u-boot@0leil.net Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=kwiboo.se header.i=@kwiboo.se header.a=rsa-sha256 header.s=fe-e1b5cab7be header.b=zedhn/ho; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=patchwork.ozlabs.org) Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Yjxqk1cjmz1ycb for ; Thu, 30 Jan 2025 09:37:38 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 9A2C680C6E; Wed, 29 Jan 2025 23:37:08 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=kwiboo.se Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; secure) header.d=kwiboo.se header.i=@kwiboo.se header.b="zedhn/ho"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 6363581FE8; Wed, 29 Jan 2025 23:37:07 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED,RCVD_IN_VALIDITY_RPBL_BLOCKED, SPF_HELO_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 Received: from smtp.forwardemail.net (smtp.forwardemail.net [149.28.215.223]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id D29C580C8F for ; Wed, 29 Jan 2025 23:37:04 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=kwiboo.se Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=SRS0=e4db=UW=kwiboo.se=jonas@fe-bounces.kwiboo.se DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kwiboo.se; h=Content-Transfer-Encoding: MIME-Version: References: In-Reply-To: Message-ID: Date: Subject: Cc: To: From; q=dns/txt; s=fe-e1b5cab7be; t=1738190223; bh=IbZgzhvdCKnk/9rY0pUCtbeLNrOCl/oHm0ICMv9QfBE=; b=zedhn/hohy9kHDeTz2D4T6ZgXxWM5bjE6LcKKtHWomhlAmeqnZPM8tFAFwwpAWZIsZozOA7qa DC203l6epagBxotHn2/BZZH657eyCF6JfdZFK2x4dRLFqZZOOE0kY5FMsX37cUJxCW4l1vGefgv Mi8p5gvkMMvs9ngSuZUJFItuJvLn00GOyIZCKf7GYsq0SCi4YZE6Qk0ONYzPGx8rQgohQUsjurS 0klu2GcfkbO0FatDjhaRAK5Vwk2OCEe35T6Z4lmBV3WfODjD1VjsIhIeLbZ6WYnHe94lDfZrx00 ZK7JIwMnFBpahigo0o07YLcZIcd7hMf6NH/kCXTg/N/A== X-Forward-Email-ID: 679aad8d3590a80aa97f8e47 X-Forward-Email-Sender: rfc822; jonas@kwiboo.se, smtp.forwardemail.net, 149.28.215.223 X-Forward-Email-Version: 0.4.40 X-Forward-Email-Website: https://forwardemail.net X-Complaints-To: abuse@forwardemail.net X-Report-Abuse: abuse@forwardemail.net X-Report-Abuse-To: abuse@forwardemail.net From: Jonas Karlman To: Kever Yang , Simon Glass , Philipp Tomsich , Tom Rini Cc: u-boot@lists.denx.de, Jonas Karlman Subject: [PATCH 5/6] rockchip: mkimage: Add support for up to 4 input files Date: Wed, 29 Jan 2025 22:36:31 +0000 Message-ID: <20250129223641.1888833-6-jonas@kwiboo.se> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250129223641.1888833-1-jonas@kwiboo.se> References: <20250129223641.1888833-1-jonas@kwiboo.se> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean The v2 image format can support up to 4 embedded images that can be loaded by the BootROM using the back-to-bootrom method. Currently two input files can be passed in using the datafile parameter, separated by a colon (":"). Extend the datafile parameter parsing to support up to 4 input files separated by a colon (":") for use with the v2 image format. Signed-off-by: Jonas Karlman --- tools/rkcommon.c | 93 +++++++++++++++++++++++------------------------- 1 file changed, 44 insertions(+), 49 deletions(-) diff --git a/tools/rkcommon.c b/tools/rkcommon.c index 542aca931693..4ff48e81a636 100644 --- a/tools/rkcommon.c +++ b/tools/rkcommon.c @@ -148,17 +148,15 @@ static struct spl_info spl_infos[] = { /** * struct spl_params - spl params parsed in check_params() * - * @init_file: Init data file path - * @init_size: Aligned size of init data in bytes - * @boot_file: Boot data file path - * @boot_size: Aligned size of boot data in bytes + * @file: image file path + * @size: aligned size of image in bytes */ struct spl_params { - char *init_file; - uint32_t init_size; - char *boot_file; - uint32_t boot_size; + struct { + char *file; + uint32_t size; + } images[4]; }; static struct spl_params spl_params = { 0 }; @@ -238,31 +236,32 @@ int rkcommon_check_params(struct image_tool_params *params) if (!rkcommon_get_spl_info(params->imagename)) goto err_spl_info; - spl_params.init_file = params->datafile; + spl_params.images[0].file = params->datafile; + for (i = 1; i < ARRAY_SIZE(spl_params.images); i++) { + spl_params.images[i].file = + strchr(spl_params.images[i - 1].file, ':'); + if (!spl_params.images[i].file) + break; - spl_params.boot_file = strchr(spl_params.init_file, ':'); - if (spl_params.boot_file) { - *spl_params.boot_file = '\0'; - spl_params.boot_file += 1; + *spl_params.images[i].file = '\0'; + spl_params.images[i].file += 1; } - size = rkcommon_get_aligned_filesize(params, spl_params.init_file); - if (size < 0) - return EXIT_FAILURE; - spl_params.init_size = size; + for (i = 0; i < ARRAY_SIZE(spl_params.images); i++) { + if (!spl_params.images[i].file) + break; - /* Boot file is optional, and only for back-to-bootrom functionality. */ - if (spl_params.boot_file) { - size = rkcommon_get_aligned_filesize(params, spl_params.boot_file); + size = rkcommon_get_aligned_filesize(params, + spl_params.images[i].file); if (size < 0) return EXIT_FAILURE; - spl_params.boot_size = size; + spl_params.images[i].size = size; } - if (spl_params.init_size > rkcommon_get_spl_size(params)) { + if (spl_params.images[0].size > rkcommon_get_spl_size(params)) { fprintf(stderr, "Error: SPL image is too large (size %#x than %#x)\n", - spl_params.init_size, rkcommon_get_spl_size(params)); + spl_params.images[0].size, rkcommon_get_spl_size(params)); return EXIT_FAILURE; } @@ -329,7 +328,7 @@ static void rkcommon_set_header0(void *buf, struct image_tool_params *params) hdr->magic = cpu_to_le32(RK_MAGIC); hdr->disable_rc4 = cpu_to_le32(!rkcommon_need_rc4_spl(params)); hdr->init_offset = cpu_to_le16(init_offset); - hdr->init_size = cpu_to_le16(spl_params.init_size / RK_BLK_SIZE); + hdr->init_size = cpu_to_le16(spl_params.images[0].size / RK_BLK_SIZE); /* * init_boot_size needs to be set, as it is read by the BootROM @@ -339,10 +338,11 @@ static void rkcommon_set_header0(void *buf, struct image_tool_params *params) * see https://lists.denx.de/pipermail/u-boot/2017-May/293267.html * for a more detailed explanation by Andy Yan */ - if (spl_params.boot_file) - init_boot_size = spl_params.init_size + spl_params.boot_size; + if (spl_params.images[1].file) + init_boot_size = spl_params.images[0].size + + spl_params.images[1].size; else - init_boot_size = spl_params.init_size + RK_MAX_BOOT_SIZE; + init_boot_size = spl_params.images[0].size + RK_MAX_BOOT_SIZE; hdr->init_boot_size = cpu_to_le16(init_boot_size / RK_BLK_SIZE); rc4_encode(buf, RK_BLK_SIZE, rc4_key); @@ -352,7 +352,6 @@ static void rkcommon_set_header0_v2(void *buf, struct image_tool_params *params) { struct header0_info_v2 *hdr = buf; uint32_t sector_offset, image_sector_count; - uint32_t image_size_array[2]; uint8_t *image_ptr = NULL; int i; @@ -360,19 +359,17 @@ static void rkcommon_set_header0_v2(void *buf, struct image_tool_params *params) memset(buf, '\0', sector_offset * RK_BLK_SIZE); hdr->magic = cpu_to_le32(RK_MAGIC_V2); hdr->boot_flag = cpu_to_le32(HASH_SHA256); - image_size_array[0] = spl_params.init_size; - image_size_array[1] = spl_params.boot_size; - for (i = 0; i < 2; i++) { - if (!image_size_array[i]) + for (i = 0; i < ARRAY_SIZE(spl_params.images); i++) { + if (!spl_params.images[i].size) break; - image_sector_count = image_size_array[i] / RK_BLK_SIZE; + image_sector_count = spl_params.images[i].size / RK_BLK_SIZE; hdr->images[i].offset = cpu_to_le16(sector_offset); hdr->images[i].size = cpu_to_le16(image_sector_count); hdr->images[i].address = 0xFFFFFFFF; hdr->images[i].counter = cpu_to_le32(i + 1); image_ptr = buf + sector_offset * RK_BLK_SIZE; - do_sha256_hash(image_ptr, image_size_array[i], + do_sha256_hash(image_ptr, spl_params.images[i].size, hdr->images[i].hash); sector_offset = sector_offset + image_sector_count; } @@ -399,13 +396,13 @@ void rkcommon_set_header(void *buf, struct stat *sbuf, int ifd, if (rkcommon_need_rc4_spl(params)) rkcommon_rc4_encode_spl(buf, header_size, - spl_params.init_size); + spl_params.images[0].size); - if (spl_params.boot_file) { + if (spl_params.images[1].file) { if (rkcommon_need_rc4_spl(params)) rkcommon_rc4_encode_spl(buf + header_size, - spl_params.init_size, - spl_params.boot_size); + spl_params.images[0].size, + spl_params.images[1].size); } } } @@ -643,8 +640,9 @@ int rkcommon_vrec_header(struct image_tool_params *params, * We need to store the original file-size (i.e. before padding), as * imagetool does not set this during its adjustment of file_size. */ - params->orig_file_size = tparams->header_size + - spl_params.init_size + spl_params.boot_size; + params->orig_file_size = tparams->header_size; + for (int i = 0; i < ARRAY_SIZE(spl_params.images); i++) + params->orig_file_size += spl_params.images[i].size; params->file_size = rkcommon_get_aligned_size(params, params->orig_file_size); @@ -731,16 +729,13 @@ err_close: int rockchip_copy_image(int ifd, struct image_tool_params *params) { - int ret; - - ret = copy_file(params, ifd, spl_params.init_file, - spl_params.init_size); - if (ret) - return ret; + int i, ret; - if (spl_params.boot_file) { - ret = copy_file(params, ifd, spl_params.boot_file, - spl_params.boot_size); + for (i = 0; i < ARRAY_SIZE(spl_params.images); i++) { + if (!spl_params.images[i].size) + break; + ret = copy_file(params, ifd, spl_params.images[i].file, + spl_params.images[i].size); if (ret) return ret; } From patchwork Wed Jan 29 22:36:32 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonas Karlman X-Patchwork-Id: 2040412 X-Patchwork-Delegate: u-boot@0leil.net Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=kwiboo.se header.i=@kwiboo.se header.a=rsa-sha256 header.s=fe-e1b5cab7be header.b=T86Mo5o9; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=patchwork.ozlabs.org) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Yjxqt6Vb6z1ycb for ; Thu, 30 Jan 2025 09:37:46 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id EB43380C85; Wed, 29 Jan 2025 23:37:11 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=kwiboo.se Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; secure) header.d=kwiboo.se header.i=@kwiboo.se header.b="T86Mo5o9"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 2B5E080AE5; Wed, 29 Jan 2025 23:37:11 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED,RCVD_IN_VALIDITY_RPBL_BLOCKED, SPF_HELO_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 Received: from smtp.forwardemail.net (smtp.forwardemail.net [207.246.76.47]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id E106C81EEF for ; Wed, 29 Jan 2025 23:37:08 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=kwiboo.se Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=SRS0=e4db=UW=kwiboo.se=jonas@fe-bounces.kwiboo.se DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kwiboo.se; h=Content-Transfer-Encoding: MIME-Version: References: In-Reply-To: Message-ID: Date: Subject: Cc: To: From; q=dns/txt; s=fe-e1b5cab7be; t=1738190227; bh=YRwoQu/NI1tLn6cZ7Tx97f0/zKgLtIH7H59u6fRODrg=; b=T86Mo5o9qGLdWlwBE2RylgYABdPVgDls+2vhs/c+rBLTYu01apaCBaOIiaeyJZ4yksYODJiLZ nW7rULEK1qETtAXMFeD4utIur2e/9Y95COrIC88SpeD9KQcffv3pDjsZzGP5M4AB77LNiuxww0h 148HM7X6jedlxWI4EjboPZ6mOpxBbwW+Yfz6YeCsxC/UAt0MZBXm61d29TdQ+iYXiLBJPMY9sqw +uyc3uSq36+EjEYgx3iIj6MewZ6lDHcffWXVZCTCiJrH+V+8Zz15ZkOa6s4eoGn+hH415ikffLT Zph3hLAWhWRUVxPdVPQqWKD6LwFyxvNbiC7Rb0Iy94lw== X-Forward-Email-ID: 679aad903590a80aa97f8e56 X-Forward-Email-Sender: rfc822; jonas@kwiboo.se, smtp.forwardemail.net, 207.246.76.47 X-Forward-Email-Version: 0.4.40 X-Forward-Email-Website: https://forwardemail.net X-Complaints-To: abuse@forwardemail.net X-Report-Abuse: abuse@forwardemail.net X-Report-Abuse-To: abuse@forwardemail.net From: Jonas Karlman To: Kever Yang , Simon Glass , Philipp Tomsich , Tom Rini Cc: u-boot@lists.denx.de, Jonas Karlman Subject: [PATCH 6/6] rockchip: mkimage: Add option for image load address and flag Date: Wed, 29 Jan 2025 22:36:32 +0000 Message-ID: <20250129223641.1888833-7-jonas@kwiboo.se> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250129223641.1888833-1-jonas@kwiboo.se> References: <20250129223641.1888833-1-jonas@kwiboo.se> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean The v2 image format supports defining a load address and flag for each embedded image. Add initial support for writing the image load address and flag to the v2 image format header. This may later be used for RK3576 to embed a minimal initial image that if required to fix booting from SD-card due to a BootROM issue. Signed-off-by: Jonas Karlman --- tools/rkcommon.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tools/rkcommon.c b/tools/rkcommon.c index 4ff48e81a636..952b76297dd9 100644 --- a/tools/rkcommon.c +++ b/tools/rkcommon.c @@ -150,12 +150,16 @@ static struct spl_info spl_infos[] = { * * @file: image file path * @size: aligned size of image in bytes + * @address: image load address + * @flag: no use */ struct spl_params { struct { char *file; uint32_t size; + uint32_t address; + uint32_t flag; } images[4]; }; @@ -366,7 +370,8 @@ static void rkcommon_set_header0_v2(void *buf, struct image_tool_params *params) image_sector_count = spl_params.images[i].size / RK_BLK_SIZE; hdr->images[i].offset = cpu_to_le16(sector_offset); hdr->images[i].size = cpu_to_le16(image_sector_count); - hdr->images[i].address = 0xFFFFFFFF; + hdr->images[i].address = spl_params.images[i].address ?: 0xFFFFFFFF; + hdr->images[i].flag = spl_params.images[i].flag; hdr->images[i].counter = cpu_to_le32(i + 1); image_ptr = buf + sector_offset * RK_BLK_SIZE; do_sha256_hash(image_ptr, spl_params.images[i].size,