
-----Original Message----- From: Nico Becker n.becker@ic-automation.de Sent: Friday, July 17, 2020 6:23 PM To: u-boot@lists.denx.de; marex@denx.de; simon.k.r.goldschmidt@gmail.com; Tan, Ley Foon ley.foon.tan@intel.com Cc: Nico Becker n.becker@ic-automation.de Subject: [PATCH v4] arm: socfpga: add board support for ic-automation Moritz III
add board support for the moritz III from ic-automation
Changes for v4:
- re-sort list alphabetically
- c style comments
Changes for v3: - Resend via git send-email
Changes for v2:
- Coding Style cleanup
Signed-off-by: Nico Becker n.becker@ic-automation.de
+#include <common.h> +#include <net.h> +#include <dm/uclass.h> +#include <i2c.h> +#include <env_flags.h> +#include <u-boot/crc.h>
+#define I2C_BUS_NUM 1 +#define EEPROM_ADDR 0x50 +#define GPIO_ADDR 0x20
+#define SERIALNUMBER_LENGTH 8 +#define MAC_LENGTH 6 +#define CRC32_LENGTH 4 +#define OVERALL_LENGTH (SERIALNUMBER_LENGTH + MAC_LENGTH + CRC32_LENGTH)
+int board_late_init(void) +{
- u8 mac[MAC_LENGTH];
- char serial[SERIALNUMBER_LENGTH + 1];
- u8 eeprom_data[OVERALL_LENGTH];
- u32 calc_crc32;
- u32 *read_crc32;
- u8 w_data;
- int error;
- u8 registers[] = {0x02, 0x03, 0x06, 0x07};
- for (int i = 0; i < OVERALL_LENGTH; i++)
eeprom_data[i] = 0x00;
- printf(" _ _ _ _\n");
- printf("(_) ___ __ _ _ _| |_ ___ _ __ ___ __ _| |_(_) ___ _
__\n");
- printf("| |/ __|____ / _` | | | | __/ _ \| '_ ` _ \ / _` | __| |/ _ \| '_
\\n");
- printf("| | (_|_____| (_| | |_| | || (_) | | | | | | (_| | |_| | (_) | | |
|\n");
- printf("|_|\___| \__,_|\__,_|\__\___/|_| |_|
|_|\__,_|\__|_|\___/|_| |_|\n");
- printf("\n");
- /* delete environment var first. Otherwise we are unable to set it's
value... */
- env_set("ethaddr", "");
- struct udevice *bus;
- struct udevice *dev;
- error = uclass_get_device_by_seq(UCLASS_I2C, I2C_BUS_NUM,
&bus);
- if (error) {
printf("cannot get I2C bus 1: uclass_get_device_by_seq
failed: %i\n", error);
return 0;
- }
- error = i2c_get_chip(bus, EEPROM_ADDR, 1, &dev);
- if (error) {
printf("Cannot get I2C chip: i2c_get_chip failed: %i\n", error);
return 0;
- }
- /* i2c EEPROM available? */
- error = dm_i2c_probe(bus, EEPROM_ADDR, 0, &dev);
- if (error) {
printf("Couldn't find i2c eeprom\n");
return 0;
- }
- error = dm_i2c_read(dev, 0, eeprom_data, OVERALL_LENGTH);
- if (error) {
printf("i2c_read failed %d\n", error);
return 0;
- }
- /* check crc32 */
- calc_crc32 = crc32(0, eeprom_data, OVERALL_LENGTH -
CRC32_LENGTH);
- read_crc32 = (u32 *)&eeprom_data[SERIALNUMBER_LENGTH +
MAC_LENGTH];
- if (*read_crc32 != calc_crc32) {
/* print read data is crc32 not valid */
printf("read data:");
for (int i = 0; i < OVERALL_LENGTH; i++)
printf("%02X", eeprom_data[i]);
printf("\n");
/* print crc32 */
printf("read crc32 %08X calc crc32 %08X\n", *read_crc32,
calc_crc32);
strncpy(serial, "00000000", 8);
memset((void *)mac, 0x00, 8);
- } else {
/* copy and print serial */
Comment should be "copy".
memcpy((void *)serial, (void *)eeprom_data,
SERIALNUMBER_LENGTH);
/* print MAC address */
Comment should be "copy".
memcpy((void *)mac, (void
*)&eeprom_data[SERIALNUMBER_LENGTH], MAC_LENGTH);
- }
- serial[SERIALNUMBER_LENGTH] = 0x00;
- printf("Serialnumber = %s\n", serial);
- if (!is_valid_ethaddr(mac)) {
printf("MAC address is invalid, set random MAC\n");
How it set random MAC address here? Need call to net_random_ethaddr() here?
- } else {
printf("MAC = %02X:%02X:%02X:%02X:%02X:%02X\n",
mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
error = eth_env_set_enetaddr("ethaddr", mac);
if (error)
printf("MAC address NOT set. Error: %d\n", error);
else
printf("MAC address successfully set\n");
- }
- /* set GPIOs */
- error = i2c_get_chip(bus, GPIO_ADDR, 1, &dev);
- w_data = 0x00;
- for (int i = 0 ; i < sizeof(registers) / sizeof(u8); i++) {
/* set all values 0 at GPIO-Bank 0 */
error = dm_i2c_write(dev, registers[i], &w_data, 1);
if (error) {
printf("i2c_write GPIO register %X failed.
Error: %d\n",
registers[i], error);
return 0;
}
- }
- return 0;
+}
Thanks.
Regards Ley Foon