From patchwork Tue Feb 4 09:37:55 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andre Heider X-Patchwork-Id: 1233196 X-Patchwork-Delegate: jagannadh.teki@gmail.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=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=UCwcfWb2; 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 48BflC49ywzB3wK for ; Tue, 4 Feb 2020 20:38:31 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id A31CB81AAB; Tue, 4 Feb 2020 10:38:16 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="UCwcfWb2"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id D5F5481AA8; Tue, 4 Feb 2020 10:38:12 +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.1 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FROM,SPF_HELO_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-wm1-x341.google.com (mail-wm1-x341.google.com [IPv6:2a00:1450:4864:20::341]) (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 3E37D81A8F for ; Tue, 4 Feb 2020 10:38:09 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=a.heider@gmail.com Received: by mail-wm1-x341.google.com with SMTP id p17so2677430wma.1 for ; Tue, 04 Feb 2020 01:38:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=+PDzt8+HfwsYp0m0sTe3XqyaiSdQF/4k5ctSMtXocbU=; b=UCwcfWb2MiAHE4Ngcgjek2bbMNhT+LMcyFGfkEo0YL2cMWQJKrj5Fm+n4m4TSXonbt MeFRtZ73KuuudMJE/ESHViy4e4j7a8TPF96O32e+482XjDH2c0wocxFVfJ8SQNlle5uO H9+KruIYOhyRhKK8A8XIxLE+nlV3UoocNBg+fdThjFTUDV1p111fyrrw0fyppU+v5UqO nazeOKFVJWtNoQchjCYUrDPuqfkCwanthb1U+syHnFUzZxOAh22LcGeHmIstOgRx4gnP FzCrZIFgcCvdtMk1sEvDWGbSmXYriCsu8YhaL9aKwgzaom2J8YbxoHI8/kgnQd83GSh7 nqMw== 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:mime-version:content-transfer-encoding; bh=+PDzt8+HfwsYp0m0sTe3XqyaiSdQF/4k5ctSMtXocbU=; b=b60nhihCGk7yR4LlzEiG4KgTFzBNfu2yt072KvYSulhnvmklU86yqhCqmda31IRUQ6 GGTmsY33kkn/X9Dl6sOezrd81rD4l80jQV70Hwa3MHQbe+rzSZ+fRrJ7/LTw3MWhkERH tjGHYunEkUNBS2A6d1i41loOw+t/yxjSZie72YVnMVJyflcmRZe7FgnSTEDez8Ol4TSs 51FHWA/FOVI6zluTvgN45E0YAx4//sLXHDJ/Mq7rmTA4J6oK3Yt1qU/1sKPY1ZxnhJeZ X2rxx8DCMcEHTKngkR3LFnFSotDf9Oh/cjNCFQy41U8El/yuF+EqS7n+ohDzzpdbicnt rL/w== X-Gm-Message-State: APjAAAWBtD8lGZEnmV9K/x8kSKEqB1TfdM2e34L9xMOBac+xmf5kXfPc mR0JVPSD4iHUVeTfoI2VfvY= X-Google-Smtp-Source: APXvYqzP7c4C66c1JJFmQDliwX2CIPJeY1H1W0yUF9e+oLJgz8ESrdJyrdbwPBSgnpRe+9ZvFuKa3w== X-Received: by 2002:a1c:de55:: with SMTP id v82mr4730414wmg.48.1580809088425; Tue, 04 Feb 2020 01:38:08 -0800 (PST) Received: from mamamia.internal (a89-183-45-130.net-htp.de. [89.183.45.130]) by smtp.gmail.com with ESMTPSA id q130sm3345425wme.19.2020.02.04.01.38.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Feb 2020 01:38:08 -0800 (PST) From: Andre Heider To: Jagan Teki , Maxime Ripard Subject: [PATCH v4 1/4] sunxi: board: extract creating a unique sid into a helper function Date: Tue, 4 Feb 2020 10:37:55 +0100 Message-Id: <20200204093758.584725-2-a.heider@gmail.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200204093758.584725-1-a.heider@gmail.com> References: <20200204093758.584725-1-a.heider@gmail.com> 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: Ondrej Jirman , u-boot@lists.denx.de, Jernej Skrabec 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 Refactor setup_environment() so we can use the created sid for a Bluetooth address too. Signed-off-by: Andre Heider Acked-by: Maxime Ripard --- board/sunxi/board.c | 105 ++++++++++++++++++++++++-------------------- 1 file changed, 58 insertions(+), 47 deletions(-) diff --git a/board/sunxi/board.c b/board/sunxi/board.c index 6afea6ef42..e670793479 100644 --- a/board/sunxi/board.c +++ b/board/sunxi/board.c @@ -770,6 +770,38 @@ static void parse_spl_header(const uint32_t spl_addr) env_set_hex("fel_scriptaddr", spl->fel_script_address); } +static bool get_unique_sid(unsigned int *sid) +{ + if (sunxi_get_sid(sid) != 0) + return false; + + if (!sid[0]) + return false; + + /* + * The single words 1 - 3 of the SID have quite a few bits + * which are the same on many models, so we take a crc32 + * of all 3 words, to get a more unique value. + * + * Note we only do this on newer SoCs as we cannot change + * the algorithm on older SoCs since those have been using + * fixed mac-addresses based on only using word 3 for a + * long time and changing a fixed mac-address with an + * u-boot update is not good. + */ +#if !defined(CONFIG_MACH_SUN4I) && !defined(CONFIG_MACH_SUN5I) && \ + !defined(CONFIG_MACH_SUN6I) && !defined(CONFIG_MACH_SUN7I) && \ + !defined(CONFIG_MACH_SUN8I_A23) && !defined(CONFIG_MACH_SUN8I_A33) + sid[3] = crc32(0, (unsigned char *)&sid[1], 12); +#endif + + /* Ensure the NIC specific bytes of the mac are not all 0 */ + if ((sid[3] & 0xffffff) == 0) + sid[3] |= 0x800000; + + return true; +} + /* * Note this function gets called multiple times. * It must not make any changes to env variables which already exist. @@ -780,61 +812,40 @@ static void setup_environment(const void *fdt) unsigned int sid[4]; uint8_t mac_addr[6]; char ethaddr[16]; - int i, ret; + int i; - ret = sunxi_get_sid(sid); - if (ret == 0 && sid[0] != 0) { - /* - * The single words 1 - 3 of the SID have quite a few bits - * which are the same on many models, so we take a crc32 - * of all 3 words, to get a more unique value. - * - * Note we only do this on newer SoCs as we cannot change - * the algorithm on older SoCs since those have been using - * fixed mac-addresses based on only using word 3 for a - * long time and changing a fixed mac-address with an - * u-boot update is not good. - */ -#if !defined(CONFIG_MACH_SUN4I) && !defined(CONFIG_MACH_SUN5I) && \ - !defined(CONFIG_MACH_SUN6I) && !defined(CONFIG_MACH_SUN7I) && \ - !defined(CONFIG_MACH_SUN8I_A23) && !defined(CONFIG_MACH_SUN8I_A33) - sid[3] = crc32(0, (unsigned char *)&sid[1], 12); -#endif - - /* Ensure the NIC specific bytes of the mac are not all 0 */ - if ((sid[3] & 0xffffff) == 0) - sid[3] |= 0x800000; + if (!get_unique_sid(sid)) + return; - for (i = 0; i < 4; i++) { - sprintf(ethaddr, "ethernet%d", i); - if (!fdt_get_alias(fdt, ethaddr)) - continue; + for (i = 0; i < 4; i++) { + sprintf(ethaddr, "ethernet%d", i); + if (!fdt_get_alias(fdt, ethaddr)) + continue; - if (i == 0) - strcpy(ethaddr, "ethaddr"); - else - sprintf(ethaddr, "eth%daddr", i); + if (i == 0) + strcpy(ethaddr, "ethaddr"); + else + sprintf(ethaddr, "eth%daddr", i); - if (env_get(ethaddr)) - continue; + if (env_get(ethaddr)) + continue; - /* Non OUI / registered MAC address */ - mac_addr[0] = (i << 4) | 0x02; - mac_addr[1] = (sid[0] >> 0) & 0xff; - mac_addr[2] = (sid[3] >> 24) & 0xff; - mac_addr[3] = (sid[3] >> 16) & 0xff; - mac_addr[4] = (sid[3] >> 8) & 0xff; - mac_addr[5] = (sid[3] >> 0) & 0xff; + /* Non OUI / registered MAC address */ + mac_addr[0] = (i << 4) | 0x02; + mac_addr[1] = (sid[0] >> 0) & 0xff; + mac_addr[2] = (sid[3] >> 24) & 0xff; + mac_addr[3] = (sid[3] >> 16) & 0xff; + mac_addr[4] = (sid[3] >> 8) & 0xff; + mac_addr[5] = (sid[3] >> 0) & 0xff; - eth_env_set_enetaddr(ethaddr, mac_addr); - } + eth_env_set_enetaddr(ethaddr, mac_addr); + } - if (!env_get("serial#")) { - snprintf(serial_string, sizeof(serial_string), - "%08x%08x", sid[0], sid[3]); + if (!env_get("serial#")) { + snprintf(serial_string, sizeof(serial_string), + "%08x%08x", sid[0], sid[3]); - env_set("serial#", serial_string); - } + env_set("serial#", serial_string); } }