All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Marek Behún" <kabel@kernel.org>
To: Stefan Roese <sr@denx.de>
Cc: u-boot@lists.denx.de, "Marek Behún" <kabel@kernel.org>
Subject: [PATCH u-boot-marvell 10/16] arm: mvebu: turris_omnia: Extend EEPROM info structure
Date: Tue, 18 Jun 2024 17:34:33 +0200	[thread overview]
Message-ID: <20240618153439.9518-11-kabel@kernel.org> (raw)
In-Reply-To: <20240618153439.9518-1-kabel@kernel.org>

Extend the Omnia EEPROM information structure in preparation for more
variables to be stored there.

Signed-off-by: Marek Behún <kabel@kernel.org>
---
 board/CZ.NIC/turris_omnia/eeprom.c       | 11 ++++++-
 board/CZ.NIC/turris_omnia/turris_omnia.c | 42 ++++++++++++++++++++----
 2 files changed, 46 insertions(+), 7 deletions(-)

diff --git a/board/CZ.NIC/turris_omnia/eeprom.c b/board/CZ.NIC/turris_omnia/eeprom.c
index a4f1dab469..ea13e95b37 100644
--- a/board/CZ.NIC/turris_omnia/eeprom.c
+++ b/board/CZ.NIC/turris_omnia/eeprom.c
@@ -60,9 +60,13 @@ static struct eeprom_field omnia_layout[] = {
 	_DEF_FIELD("RAM size in GB", 4, ramsz),
 	_DEF_FIELD("Wi-Fi Region", 4, region),
 	_DEF_FIELD("CRC32 checksum", 4, bin),
+	_DEF_FIELD("Extended reserved fields", 44, reserved),
+	_DEF_FIELD("Extended CRC32 checksum", 4, bin),
 };
 
 static struct eeprom_field *crc_field = &omnia_layout[3];
+static struct eeprom_field *ext_crc_field =
+	&omnia_layout[ARRAY_SIZE(omnia_layout) - 1];
 
 static int omnia_update_field(struct eeprom_layout *layout, char *field_name,
 			      char *new_data)
@@ -91,6 +95,11 @@ static int omnia_update_field(struct eeprom_layout *layout, char *field_name,
 		put_unaligned_le32(crc, crc_field->buf);
 	}
 
+	if (field < ext_crc_field) {
+		u32 crc = crc32(0, layout->data, 44);
+		put_unaligned_le32(crc, ext_crc_field->buf);
+	}
+
 	return 0;
 }
 
@@ -99,7 +108,7 @@ void eeprom_layout_assign(struct eeprom_layout *layout, int)
 	layout->fields = omnia_layout;
 	layout->num_of_fields = ARRAY_SIZE(omnia_layout);
 	layout->update = omnia_update_field;
-	layout->data_size = 16;
+	layout->data_size = 64;
 }
 
 int eeprom_layout_detect(unsigned char *)
diff --git a/board/CZ.NIC/turris_omnia/turris_omnia.c b/board/CZ.NIC/turris_omnia/turris_omnia.c
index 100a991406..c2f91b762f 100644
--- a/board/CZ.NIC/turris_omnia/turris_omnia.c
+++ b/board/CZ.NIC/turris_omnia/turris_omnia.c
@@ -429,12 +429,40 @@ struct omnia_eeprom {
 	u32 ramsize;
 	char region[4];
 	u32 crc;
+
+	/* second part (only considered if crc2 is not all-ones) */
+	u8 reserved[44];
+	u32 crc2;
 };
 
+static bool is_omnia_eeprom_second_part_valid(const struct omnia_eeprom *oep)
+{
+	return oep->crc2 != 0xffffffff;
+}
+
+static void make_omnia_eeprom_second_part_invalid(struct omnia_eeprom *oep)
+{
+	oep->crc2 = 0xffffffff;
+}
+
+static bool check_eeprom_crc(const void *buf, size_t size, u32 expected,
+			     const char *name)
+{
+	u32 crc;
+
+	crc = crc32(0, buf, size);
+	if (crc != expected) {
+		printf("bad %s EEPROM CRC (stored %08x, computed %08x)\n",
+		       name, expected, crc);
+		return false;
+	}
+
+	return true;
+}
+
 static bool omnia_read_eeprom(struct omnia_eeprom *oep)
 {
 	struct udevice *chip;
-	u32 crc;
 	int ret;
 
 	chip = omnia_get_i2c_chip("EEPROM", OMNIA_I2C_EEPROM_CHIP_ADDR,
@@ -455,12 +483,14 @@ static bool omnia_read_eeprom(struct omnia_eeprom *oep)
 		return false;
 	}
 
-	crc = crc32(0, (void *)oep, sizeof(*oep) - 4);
-	if (crc != oep->crc) {
-		printf("bad EEPROM CRC (stored %08x, computed %08x)\n",
-		       oep->crc, crc);
+	if (!check_eeprom_crc(oep, offsetof(struct omnia_eeprom, crc), oep->crc,
+			      "first"))
 		return false;
-	}
+
+	if (is_omnia_eeprom_second_part_valid(oep) &&
+	    !check_eeprom_crc(oep, offsetof(struct omnia_eeprom, crc2),
+			      oep->crc2, "second"))
+		make_omnia_eeprom_second_part_invalid(oep);
 
 	return true;
 }
-- 
2.44.2


  parent reply	other threads:[~2024-06-18 15:36 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-18 15:34 [PATCH u-boot-marvell 00/16] Turris Omnia DDR training changes Marek Behún
2024-06-18 15:34 ` [PATCH u-boot-marvell 01/16] arm: mvebu: turris_omnia: Disable ext4 write support in defconfig Marek Behún
2024-06-18 15:34 ` [PATCH u-boot-marvell 02/16] ddr: marvell: a38x: debug: return from ddr3_tip_print_log() early if we won't print anything Marek Behún
2024-06-18 15:34 ` [PATCH u-boot-marvell 03/16] ddr: marvell: a38x: debug: Remove unused variables Marek Behún
2024-06-18 15:34 ` [PATCH u-boot-marvell 04/16] ddr: marvell: a38x: debug: Define DDR_VIEWER_TOOL variables only if needed, and make them static Marek Behún
2024-06-18 15:34 ` [PATCH u-boot-marvell 05/16] ddr: marvell: a38x: debug: Allow compiling with immutable debug settings to reduce binary size Marek Behún
2024-06-18 15:34 ` [PATCH u-boot-marvell 06/16] arm: mvebu: turris_omnia: Enable immutable debug settings in DDR3 training by default Marek Behún
2024-06-18 15:34 ` [PATCH u-boot-marvell 07/16] arm: mvebu: turris_omnia: Fix ethernet PHY reset gpio FDT fixup Marek Behún
2024-06-18 15:34 ` [PATCH u-boot-marvell 08/16] arm: mvebu: turris_omnia: Implement EEPROM layout for the 'eeprom' command Marek Behún
2024-06-18 15:34 ` [PATCH u-boot-marvell 09/16] arm: mvebu: turris_omnia: Enable " Marek Behún
2024-06-18 15:34 ` Marek Behún [this message]
2024-06-18 15:34 ` [PATCH u-boot-marvell 11/16] arm: mvebu: turris_omnia: Read DDR speed from EEPROM Marek Behún
2024-06-18 15:34 ` [PATCH u-boot-marvell 12/16] ddr: marvell: a38x: Import old DDR training code from 2017 version of U-Boot Marek Behún
2024-06-18 15:34 ` [PATCH u-boot-marvell 13/16] ddr: marvell: a38x: old: Fix some compiler warning of the old code Marek Behún
2024-06-18 15:34 ` [PATCH u-boot-marvell 14/16] ddr: marvell: a38x: old: Backport immutable debug settings Marek Behún
2024-06-18 15:34 ` [PATCH u-boot-marvell 15/16] arm: mvebu: a38x: Add optional support for using old DDR3 training code Marek Behún
2024-06-18 15:34 ` [PATCH u-boot-marvell 16/16] arm: mvebu: turris_omnia: Support old DDR3 training Marek Behún
2024-07-08 14:16 ` [PATCH u-boot-marvell 00/16] Turris Omnia DDR training changes Stefan Roese

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240618153439.9518-11-kabel@kernel.org \
    --to=kabel@kernel.org \
    --cc=sr@denx.de \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.