* [U-Boot] [PATCH v3] sunxi: On newer SoCs use words 1-3 instead of just word 3 from the SID
@ 2016-07-30 12:43 Hans de Goede
2016-07-31 11:47 ` Ian Campbell
0 siblings, 1 reply; 2+ messages in thread
From: Hans de Goede @ 2016-07-30 12:43 UTC (permalink / raw)
To: u-boot
It seems that bytes 13-14 of the SID / bytes 1-2 from word 3 of the SID
are always 0 on H3 making it a poor candidate to use as source for the
serialnr / mac-address, and the other non constant words (1 and 2) also
have quite a few bits which are the same for some boards,
This commits switches to using the crc32 of words 1 - 3 to get a
more unique value for the mac-address / serialnr.
Cc: Chen-Yu Tsai <wens@csie.org>
Cc: Corentin LABBE <clabbe.montjoie@gmail.com>
Cc: Amit Singh Tomar <amittomer25@gmail.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
Changes in v3:
-Use crc32 instead of ex-or-ing the bytes together
-Use new algorithm on all newer SoCs
-Only check for sid[0] != 0 to capture non initialized sid-s.
Changes in v2:
-ex-or all 3 words together instead of picking a different word
---
board/sunxi/board.c | 20 +++++++++++++++++++-
1 file changed, 19 insertions(+), 1 deletion(-)
diff --git a/board/sunxi/board.c b/board/sunxi/board.c
index ef3fe26..209fb1c 100644
--- a/board/sunxi/board.c
+++ b/board/sunxi/board.c
@@ -27,6 +27,7 @@
#endif
#include <asm/gpio.h>
#include <asm/io.h>
+#include <crc.h>
#include <environment.h>
#include <libfdt.h>
#include <nand.h>
@@ -622,7 +623,24 @@ static void setup_environment(const void *fdt)
int i, ret;
ret = sunxi_get_sid(sid);
- if (ret == 0 && sid[0] != 0 && sid[3] != 0) {
+ 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;
--
2.7.4
^ permalink raw reply related [flat|nested] 2+ messages in thread* [U-Boot] [PATCH v3] sunxi: On newer SoCs use words 1-3 instead of just word 3 from the SID
2016-07-30 12:43 [U-Boot] [PATCH v3] sunxi: On newer SoCs use words 1-3 instead of just word 3 from the SID Hans de Goede
@ 2016-07-31 11:47 ` Ian Campbell
0 siblings, 0 replies; 2+ messages in thread
From: Ian Campbell @ 2016-07-31 11:47 UTC (permalink / raw)
To: u-boot
On Sat, 2016-07-30 at 14:43 +0200, Hans de Goede wrote:
> It seems that bytes 13-14 of the SID / bytes 1-2 from word 3 of the
> SID
> are always 0 on H3 making it a poor candidate to use as source for
> the
> serialnr / mac-address, and the other non constant words (1 and 2)
> also
> have quite a few bits which are the same for some boards,
>
> This commits switches to using the crc32 of words 1 - 3 to get a
> more unique value for the mac-address / serialnr.
>
> Cc: Chen-Yu Tsai <wens@csie.org>
> Cc: Corentin LABBE <clabbe.montjoie@gmail.com>
> Cc: Amit Singh Tomar <amittomer25@gmail.com>
> Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Acked-by: Ian Campbell <ijc@hellion.org.uk>
Two minor thoughts:
At some point it might be nice to switch from using sid[3] as the
temporary variable to contain the csum since it is no longer the 3rd
element of the sid in any meaningful way. If you decide to do so for a
v4, then please do keep my ack from above.
Likewise if you decide to express the big chain of ifndef's via Kconfig
instead, you can keep the ack.
Ian.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2016-07-31 11:47 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-07-30 12:43 [U-Boot] [PATCH v3] sunxi: On newer SoCs use words 1-3 instead of just word 3 from the SID Hans de Goede
2016-07-31 11:47 ` Ian Campbell
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox