From patchwork Mon Jan 27 16:19:48 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joel Johnson X-Patchwork-Id: 1229934 X-Patchwork-Delegate: sr@denx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: 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=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=lixil.net 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 RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 485w3617lZz9sPJ for ; Tue, 28 Jan 2020 03:20:49 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 9ECF181A65; Mon, 27 Jan 2020 17:20:23 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=lixil.net Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Received: by phobos.denx.de (Postfix, from userid 109) id 9D04081A4F; Mon, 27 Jan 2020 17:20:09 +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=0.0 required=5.0 tests=SPF_HELO_PASS, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from crane.lixil.net (crane.lixil.net [71.19.154.81]) by phobos.denx.de (Postfix) with ESMTP id 4619F81A23 for ; Mon, 27 Jan 2020 17:19:57 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=lixil.net Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=mrjoel@lixil.net Received: from dark.lixil.net (unknown [IPv6:2601:8c3:4100:b411:acb8:69dc:1c78:fefe]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: mrjoel@lixil.net) by crane.lixil.net (Postfix) with ESMTPSA id A8C3E321CDF; Mon, 27 Jan 2020 09:19:54 -0700 (MST) From: Joel Johnson To: Stefan Roese Subject: [PATCH 3/4] cmd: mvebu: bubt: verify A38x target device type Date: Mon, 27 Jan 2020 09:19:48 -0700 Message-Id: <20200127161949.15501-3-mrjoel@lixil.net> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200127161949.15501-1-mrjoel@lixil.net> References: <20200127161949.15501-1-mrjoel@lixil.net> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.26 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Joe Hershberger , Baruch Siach , u-boot@lists.denx.de Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.101.4 at phobos.denx.de X-Virus-Status: Clean Ensure that the device to which an image is being written includes header information indicating boot support for the destination device. This is derived from the support in the SolidRun master-a38x vendor fork branch. Signed-off-by: Joel Johnson --- cmd/mvebu/bubt.c | 49 ++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 47 insertions(+), 2 deletions(-) diff --git a/cmd/mvebu/bubt.c b/cmd/mvebu/bubt.c index b80b81c82a..78061a6a2d 100644 --- a/cmd/mvebu/bubt.c +++ b/cmd/mvebu/bubt.c @@ -107,6 +107,26 @@ struct a38x_main_hdr_v1 { u8 ext; /* 0x1E */ u8 checksum; /* 0x1F */ }; + +#define A38X_BOOT_MODE_MAX 8 + +struct a38x_boot_mode { + unsigned int id; + const char *name; +}; + +/* The blockid header field values used to indicate boot device of image */ +struct a38x_boot_mode a38x_boot_modes[A38X_BOOT_MODE_MAX] = { + { 0x4D, "i2c" }, + { 0x5A, "spi" }, + { 0x69, "uart" }, + { 0x78, "sata" }, + { 0x8B, "nand" }, + { 0x9C, "pex" }, + { 0xAE, "mmc" }, + {}, +}; + #endif struct bubt_dev { @@ -644,6 +664,23 @@ static int check_image_header(void) return 0; } #elif defined(CONFIG_ARMADA_38X) +static int a38x_check_boot_mode(const struct bubt_dev *dst) +{ + int mode; + const struct a38x_main_hdr_v1 *hdr = + (struct a38x_main_hdr_v1 *)get_load_addr(); + + for (mode = 0; mode < A38X_BOOT_MODE_MAX; mode++) { + if (strcmp(a38x_boot_modes[mode].name, dst->name) == 0) + break; + } + + if (a38x_boot_modes[mode].id == hdr->blockid) + return 0; + + return -ENOEXEC; +} + static size_t a38x_header_size(const struct a38x_main_hdr_v1 *h) { if (h->version == 1) @@ -697,7 +734,7 @@ static int check_image_header(void) } #endif -static int bubt_verify(size_t image_size) +static int bubt_verify(const struct bubt_dev *dst) { int err; @@ -708,6 +745,14 @@ static int bubt_verify(size_t image_size) return err; } +#if defined(CONFIG_ARMADA_38X) + err = a38x_check_boot_mode(dst); + if (err) { + puts("Error: image not built for destination device!\n"); + return err; + } +#endif + return 0; } @@ -829,7 +874,7 @@ int do_bubt_cmd(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) if (!image_size) return -EIO; - err = bubt_verify(image_size); + err = bubt_verify(dst); if (err) return err;