Patch Detail
get:
Show a patch.
patch:
Update a patch.
put:
Update a patch.
GET /api/patches/1614913/?format=api
{ "id": 1614913, "url": "http://patchwork.ozlabs.org/api/patches/1614913/?format=api", "web_url": "http://patchwork.ozlabs.org/project/uboot/patch/20220408143015.23163-1-pali@kernel.org/", "project": { "id": 18, "url": "http://patchwork.ozlabs.org/api/projects/18/?format=api", "name": "U-Boot", "link_name": "uboot", "list_id": "u-boot.lists.denx.de", "list_email": "u-boot@lists.denx.de", "web_url": null, "scm_url": null, "webscm_url": null, "list_archive_url": "", "list_archive_url_format": "", "commit_url_format": "" }, "msgid": "<20220408143015.23163-1-pali@kernel.org>", "list_archive_url": null, "date": "2022-04-08T14:30:12", "name": "[1/4] board: turris: Move Turris Atsha OTP code to separate file", "commit_ref": "6ac08dc1a83d786d8749525df32c94b94bb36123", "pull_url": null, "state": "accepted", "archived": false, "hash": "9b1fb4a35dbe7e4bcabf1fc1ab2d792adf803993", "submitter": { "id": 78810, "url": "http://patchwork.ozlabs.org/api/people/78810/?format=api", "name": "Pali Rohár", "email": "pali@kernel.org" }, "delegate": { "id": 1696, "url": "http://patchwork.ozlabs.org/api/users/1696/?format=api", "username": "stroese", "first_name": "Stefan", "last_name": "Roese", "email": "sr@denx.de" }, "mbox": "http://patchwork.ozlabs.org/project/uboot/patch/20220408143015.23163-1-pali@kernel.org/mbox/", "series": [ { "id": 294208, "url": "http://patchwork.ozlabs.org/api/series/294208/?format=api", "web_url": "http://patchwork.ozlabs.org/project/uboot/list/?series=294208", "date": "2022-04-08T14:30:13", "name": "[1/4] board: turris: Move Turris Atsha OTP code to separate file", "version": 1, "mbox": "http://patchwork.ozlabs.org/series/294208/mbox/" } ], "comments": "http://patchwork.ozlabs.org/api/patches/1614913/comments/", "check": "pending", "checks": "http://patchwork.ozlabs.org/api/patches/1614913/checks/", "tags": {}, "related": [], "headers": { "Return-Path": "<u-boot-bounces@lists.denx.de>", "X-Original-To": "incoming@patchwork.ozlabs.org", "Delivered-To": "patchwork-incoming@bilbo.ozlabs.org", "Authentication-Results": [ "bilbo.ozlabs.org;\n\tdkim=pass (2048-bit key;\n unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256\n header.s=k20201202 header.b=NRerzZ98;\n\tdkim-atps=neutral", "ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de\n (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de;\n envelope-from=u-boot-bounces@lists.denx.de; receiver=<UNKNOWN>)", "phobos.denx.de;\n dmarc=pass (p=none dis=none) header.from=kernel.org", "phobos.denx.de;\n spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de", "phobos.denx.de;\n\tdkim=pass (2048-bit key;\n unprotected) header.d=kernel.org header.i=@kernel.org header.b=\"NRerzZ98\";\n\tdkim-atps=neutral", "phobos.denx.de;\n dmarc=pass (p=none dis=none) header.from=kernel.org", "phobos.denx.de; spf=pass smtp.mailfrom=pali@kernel.org" ], "Received": [ "from phobos.denx.de (phobos.denx.de\n [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange X25519 server-signature RSA-PSS (4096 bits))\n\t(No client certificate requested)\n\tby bilbo.ozlabs.org (Postfix) with ESMTPS id 4KZggP71fRz9sFy\n\tfor <incoming@patchwork.ozlabs.org>; Sat, 9 Apr 2022 00:32:01 +1000 (AEST)", "from h2850616.stratoserver.net (localhost [IPv6:::1])\n\tby phobos.denx.de (Postfix) with ESMTP id 5A18783DAC;\n\tFri, 8 Apr 2022 16:31:40 +0200 (CEST)", "by phobos.denx.de (Postfix, from userid 109)\n id E7BCD83A3A; Fri, 8 Apr 2022 16:31:31 +0200 (CEST)", "from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217])\n (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256\n bits)) (No client certificate requested)\n by phobos.denx.de (Postfix) with ESMTPS id C8E6183A3A\n for <u-boot@lists.denx.de>; Fri, 8 Apr 2022 16:31:26 +0200 (CEST)", "from smtp.kernel.org (relay.kernel.org [52.25.139.140])\n (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))\n (No client certificate requested)\n by dfw.source.kernel.org (Postfix) with ESMTPS id 25CB361DD4;\n Fri, 8 Apr 2022 14:31:25 +0000 (UTC)", "by smtp.kernel.org (Postfix) with ESMTPSA id 3FE15C385A1;\n Fri, 8 Apr 2022 14:31:24 +0000 (UTC)", "by pali.im (Postfix)\n id 41F826D7; Fri, 8 Apr 2022 16:31:21 +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.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,\n DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,\n SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no\n version=3.4.2", "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org;\n s=k20201202; t=1649428284;\n bh=qNVxdx4WRB+Ki4EvGgEI63gpSuYHF2lUSetzxUnhodM=;\n h=From:To:Cc:Subject:Date:From;\n b=NRerzZ98WnTx4Mnp6hUmt/U1XZzD7C2oVHOX4s3rXKEeKFHKpvU6m+Vi369AaR7Ef\n ZOva49NAwX9WZeHiVszRJ413sb6GOM7w6xe9vqNd8ixZRiid3cg3rxfU4da3I6tpWV\n DQi+rW0FlXO4yCATOJUrmCEl0HpsbfQiMdotvgbljAubyZU3CvEs05kEHibAMDKMy2\n 8SxFDGSXR0NTGiY9J+/VzXANHP8PrVo4/besEZhIRzVELm6R6AvFvMiZj5fJHuYOtU\n 3FFcZYt/iGtmeNHhS0Z6k6xVg8xaoewJpFHd5bQc9h7W0nOkZCaL6ssb75o0kvWUuD\n rND/8+nvlrp2A==", "From": "=?utf-8?q?Pali_Roh=C3=A1r?= <pali@kernel.org>", "To": "Stefan Roese <sr@denx.de>,\n\tMarek Behun <marek.behun@nic.cz>", "Cc": "u-boot@lists.denx.de", "Subject": "[PATCH 1/4] board: turris: Move Turris Atsha OTP code to separate\n file", "Date": "Fri, 8 Apr 2022 16:30:12 +0200", "Message-Id": "<20220408143015.23163-1-pali@kernel.org>", "X-Mailer": "git-send-email 2.20.1", "MIME-Version": "1.0", "Content-Type": "text/plain; charset=UTF-8", "Content-Transfer-Encoding": "8bit", "X-BeenThere": "u-boot@lists.denx.de", "X-Mailman-Version": "2.1.39", "Precedence": "list", "List-Id": "U-Boot discussion <u-boot.lists.denx.de>", "List-Unsubscribe": "<https://lists.denx.de/options/u-boot>,\n <mailto:u-boot-request@lists.denx.de?subject=unsubscribe>", "List-Archive": "<https://lists.denx.de/pipermail/u-boot/>", "List-Post": "<mailto:u-boot@lists.denx.de>", "List-Help": "<mailto:u-boot-request@lists.denx.de?subject=help>", "List-Subscribe": "<https://lists.denx.de/listinfo/u-boot>,\n <mailto:u-boot-request@lists.denx.de?subject=subscribe>", "Errors-To": "u-boot-bounces@lists.denx.de", "Sender": "\"U-Boot\" <u-boot-bounces@lists.denx.de>", "X-Virus-Scanned": "clamav-milter 0.103.5 at phobos.denx.de", "X-Virus-Status": "Clean" }, "content": "OTP code is not Atsha generic but also it is not Omnia specific. It is\ncommon for all Turris routers which use Atsha cryptochip for storing OTP.\nSo move this common Turris specific Atsha OTP code from Turris Omnia into\nseparate file. It will be used also by other Turris routers.\n\nSigned-off-by: Pali Rohár <pali@kernel.org>\n---\n board/CZ.NIC/turris_atsha_otp.c | 121 +++++++++++++++++++++++\n board/CZ.NIC/turris_atsha_otp.h | 9 ++\n board/CZ.NIC/turris_omnia/Makefile | 2 +-\n board/CZ.NIC/turris_omnia/turris_omnia.c | 108 +-------------------\n 4 files changed, 135 insertions(+), 105 deletions(-)\n create mode 100644 board/CZ.NIC/turris_atsha_otp.c\n create mode 100644 board/CZ.NIC/turris_atsha_otp.h", "diff": "diff --git a/board/CZ.NIC/turris_atsha_otp.c b/board/CZ.NIC/turris_atsha_otp.c\nnew file mode 100644\nindex 000000000000..a4a77c74fb19\n--- /dev/null\n+++ b/board/CZ.NIC/turris_atsha_otp.c\n@@ -0,0 +1,121 @@\n+// SPDX-License-Identifier: GPL-2.0+\n+/*\n+ * Copyright (C) 2017 Marek Behun <marek.behun@nic.cz>\n+ * Copyright (C) 2016 Tomas Hlavacek <tomas.hlavacek@nic.cz>\n+ */\n+\n+#include <env.h>\n+#include <net.h>\n+#include <dm/uclass.h>\n+#include <atsha204a-i2c.h>\n+\n+#include \"turris_atsha_otp.h\"\n+\n+#define TURRIS_ATSHA_OTP_VERSION\t0\n+#define TURRIS_ATSHA_OTP_SERIAL\t\t1\n+#define TURRIS_ATSHA_OTP_MAC0\t\t3\n+#define TURRIS_ATSHA_OTP_MAC1\t\t4\n+\n+static struct udevice *get_atsha204a_dev(void)\n+{\n+\tstatic struct udevice *dev;\n+\n+\tif (dev)\n+\t\treturn dev;\n+\n+\tif (uclass_get_device_by_name(UCLASS_MISC, \"atsha204a@64\", &dev)) {\n+\t\tputs(\"Cannot find ATSHA204A on I2C bus!\\n\");\n+\t\tdev = NULL;\n+\t}\n+\n+\treturn dev;\n+}\n+\n+static void increment_mac(u8 *mac)\n+{\n+\tint i;\n+\n+\tfor (i = 5; i >= 3; i--) {\n+\t\tmac[i] += 1;\n+\t\tif (mac[i])\n+\t\t\tbreak;\n+\t}\n+}\n+\n+static void set_mac_if_invalid(int i, u8 *mac)\n+{\n+\tu8 oldmac[6];\n+\n+\tif (is_valid_ethaddr(mac) &&\n+\t !eth_env_get_enetaddr_by_index(\"eth\", i, oldmac))\n+\t\teth_env_set_enetaddr_by_index(\"eth\", i, mac);\n+}\n+\n+int turris_atsha_otp_init_mac_addresses(void)\n+{\n+\tstruct udevice *dev = get_atsha204a_dev();\n+\tu8 mac0[4], mac1[4], mac[6];\n+\tint ret;\n+\n+\tif (!dev)\n+\t\treturn -1;\n+\n+\tret = atsha204a_wakeup(dev);\n+\tif (ret)\n+\t\treturn ret;\n+\n+\tret = atsha204a_read(dev, ATSHA204A_ZONE_OTP, false,\n+\t\t\t TURRIS_ATSHA_OTP_MAC0, mac0);\n+\tif (ret)\n+\t\treturn ret;\n+\n+\tret = atsha204a_read(dev, ATSHA204A_ZONE_OTP, false,\n+\t\t\t TURRIS_ATSHA_OTP_MAC1, mac1);\n+\tif (ret)\n+\t\treturn ret;\n+\n+\tatsha204a_sleep(dev);\n+\n+\tmac[0] = mac0[1];\n+\tmac[1] = mac0[2];\n+\tmac[2] = mac0[3];\n+\tmac[3] = mac1[1];\n+\tmac[4] = mac1[2];\n+\tmac[5] = mac1[3];\n+\n+\tset_mac_if_invalid(1, mac);\n+\tincrement_mac(mac);\n+\tset_mac_if_invalid(2, mac);\n+\tincrement_mac(mac);\n+\tset_mac_if_invalid(0, mac);\n+\n+\treturn 0;\n+}\n+\n+int turris_atsha_otp_get_serial_number(u32 *version_num, u32 *serial_num)\n+{\n+\tstruct udevice *dev = get_atsha204a_dev();\n+\tint ret;\n+\n+\tif (!dev)\n+\t\treturn -1;\n+\n+\tret = atsha204a_wakeup(dev);\n+\tif (ret)\n+\t\treturn ret;\n+\n+\tret = atsha204a_read(dev, ATSHA204A_ZONE_OTP, false,\n+\t\t\t TURRIS_ATSHA_OTP_VERSION,\n+\t\t\t (u8 *)version_num);\n+\tif (ret)\n+\t\treturn ret;\n+\n+\tret = atsha204a_read(dev, ATSHA204A_ZONE_OTP, false,\n+\t\t\t TURRIS_ATSHA_OTP_SERIAL,\n+\t\t\t (u8 *)serial_num);\n+\tif (ret)\n+\t\treturn ret;\n+\n+\tatsha204a_sleep(dev);\n+\treturn 0;\n+}\ndiff --git a/board/CZ.NIC/turris_atsha_otp.h b/board/CZ.NIC/turris_atsha_otp.h\nnew file mode 100644\nindex 000000000000..667d01af7310\n--- /dev/null\n+++ b/board/CZ.NIC/turris_atsha_otp.h\n@@ -0,0 +1,9 @@\n+// SPDX-License-Identifier: GPL-2.0+\n+\n+#ifndef TURRIS_ATSHA_OTP_H\n+#define TURRIS_ATSHA_OTP_H\n+\n+int turris_atsha_otp_init_mac_addresses(void);\n+int turris_atsha_otp_get_serial_number(u32 *version_num, u32 *serial_num);\n+\n+#endif\ndiff --git a/board/CZ.NIC/turris_omnia/Makefile b/board/CZ.NIC/turris_omnia/Makefile\nindex ccdf6c352cad..b79555ab4673 100644\n--- a/board/CZ.NIC/turris_omnia/Makefile\n+++ b/board/CZ.NIC/turris_omnia/Makefile\n@@ -2,4 +2,4 @@\n #\n # Copyright (C) 2017 Marek Behun <marek.behun@nic.cz>\n \n-obj-y\t:= turris_omnia.o\n+obj-y\t:= turris_omnia.o ../turris_atsha_otp.o\ndiff --git a/board/CZ.NIC/turris_omnia/turris_omnia.c b/board/CZ.NIC/turris_omnia/turris_omnia.c\nindex 33cec6587e19..719e8750e60a 100644\n--- a/board/CZ.NIC/turris_omnia/turris_omnia.c\n+++ b/board/CZ.NIC/turris_omnia/turris_omnia.c\n@@ -14,8 +14,6 @@\n #include <log.h>\n #include <miiphy.h>\n #include <mtd.h>\n-#include <net.h>\n-#include <netdev.h>\n #include <asm/global_data.h>\n #include <asm/io.h>\n #include <asm/arch/cpu.h>\n@@ -25,10 +23,10 @@\n #include <time.h>\n #include <linux/bitops.h>\n #include <u-boot/crc.h>\n-# include <atsha204a-i2c.h>\n \n #include \"../drivers/ddr/marvell/a38x/ddr3_init.h\"\n #include <../serdes/a38x/high_speed_env_spec.h>\n+#include \"../turris_atsha_otp.h\"\n \n DECLARE_GLOBAL_DATA_PTR;\n \n@@ -71,11 +69,6 @@ enum status_word_bits {\n \tMSATA_IND_STSBIT\t= 0x0020,\n };\n \n-#define OMNIA_ATSHA204_OTP_VERSION\t0\n-#define OMNIA_ATSHA204_OTP_SERIAL\t1\n-#define OMNIA_ATSHA204_OTP_MAC0\t\t3\n-#define OMNIA_ATSHA204_OTP_MAC1\t\t4\n-\n /*\n * Those values and defines are taken from the Marvell U-Boot version\n * \"u-boot-2013.01-2014_T3.0\"\n@@ -594,49 +587,12 @@ int board_late_init(void)\n \treturn 0;\n }\n \n-static struct udevice *get_atsha204a_dev(void)\n-{\n-\tstatic struct udevice *dev;\n-\n-\tif (dev)\n-\t\treturn dev;\n-\n-\tif (uclass_get_device_by_name(UCLASS_MISC, \"atsha204a@64\", &dev)) {\n-\t\tputs(\"Cannot find ATSHA204A on I2C bus!\\n\");\n-\t\tdev = NULL;\n-\t}\n-\n-\treturn dev;\n-}\n-\n int show_board_info(void)\n {\n \tu32 version_num, serial_num;\n-\tint err = 1;\n-\n-\tstruct udevice *dev = get_atsha204a_dev();\n-\n-\tif (dev) {\n-\t\terr = atsha204a_wakeup(dev);\n-\t\tif (err)\n-\t\t\tgoto out;\n-\n-\t\terr = atsha204a_read(dev, ATSHA204A_ZONE_OTP, false,\n-\t\t\t\t OMNIA_ATSHA204_OTP_VERSION,\n-\t\t\t\t (u8 *)&version_num);\n-\t\tif (err)\n-\t\t\tgoto out;\n-\n-\t\terr = atsha204a_read(dev, ATSHA204A_ZONE_OTP, false,\n-\t\t\t\t OMNIA_ATSHA204_OTP_SERIAL,\n-\t\t\t\t (u8 *)&serial_num);\n-\t\tif (err)\n-\t\t\tgoto out;\n-\n-\t\tatsha204a_sleep(dev);\n-\t}\n+\tint err;\n \n-out:\n+\terr = turris_atsha_otp_get_serial_number(&version_num, &serial_num);\n \tprintf(\"Model: Turris Omnia\\n\");\n \tprintf(\" RAM size: %i MiB\\n\", omnia_get_ram_size_gb() * 1024);\n \tif (err)\n@@ -648,65 +604,9 @@ out:\n \treturn 0;\n }\n \n-static void increment_mac(u8 *mac)\n-{\n-\tint i;\n-\n-\tfor (i = 5; i >= 3; i--) {\n-\t\tmac[i] += 1;\n-\t\tif (mac[i])\n-\t\t\tbreak;\n-\t}\n-}\n-\n-static void set_mac_if_invalid(int i, u8 *mac)\n-{\n-\tu8 oldmac[6];\n-\n-\tif (is_valid_ethaddr(mac) &&\n-\t !eth_env_get_enetaddr_by_index(\"eth\", i, oldmac))\n-\t\teth_env_set_enetaddr_by_index(\"eth\", i, mac);\n-}\n-\n int misc_init_r(void)\n {\n-\tint err;\n-\tstruct udevice *dev = get_atsha204a_dev();\n-\tu8 mac0[4], mac1[4], mac[6];\n-\n-\tif (!dev)\n-\t\tgoto out;\n-\n-\terr = atsha204a_wakeup(dev);\n-\tif (err)\n-\t\tgoto out;\n-\n-\terr = atsha204a_read(dev, ATSHA204A_ZONE_OTP, false,\n-\t\t\t OMNIA_ATSHA204_OTP_MAC0, mac0);\n-\tif (err)\n-\t\tgoto out;\n-\n-\terr = atsha204a_read(dev, ATSHA204A_ZONE_OTP, false,\n-\t\t\t OMNIA_ATSHA204_OTP_MAC1, mac1);\n-\tif (err)\n-\t\tgoto out;\n-\n-\tatsha204a_sleep(dev);\n-\n-\tmac[0] = mac0[1];\n-\tmac[1] = mac0[2];\n-\tmac[2] = mac0[3];\n-\tmac[3] = mac1[1];\n-\tmac[4] = mac1[2];\n-\tmac[5] = mac1[3];\n-\n-\tset_mac_if_invalid(1, mac);\n-\tincrement_mac(mac);\n-\tset_mac_if_invalid(2, mac);\n-\tincrement_mac(mac);\n-\tset_mac_if_invalid(0, mac);\n-\n-out:\n+\tturris_atsha_otp_init_mac_addresses();\n \treturn 0;\n }\n \n", "prefixes": [ "1/4" ] }