From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 77A88C77B75 for ; Fri, 5 May 2023 08:21:31 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 951A7846B1; Fri, 5 May 2023 10:21:19 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=solid-run.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=solidrn.onmicrosoft.com header.i=@solidrn.onmicrosoft.com header.b="Td7Akvng"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 08474846B1; Fri, 5 May 2023 10:21:18 +0200 (CEST) Received: from EUR04-DB3-obe.outbound.protection.outlook.com (mail-db3eur04on061c.outbound.protection.outlook.com [IPv6:2a01:111:f400:fe0c::61c]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 02FA0846B6 for ; Fri, 5 May 2023 10:21:15 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=solid-run.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=josua@solid-run.com ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=aaT5QAj2ISUO9x4Ir0mOekVcdTtjGLeMA6AqJQh7s/eVMIPl/Pk+4N+IW39nimC/J2MxIM792HjbbRYgK4Sq+Emd/Y3u/2tOBtuOT7QCJfHXAydvewSj1jdc/zQRkKn9NVrmLBXcMzEBSbd/4wXo21/hOhlotfIU1cUm9fG30XpjsU985mvKD0cPb4pYTLDvIUCRVih9r581pGTXsASwmeIqIsOjES5i/7j/YYxWZ7BfAs8/kokBA72YCOIaP+K2T4uepJNfHQTi6swHDTrP8aDgEFVjrjpPSxYJvmGyF8wOzfEhqNmo2Cc19aQIu68JBMgH64Z3bUojNqg9f4libA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=dFk7Vw/Rt6WbMc9vlNyD7tfwGX5iPyR1liL+6hL8H+s=; b=d/B5tEeeGW39fbgJ5jmnVnBxbsZoMXaOD6s9pFUjfN9RIEwPFrIaZuhBxi5OaW29LeZEe8rX+nwnWF82RQS/fu57JQImifDykXb72zydOkSPOdDgTUe877aR2Cbge4mXqKCVD0exIAWQfu/3BHWeXfaqjwWQhzFjOVp45Cb+RSGGSITShOXnpUiaPS2N4xilzAIUb7KNhjHzqbYtTjlueRS512Xe8fWDbASr/83OO2Q6P5IT3O3nHQdUx1VPqn+keh464VFOUHEEn2EsQZSFW6tfKjIWIuvAcBv91P3DIIQHNJnxOE1GKSG5V3UJX3zil+SYjZzDDN3obpekPnX4Bg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=solid-run.com; dmarc=pass action=none header.from=solid-run.com; dkim=pass header.d=solid-run.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=solidrn.onmicrosoft.com; s=selector1-solidrn-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=dFk7Vw/Rt6WbMc9vlNyD7tfwGX5iPyR1liL+6hL8H+s=; b=Td7AkvngiGsGi7IeSDSFZpsJ7RxcXFkQVDvYfbeH59uhuTHj0ppbHXatfmLA1tV2druolNkP/oA+HiC1+3g76PsILupN8SLfQCB/u2RbycgrVRvAsaasizj0Q6rDV7123eCVfUBE2anhl3snjr2orWvNY51YACyVt+c22+c4aws= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=solid-run.com; Received: from AS8PR04MB8963.eurprd04.prod.outlook.com (2603:10a6:20b:42e::18) by AS8PR04MB7926.eurprd04.prod.outlook.com (2603:10a6:20b:2ab::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6363.27; Fri, 5 May 2023 08:21:13 +0000 Received: from AS8PR04MB8963.eurprd04.prod.outlook.com ([fe80::9e27:8c41:a8d:938e]) by AS8PR04MB8963.eurprd04.prod.outlook.com ([fe80::9e27:8c41:a8d:938e%3]) with mapi id 15.20.6363.027; Fri, 5 May 2023 08:21:13 +0000 From: Josua Mayer To: u-boot@lists.denx.de Cc: Josua Mayer , Stefan Roese , Baruch Siach , Heinrich Schuchardt Subject: [[PATCH v2] 1/4] cmd: tlv_eeprom: remove use of global variable current_dev Date: Fri, 5 May 2023 11:20:46 +0300 Message-Id: <20230505082049.9768-2-josua@solid-run.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230505082049.9768-1-josua@solid-run.com> References: <20230505082049.9768-1-josua@solid-run.com> Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: VI1PR0401CA0013.eurprd04.prod.outlook.com (2603:10a6:800:4a::23) To AS8PR04MB8963.eurprd04.prod.outlook.com (2603:10a6:20b:42e::18) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8PR04MB8963:EE_|AS8PR04MB7926:EE_ X-MS-Office365-Filtering-Correlation-Id: 5be54969-2a2c-40d7-fd70-08db4d41b06f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: S3c46urkGKxxGxh/lEo2tY0DmRuFRiMZNe+FV6wqlXFtH+bSBGBhMnnblDkO16m50/ngwv9sPVIuICnMjpEiMUpCd0mEW5KLD+r1Nnt+czJms+0TVPA9//065UC30bGs4hps4xh2WB1k4nUBU87gwgxax9ps9xbLpoI0kVGDwH6Thf0A+rC0MhjZqma51c1Z0FrBebPQ1VdvT/GfUbvxRQ4hBTmih9LzMzmuvSuVKiwytPAkp3wwVUvd+eWPv1Xp8RM06caQ5tjfvD14EHfYRAwrRHcHQzr1oxfcORlYinGf2LjNVcWemHP72bwNOM4iqkzoMpsiJehnyMOPFbBY3crNriQdRNlw3wybc1NpGWVuxpOhLuin+aHsc8EB+9Sn+WitsTaAzFDuw5iKer5/7/vkxwtRo07n6nxtKv9aaOLF0Cca2o4LgjQ7i/PWZVbBykSp6rOk6MOcrIGUCRVVGZO0rWIyx3Lm932KeBAQyEQPb+yWk26IF1gMpj4tCgLyRRRkpIw9LpoIlUZHpDs8TS4P1Mg+htX3yi9sk+FLJmJV9PJBz2PrK1ziTvO3SruD X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AS8PR04MB8963.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230028)(39840400004)(366004)(136003)(396003)(346002)(376002)(451199021)(52116002)(478600001)(6916009)(4326008)(66946007)(66556008)(66476007)(6486002)(316002)(54906003)(6666004)(86362001)(36756003)(83380400001)(2616005)(6506007)(1076003)(6512007)(8936002)(5660300002)(8676002)(41300700001)(2906002)(186003)(38100700002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?Eu5dmRdGa32PeVJWrCrmJe+Ndi2lKWzJHkRLLk/RcDVlfcAdTKpuiR5P0aEb?= =?us-ascii?Q?kkB46e8Ypu3C7Uq22bqEu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KnbQ2O?= =?us-ascii?Q?IrKigIU6G5QFwOwqmSjxmeJmWuY6pIEOHq80wtxW+yWdTXk0wMd2AW5dSVpV?= =?us-ascii?Q?ORR7xMXAy1YgF1iSCi7nISj99rCWpgvCztPBwJib8S5UkKMkJTapxh1Eq3f0?= =?us-ascii?Q?g4d/RqWePECWRXdcfoOVMGEsdE7+NrzJFFsu8/zfDJv0fxYZC1fU9xOubEBZ?= =?us-ascii?Q?VVXgdn/VFCMQIJddJYCmpM3qRe+UFICl4vbGH1i9N4VjdsPANAEO5NjiY31u?= =?us-ascii?Q?wC1y2xVx4AYoYYN3JFM9MDho+uJ6v3wOxqpiOgIvpt8uY/rHHKworcr8J5sv?= =?us-ascii?Q?75KbEpIKcil6fnAQjDDNAQDN8VnebsfNdgVXJJojcEqKov1TBmJAnRU2dbHu?= =?us-ascii?Q?2e0zxCWxmb5GpwqkpB2UP4iFvRvLSqsQU+l7i59PzBDXdpS4kiJM09mz7LnM?= =?us-ascii?Q?jCa1hhNaml2osITM6zCCsNbmmsjc8taMdlb9FjnXcRCbVvFrJAWWFX6FZUTx?= =?us-ascii?Q?NUAyJC28fYox5cGSY9F7lc75P2O2D/Ol6qheI0NyAjb0lfxx3eqxoR7HzdZe?= =?us-ascii?Q?LMZirkwr6sgGfIr0a+YrZ3MVdr5rgfSRcwJ1aFU/h5spNjKtYrTXNAKDd8CA?= =?us-ascii?Q?iyQ58ObQrzuoaffAmaoh3ad1rpP92KyWqMbov+u2Q1JKk7o5K9nV8hJv/rpF?= =?us-ascii?Q?/oEwnAXNtUBU3Fpqwaps+9g=3D?= X-OriginatorOrg: solid-run.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5be54969-2a2c-40d7-fd70-08db4d41b06f X-MS-Exchange-CrossTenant-AuthSource: AS8PR04MB8963.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 May 2023 08:21:13.2815 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: a4a8aaf3-fd27-4e27-add2-604707ce5b82 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: HUiNqOmw6yU+RR5XA49jinFAaT/5m3J/Y+KEP5Ju75j3c3ccXJ5rgBjJa3j68MXE/8+ccz05HrlQpD5Nz5T1HQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR04MB7926 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 Make tlv_eeprom command device selection an explicit parameter of all function calls. Signed-off-by: Josua Mayer Cc: Stefan Roese Cc: Baruch Siach Cc: Heinrich Schuchardt --- cmd/tlv_eeprom.c | 50 ++++++++++++++++++++++---------------------- include/tlv_eeprom.h | 3 ++- 2 files changed, 27 insertions(+), 26 deletions(-) diff --git a/cmd/tlv_eeprom.c b/cmd/tlv_eeprom.c index 4591ff336bb..8049bf9843c 100644 --- a/cmd/tlv_eeprom.c +++ b/cmd/tlv_eeprom.c @@ -29,18 +29,18 @@ DECLARE_GLOBAL_DATA_PTR; /* File scope function prototypes */ static bool is_checksum_valid(u8 *eeprom); -static int read_eeprom(u8 *eeprom); -static void show_eeprom(u8 *eeprom); +static int read_eeprom(int devnum, u8 *eeprom); +static void show_eeprom(int devnum, u8 *eeprom); static void decode_tlv(struct tlvinfo_tlv *tlv); static void update_crc(u8 *eeprom); -static int prog_eeprom(u8 *eeprom); +static int prog_eeprom(int devnum, u8 *eeprom); static bool tlvinfo_find_tlv(u8 *eeprom, u8 tcode, int *eeprom_index); static bool tlvinfo_delete_tlv(u8 *eeprom, u8 code); static bool tlvinfo_add_tlv(u8 *eeprom, int tcode, char *strval); static int set_mac(char *buf, const char *string); static int set_date(char *buf, const char *string); static int set_bytes(char *buf, const char *string, int *converted_accum); -static void show_tlv_devices(void); +static void show_tlv_devices(int current_dev); /* Set to 1 if we've read EEPROM into memory */ static int has_been_read; @@ -48,7 +48,6 @@ static int has_been_read; static u8 eeprom[TLV_INFO_MAX_LEN]; static struct udevice *tlv_devices[MAX_TLV_DEVICES]; -static unsigned int current_dev; #define to_header(p) ((struct tlvinfo_header *)p) #define to_entry(p) ((struct tlvinfo_tlv *)p) @@ -125,7 +124,7 @@ static bool is_checksum_valid(u8 *eeprom) * * Read the EEPROM into memory, if it hasn't already been read. */ -static int read_eeprom(u8 *eeprom) +static int read_eeprom(int devnum, u8 *eeprom) { int ret; struct tlvinfo_header *eeprom_hdr = to_header(eeprom); @@ -135,12 +134,11 @@ static int read_eeprom(u8 *eeprom) return 0; /* Read the header */ - ret = read_tlv_eeprom((void *)eeprom_hdr, 0, HDR_SIZE, current_dev); + ret = read_tlv_eeprom((void *)eeprom_hdr, 0, HDR_SIZE, devnum); /* If the header was successfully read, read the TLVs */ if (ret == 0 && is_valid_tlvinfo_header(eeprom_hdr)) ret = read_tlv_eeprom((void *)eeprom_tlv, HDR_SIZE, - be16_to_cpu(eeprom_hdr->totallen), - current_dev); + be16_to_cpu(eeprom_hdr->totallen), devnum); // If the contents are invalid, start over with default contents if (!is_valid_tlvinfo_header(eeprom_hdr) || @@ -165,7 +163,7 @@ static int read_eeprom(u8 *eeprom) * * Display the contents of the EEPROM */ -static void show_eeprom(u8 *eeprom) +static void show_eeprom(int devnum, u8 *eeprom) { int tlv_end; int curr_tlv; @@ -180,7 +178,7 @@ static void show_eeprom(u8 *eeprom) return; } - printf("TLV: %u\n", current_dev); + printf("TLV: %u\n", devnum); printf("TlvInfo Header:\n"); printf(" Id String: %s\n", eeprom_hdr->signature); printf(" Version: %d\n", eeprom_hdr->version); @@ -389,7 +387,7 @@ static void update_crc(u8 *eeprom) * * Write the EEPROM data from CPU memory to the hardware. */ -static int prog_eeprom(u8 *eeprom) +static int prog_eeprom(int devnum, u8 *eeprom) { int ret = 0; struct tlvinfo_header *eeprom_hdr = to_header(eeprom); @@ -398,7 +396,7 @@ static int prog_eeprom(u8 *eeprom) update_crc(eeprom); eeprom_len = HDR_SIZE + be16_to_cpu(eeprom_hdr->totallen); - ret = write_tlv_eeprom(eeprom, eeprom_len); + ret = write_tlv_eeprom(eeprom, eeprom_len, devnum); if (ret) { printf("Programming failed.\n"); return -1; @@ -433,11 +431,12 @@ int do_tlv_eeprom(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) { char cmd; struct tlvinfo_header *eeprom_hdr = to_header(eeprom); + static unsigned int current_dev; // If no arguments, read the EERPOM and display its contents if (argc == 1) { - read_eeprom(eeprom); - show_eeprom(eeprom); + read_eeprom(current_dev, eeprom); + show_eeprom(current_dev, eeprom); return 0; } @@ -448,7 +447,7 @@ int do_tlv_eeprom(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) // Read the EEPROM contents if (cmd == 'r') { has_been_read = 0; - if (!read_eeprom(eeprom)) + if (!read_eeprom(current_dev, eeprom)) printf("EEPROM data loaded from device to memory.\n"); return 0; } @@ -463,7 +462,7 @@ int do_tlv_eeprom(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) if (argc == 2) { switch (cmd) { case 'w': /* write */ - prog_eeprom(eeprom); + prog_eeprom(current_dev, eeprom); break; case 'e': /* erase */ strcpy(eeprom_hdr->signature, TLV_INFO_ID_STRING); @@ -476,7 +475,7 @@ int do_tlv_eeprom(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) show_tlv_code_list(); break; case 'd': /* dev */ - show_tlv_devices(); + show_tlv_devices(current_dev); break; default: return CMD_RET_USAGE; @@ -883,7 +882,7 @@ static int set_bytes(char *buf, const char *string, int *converted_accum) return 0; } -static void show_tlv_devices(void) +static void show_tlv_devices(int current_dev) { unsigned int dev; @@ -953,14 +952,14 @@ int read_tlv_eeprom(void *eeprom, int offset, int len, int dev_num) /** * write_tlv_eeprom - write the hwinfo to i2c EEPROM */ -int write_tlv_eeprom(void *eeprom, int len) +int write_tlv_eeprom(void *eeprom, int len, int dev) { if (!(gd->flags & GD_FLG_RELOC)) return -ENODEV; - if (!tlv_devices[current_dev]) + if (!tlv_devices[dev]) return -ENODEV; - return i2c_eeprom_write(tlv_devices[current_dev], 0, eeprom, len); + return i2c_eeprom_write(tlv_devices[dev], 0, eeprom, len); } int read_tlvinfo_tlv_eeprom(void *eeprom, struct tlvinfo_header **hdr, @@ -1015,10 +1014,11 @@ int mac_read_from_eeprom(void) int maccount; u8 macbase[6]; struct tlvinfo_header *eeprom_hdr = to_header(eeprom); + int devnum = 0; // TODO: support multiple EEPROMs puts("EEPROM: "); - if (read_eeprom(eeprom)) { + if (read_eeprom(devnum, eeprom)) { printf("Read failed.\n"); return -1; } @@ -1083,7 +1083,7 @@ int mac_read_from_eeprom(void) * * This function must be called after relocation. */ -int populate_serial_number(void) +int populate_serial_number(int devnum) { char serialstr[257]; int eeprom_index; @@ -1092,7 +1092,7 @@ int populate_serial_number(void) if (env_get("serial#")) return 0; - if (read_eeprom(eeprom)) { + if (read_eeprom(devnum, eeprom)) { printf("Read failed.\n"); return -1; } diff --git a/include/tlv_eeprom.h b/include/tlv_eeprom.h index a2c333e7446..fd45e5f6ebb 100644 --- a/include/tlv_eeprom.h +++ b/include/tlv_eeprom.h @@ -84,11 +84,12 @@ int read_tlv_eeprom(void *eeprom, int offset, int len, int dev); * write_tlv_eeprom - Write the entire EEPROM binary data to the hardware * @eeprom: Pointer to buffer to hold the binary data * @len : Maximum size of buffer + * @dev : EEPROM device to write * * Note: this routine does not validate the EEPROM data. * */ -int write_tlv_eeprom(void *eeprom, int len); +int write_tlv_eeprom(void *eeprom, int len, int dev); /** * read_tlvinfo_tlv_eeprom - Read the TLV from EEPROM, and validate -- 2.35.3