Modify read sys eeprom from byte mode

This commit is contained in:
Jostar Yang
2019-07-29 18:12:26 +08:00
parent 762b9f226d
commit 2493d3c079
2 changed files with 23 additions and 10 deletions

View File

@@ -26,6 +26,7 @@
#include <unistd.h> #include <unistd.h>
#include <fcntl.h> #include <fcntl.h>
#include <onlplib/i2c.h>
#include <onlplib/file.h> #include <onlplib/file.h>
#include <onlp/platformi/sysi.h> #include <onlp/platformi/sysi.h>
#include <onlp/platformi/ledi.h> #include <onlp/platformi/ledi.h>
@@ -56,7 +57,7 @@ onlp_sysi_init(void)
} }
memset(interface, 0x0, 64); memset(interface, 0x0, 64);
strncpy(interface, "eth0", strlen("eth0")); strncpy(interface, "eth0", strlen("eth0"));
strncpy(ifr.ifr_name, interface, IFNAMSIZ); strncpy(ifr.ifr_name, interface, IFNAMSIZ);
if (ioctl(skfd, SIOCGMIIPHY, &ifr) < 0) { if (ioctl(skfd, SIOCGMIIPHY, &ifr) < 0) {
if (errno != ENODEV) if (errno != ENODEV)
fprintf(stderr, "SIOCGMIIPHY on '%s' failed: %s\n", fprintf(stderr, "SIOCGMIIPHY on '%s' failed: %s\n",
@@ -78,17 +79,29 @@ onlp_sysi_init(void)
int int
onlp_sysi_onie_data_get(uint8_t** data, int* size) onlp_sysi_onie_data_get(uint8_t** data, int* size)
{ {
uint8_t* rdata = aim_zmalloc(512); int ret = ONLP_STATUS_OK;
if(onlp_file_read(rdata, 512, size, IDPROM_PATH) == ONLP_STATUS_OK) { int i = 0;
if(*size == 512) { uint8_t* rdata = aim_zmalloc(256);
*data = rdata;
return ONLP_STATUS_OK; for (i = 0; i < 128; i++) {
ret = onlp_i2c_readw(0, 0x57, i*2, ONLP_I2C_F_FORCE);
if (ret < 0) {
printf ("i=%d, ret<0\n",i);
perror("perror:");
printf("strerror:%s\n", strerror(errno));
aim_free(rdata);
*size = 0;
return ret;
} }
rdata[i*2] = ret & 0xff;
rdata[i*2+1] = (ret >> 8) & 0xff;
} }
aim_free(rdata); *size = 256;
*size = 0; *data = rdata;
return ONLP_STATUS_E_INTERNAL;
return ONLP_STATUS_OK;
} }
int int

View File

@@ -113,7 +113,7 @@ class OnlPlatform_x86_64_accton_asgvolt64_r0(OnlPlatformAccton,
self.new_i2c_device('optoe2', 0x50, port) self.new_i2c_device('optoe2', 0x50, port)
subprocess.call('echo port%d > /sys/bus/i2c/devices/%d-0050/port_name' % (port+41, port), shell=True) subprocess.call('echo port%d > /sys/bus/i2c/devices/%d-0050/port_name' % (port+41, port), shell=True)
# initiate IDPROM # initiate IDPROM
self.new_i2c_device('24c02', 0x57, 0) #self.new_i2c_device('24c02', 0x57, 0)
ir3570_check() ir3570_check()