From patchwork Thu Aug 20 15:11:05 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rayagonda Kokatanur X-Patchwork-Id: 1348440 X-Patchwork-Delegate: trini@ti.com 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=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=quarantine dis=none) header.from=broadcom.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=broadcom.com header.i=@broadcom.com header.a=rsa-sha256 header.s=google header.b=IJKDBgIv; dkim-atps=neutral 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 RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4BXSmX04Pnz9sTy for ; Fri, 21 Aug 2020 01:11:55 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 336F08236C; Thu, 20 Aug 2020 17:11:40 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=quarantine dis=none) header.from=broadcom.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=broadcom.com header.i=@broadcom.com header.b="IJKDBgIv"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 228C08236B; Thu, 20 Aug 2020 17:11:39 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,SPF_HELO_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-pg1-x536.google.com (mail-pg1-x536.google.com [IPv6:2607:f8b0:4864:20::536]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id E5DAF8237B for ; Thu, 20 Aug 2020 17:11:34 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=quarantine dis=none) header.from=broadcom.com Authentication-Results: phobos.denx.de; spf=fail smtp.mailfrom=rayagonda.kokatanur@broadcom.com Received: by mail-pg1-x536.google.com with SMTP id d19so1267624pgl.10 for ; Thu, 20 Aug 2020 08:11:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=YU4JT1FzBU9zODX2EiCSE8FzPWcqzCnLfpq+oaLDWF0=; b=IJKDBgIv9kY3k/1eMAoF+lwHBBb0szJNVyEUQF4TUsc4bf9L/l69sxU0pqhMOUm/75 BxdDZIVcVTJ/KpCDUHKH9mQ36K3XsQr7VH93AfW0xhrpFyz96fqqAPDv0zkA2Bp5xm5d TtVBQncmWdWaULvjWl9ZEXmhiMM45M5uLQE90= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=YU4JT1FzBU9zODX2EiCSE8FzPWcqzCnLfpq+oaLDWF0=; b=iS3TKRJp5Z1fonnwyA/NEklX1f0fcuVSbrnTiiEXI/iuw1lEgXRa6UWw7oo/eKYPR+ VVyb0CWqavJeGlQ6AVeXxG97HEIfysePOeeeee95MIW1Wrc+BZCCUzLWKKPyx+4AqK5W 5tTHWHwj8cGCwZR1jnpJR/ULxoJlqWSoTBGn4/HaBVSB5R5pX1ZsLhwXYJrnXER5842f hgBFLSTrQ8BwrN+YLyMIw/5R2G5q6ksBFQ9rTME2I8FmhRzdFkcDHb1PQDhwdubL4E8S 4g+JgoqcLIa1I+wWfwrA9R4kSzchLf0xNC/pqPZjOQhtcPsT6nj9aBrvAwebD2NqincQ We1A== X-Gm-Message-State: AOAM531R8L5S8Z8BsxM2n8hcRHezgdwr8HjHOZQG1gV9iJhk0AyzUxLy uoUMc7qSf2BBSrfw1YWvrgwbuMI57Oxc0ha0+qQfmlHxe3gSr8Ez8foPofylne+qwlQIOUkkioi oXsB/M4frtt+HQc2Lu79BLLc6+4tjWIj6oXvYKkQWeT6UUOemwuT1Yp/4i7YMtZfFJe3hHqvkG5 KY2uevZOl0 X-Google-Smtp-Source: ABdhPJwsHlMI2tlLphmucmZMU0Jb+GWAGy1spJMz4VadHLjec/tg6vdrztwxSsmfqARzCgInnqhYaw== X-Received: by 2002:a63:5a41:: with SMTP id k1mr2694827pgm.346.1597936292822; Thu, 20 Aug 2020 08:11:32 -0700 (PDT) Received: from rayagonda.dhcp.broadcom.net ([192.19.234.250]) by smtp.gmail.com with ESMTPSA id e23sm2861014pgb.79.2020.08.20.08.11.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Aug 2020 08:11:32 -0700 (PDT) From: Rayagonda Kokatanur To: u-boot@lists.denx.de, Simon Glass , Tom Rini , Bharat Gooty , Vladimir Olovyannikov Cc: Vikas Gupta , Rayagonda Kokatanur Subject: [PATCH v2 2/5] cmd: broadcom: add cmd to update bnxt image env variables Date: Thu, 20 Aug 2020 20:41:05 +0530 Message-Id: <20200820151108.5503-3-rayagonda.kokatanur@broadcom.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200820151108.5503-1-rayagonda.kokatanur@broadcom.com> References: <20200820151108.5503-1-rayagonda.kokatanur@broadcom.com> X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 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.102.3 at phobos.denx.de X-Virus-Status: Clean From: Vikas Gupta Add command to update the environmental variables which are used to read the data from QSPI offsets and load the binaries to bnxt. Signed-off-by: Vikas Gupta Signed-off-by: Rayagonda Kokatanur Reviewed-by: Simon Glass --- Changes from V1: -Address review comments from Simon, Rearrange header files. Use lower case hex. Rename struct name from nitro_img_header to img_header. Drop unnecessary type cast. Check returun value for env_set_hex(). cmd/broadcom/Makefile | 1 + cmd/broadcom/nitro_image_load.c | 125 ++++++++++++++++++++++++++++++++ 2 files changed, 126 insertions(+) create mode 100644 cmd/broadcom/nitro_image_load.c diff --git a/cmd/broadcom/Makefile b/cmd/broadcom/Makefile index 22ccf2f334..6cdece1a3a 100644 --- a/cmd/broadcom/Makefile +++ b/cmd/broadcom/Makefile @@ -2,3 +2,4 @@ # Copyright 2020 Broadcom obj-y += chimp_boot.o +obj-y += nitro_image_load.o diff --git a/cmd/broadcom/nitro_image_load.c b/cmd/broadcom/nitro_image_load.c new file mode 100644 index 0000000000..4a36b300c4 --- /dev/null +++ b/cmd/broadcom/nitro_image_load.c @@ -0,0 +1,125 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright 2020 Broadcom + */ + +#include +#include + +#define FW_IMAGE_SIG 0xff123456 +#define CFG_IMAGE_SIG 0xcf54321a + +/* + * structure for bin file + * signature: fw itb file + * size: fw itb file + * signature: NS3 config file + * size: NS3 config file + * Data: fw itb file + * ............................ + * ............................ + * Data: NS3 config file + * ............................ + * ............................ + */ + +static struct img_header { + u32 bin_sig; + u32 bin_size; + u32 cfg1_sig; + u32 cfg1_size; +} *img_header; + +static int env_set_val(const char *varname, ulong val) +{ + int ret; + + ret = env_set_hex(varname, val); + if (ret) + pr_err("Failed to %s env var\n", varname); + + return ret; +} + +static int do_spi_images_addr(struct cmd_tbl *cmdtp, int flag, int argc, + char *const argv[]) +{ + uintptr_t images_load_addr; + uintptr_t spi_load_addr; + u32 len; + u32 spi_data_offset = sizeof(struct img_header); + + if (argc != 3) + return CMD_RET_USAGE; + + /* convert command parameter to fastboot address (base 16), i.e. hex */ + images_load_addr = simple_strtoul(argv[1], NULL, 16); + if (!images_load_addr) { + pr_err("Invalid load address\n"); + return CMD_RET_USAGE; + } + + spi_load_addr = simple_strtoul(argv[2], NULL, 16); + if (!spi_load_addr) { + pr_err("Invalid spi load address\n"); + return CMD_RET_USAGE; + } + + img_header = (struct img_header *)images_load_addr; + + if (img_header->bin_sig != FW_IMAGE_SIG) { + pr_err("Invalid Nitro bin file\n"); + goto error; + } + + if (env_set_val("spi_nitro_fw_itb_start_addr", 0)) + goto error; + + if (env_set_val("spi_nitro_fw_itb_len", 0)) + goto error; + + if (env_set_val("spi_nitro_fw_ns3_cfg_start_addr", 0)) + goto error; + + if (env_set_val("spi_nitro_fw_ns3_cfg_len", 0)) + goto error; + + len = img_header->bin_size; + + if (env_set_val("spi_nitro_fw_itb_start_addr", + (spi_load_addr + spi_data_offset))) + goto error; + + if (env_set_val("spi_nitro_fw_itb_len", img_header->bin_size)) + goto error; + + spi_data_offset += len; + + if (img_header->cfg1_sig == CFG_IMAGE_SIG) { + len = img_header->cfg1_size; + + if (env_set_val("spi_nitro_fw_ns3_cfg_start_addr", + (spi_load_addr + spi_data_offset))) + goto error; + + if (env_set_val("spi_nitro_fw_ns3_cfg_len", len)) + goto error; + + spi_data_offset += len; + } + + /* disable secure boot */ + if (env_set_val("nitro_fastboot_secure", 0)) + goto error; + + return CMD_RET_SUCCESS; + +error: + return CMD_RET_FAILURE; +} + +U_BOOT_CMD + (spi_nitro_images_addr, 3, 1, do_spi_images_addr, + "Load the bnxt bin header and sets envs ", + "spi_nitro_images_addr \n" +);