mirror of
https://github.com/lm-sensors/lm-sensors
synced 2025-09-02 15:25:38 +00:00
update to version 0.7.5, which makes -8 mode the default.
This should be safer. Contribution from Stefano Barbato <stefano@codesink.org> git-svn-id: http://lm-sensors.org/svn/lm-sensors/trunk@2167 7894878c-1315-0410-8ee3-d5d059ff63e0
This commit is contained in:
@@ -11,7 +11,7 @@ Use eepromer for large eeproms with two-byte addresses:
|
|||||||
See README.eepromer for details.
|
See README.eepromer for details.
|
||||||
|
|
||||||
Use eeprog for either small or large eeproms.
|
Use eeprog for either small or large eeproms.
|
||||||
Use the -8 switch for small eeproms.
|
Use the -16 switch for large eeproms.
|
||||||
It works on both i2c and smbus bus adapters.
|
It works on both i2c and smbus bus adapters.
|
||||||
See README.eeprog for details.
|
See README.eeprog for details.
|
||||||
|
|
||||||
|
@@ -5,7 +5,7 @@ eeprog reads and writes 24Cxx EEPROMs connected to I2C serial bus.
|
|||||||
It uses the SMBus protocol used by most of the recent chipsets. Don't forget to load
|
It uses the SMBus protocol used by most of the recent chipsets. Don't forget to load
|
||||||
your i2c chipset and the i2c-dev drivers.
|
your i2c chipset and the i2c-dev drivers.
|
||||||
|
|
||||||
Use -8 switch for EEPROM smaller then 24C16 (8bit addressing mode).
|
Use -16 switch for EEPROM larger then 24C16 (16 bit addressing mode).
|
||||||
|
|
||||||
Again, it's really important that you read the README file.
|
Again, it's really important that you read the README file.
|
||||||
|
|
||||||
|
@@ -24,23 +24,34 @@
|
|||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include "24cXX.h"
|
#include "24cXX.h"
|
||||||
|
|
||||||
#define VERSION "0.7.4"
|
#define VERSION "0.7.5"
|
||||||
|
|
||||||
#define ENV_DEV "EEPROG_DEV"
|
#define ENV_DEV "EEPROG_DEV"
|
||||||
#define ENV_I2C_ADDR "EEPROG_I2C_ADDR"
|
#define ENV_I2C_ADDR "EEPROG_I2C_ADDR"
|
||||||
|
|
||||||
|
int g_quiet;
|
||||||
|
|
||||||
#define usage_if(a) do { do_usage_if( a , __LINE__); } while(0);
|
#define usage_if(a) do { do_usage_if( a , __LINE__); } while(0);
|
||||||
void do_usage_if(int b, int line)
|
void do_usage_if(int b, int line)
|
||||||
{
|
{
|
||||||
const static char *eeprog_usage =
|
const static char *eeprog_usage =
|
||||||
"Usage: eeprog [ -r addr[:count] | -w addr ] /dev/i2c-N i2c-address\n"
|
"eeprog " VERSION ", a 24Cxx EEPROM reader/writer\n"
|
||||||
" -8 Use 8bit address mode for 24c0x...24C16\n"
|
"Copyright (c) 2003 by Stefano Barbato - All rights reserved.\n"
|
||||||
|
"Usage: eeprog [-fqxdh] [-16|-8] [ -r addr[:count] | -w addr ] /dev/i2c-N i2c-address\n"
|
||||||
|
"\n"
|
||||||
|
" Address modes: \n"
|
||||||
|
" -8 Use 8bit address mode for 24c0x...24C16 [default]\n"
|
||||||
|
" -16 Use 16bit address mode for 24c32...24C256\n"
|
||||||
|
" Actions: \n"
|
||||||
" -r addr[:count] Read [count] (1 if omitted) bytes from [addr]\n"
|
" -r addr[:count] Read [count] (1 if omitted) bytes from [addr]\n"
|
||||||
" and print them to the standard output\n"
|
" and print them to the standard output\n"
|
||||||
" -w addr Write input (stdin) at mem address [addr]\n"
|
" -w addr Write input (stdin) at address [addr] of the EEPROM\n"
|
||||||
" -x Set the hex output mode\n"
|
" -h Print this help\n"
|
||||||
|
" Options: \n"
|
||||||
|
" -x Set hex output mode\n"
|
||||||
" -d Dummy mode, display what *would* have been done\n"
|
" -d Dummy mode, display what *would* have been done\n"
|
||||||
" -f Disable warnings and don't ask confirmation\n"
|
" -f Disable warnings and don't ask confirmation\n"
|
||||||
|
" -q Quiet mode\n"
|
||||||
"\n"
|
"\n"
|
||||||
"The following environment variables could be set instead of the command\n"
|
"The following environment variables could be set instead of the command\n"
|
||||||
"line arguments:\n"
|
"line arguments:\n"
|
||||||
@@ -75,6 +86,7 @@ void do_die_if(int b, char* msg, int line)
|
|||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define print_info(args...) do { if(!g_quiet) fprintf(stderr, args); } while(0);
|
||||||
|
|
||||||
void parse_arg(char *arg, int* paddr, int *psize)
|
void parse_arg(char *arg, int* paddr, int *psize)
|
||||||
{
|
{
|
||||||
@@ -88,13 +100,14 @@ int confirm_action()
|
|||||||
{
|
{
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"\n"
|
"\n"
|
||||||
"__________________________________WARNING_______________________________\n"
|
"____________________________WARNING____________________________\n"
|
||||||
"Erroneously writing to a system EEPROM (like DIMM SPD modules) can break your\n"
|
"Erroneously writing to a system EEPROM (like DIMM SPD modules)\n"
|
||||||
"system. It will NOT boot anymore so you'll not be able to fix it.\n"
|
"can break your system. It will NOT boot anymore so you'll not\n"
|
||||||
|
"be able to fix it.\n"
|
||||||
"\n"
|
"\n"
|
||||||
"Reading from 8bit EEPROMs (like that in your DIMM) without using the -8 switch\n"
|
"Reading from 8bit EEPROMs (like that in your DIMM) without using\n"
|
||||||
"can also UNEXPECTEDLY write to them, so be sure to use the -8 command param when\n"
|
"the -8 switch can also UNEXPECTEDLY write to them, so be sure to\n"
|
||||||
"required.\n"
|
"use the -8 command param when required.\n"
|
||||||
"\n"
|
"\n"
|
||||||
"Use -f to disable this warning message\n"
|
"Use -f to disable this warning message\n"
|
||||||
"\n"
|
"\n"
|
||||||
@@ -105,33 +118,35 @@ int confirm_action()
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int read_from_eeprom(struct eeprom *e, int addr, int size, int hex)
|
int read_from_eeprom(struct eeprom *e, int addr, int size, int hex)
|
||||||
{
|
{
|
||||||
int c=1;
|
|
||||||
|
|
||||||
if(!hex)
|
int ch, i;
|
||||||
{
|
|
||||||
putchar(eeprom_read_byte(e, addr));
|
|
||||||
while(--size)
|
|
||||||
{
|
|
||||||
putchar(eeprom_read_current_byte(e));
|
|
||||||
fflush(stdout);
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
// hex print out
|
// hex print out
|
||||||
printf("\n %.4x| %.2x ", addr, eeprom_read_byte(e, addr));
|
die_if((ch = eeprom_read_byte(e, addr)) < 0, "read error");
|
||||||
|
i = 1;
|
||||||
|
if(hex)
|
||||||
|
printf("\n %.4x| %.2x ", addr, ch);
|
||||||
while(--size)
|
while(--size)
|
||||||
|
{
|
||||||
|
die_if((ch = eeprom_read_current_byte(e)) < 0, "read error");
|
||||||
|
if(hex)
|
||||||
{
|
{
|
||||||
addr++;
|
addr++;
|
||||||
if( (c % 16) == 0 )
|
if( (i % 16) == 0 )
|
||||||
printf("\n %.4x| ", addr);
|
printf("\n %.4x| ", addr);
|
||||||
else if( (c % 8) == 0 )
|
else if( (i % 8) == 0 )
|
||||||
printf(" ");
|
printf(" ");
|
||||||
c++;
|
i++;
|
||||||
printf("%.2x ", eeprom_read_current_byte(e));
|
printf("%.2x ", ch);
|
||||||
|
} else {
|
||||||
|
putchar(ch);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
if(hex)
|
||||||
printf("\n\n");
|
printf("\n\n");
|
||||||
|
fflush(stdout);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -140,31 +155,34 @@ int write_to_eeprom(struct eeprom *e, int addr)
|
|||||||
int c;
|
int c;
|
||||||
while((c = getchar()) != EOF)
|
while((c = getchar()) != EOF)
|
||||||
{
|
{
|
||||||
fprintf(stderr, ".");
|
print_info(".");
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
eeprom_write_byte(e, addr++, c);
|
die_if(eeprom_write_byte(e, addr++, c), "write error");
|
||||||
}
|
}
|
||||||
printf("\n\n");
|
print_info("\n\n");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
struct eeprom e;
|
struct eeprom e;
|
||||||
int ret, op, i2c_addr, memaddr, size, want_hex, dummy, force;
|
int ret, op, i2c_addr, memaddr, size, want_hex, dummy, force, sixteen;
|
||||||
char *device, *arg = 0, *i2c_addr_s;
|
char *device, *arg = 0, *i2c_addr_s;
|
||||||
struct stat st;
|
struct stat st;
|
||||||
int eeprom_type = EEPROM_TYPE_16BIT_ADDR;
|
int eeprom_type = 0;
|
||||||
|
|
||||||
op = want_hex = dummy = force = 0;
|
op = want_hex = dummy = force = sixteen = 0;
|
||||||
|
g_quiet = 0;
|
||||||
|
|
||||||
fprintf(stderr, "eeprog %s, a 24Cxx EEPROM reader/writer\n", VERSION);
|
while((ret = getopt(argc, argv, "1:8fr:qhw:xd")) != -1)
|
||||||
fprintf(stderr,
|
|
||||||
"Copyright (c) 2003 by Stefano Barbato - All rights reserved.\n");
|
|
||||||
while((ret = getopt(argc, argv, "8fr:w:xd")) != -1)
|
|
||||||
{
|
{
|
||||||
switch(ret)
|
switch(ret)
|
||||||
{
|
{
|
||||||
|
case '1':
|
||||||
|
usage_if(*optarg != '6' || strlen(optarg) != 1);
|
||||||
|
die_if(eeprom_type, "EEPROM type switch (-8 or -16) used twice");
|
||||||
|
eeprom_type = EEPROM_TYPE_16BIT_ADDR;
|
||||||
|
break;
|
||||||
case 'x':
|
case 'x':
|
||||||
want_hex++;
|
want_hex++;
|
||||||
break;
|
break;
|
||||||
@@ -172,17 +190,27 @@ int main(int argc, char** argv)
|
|||||||
dummy++;
|
dummy++;
|
||||||
break;
|
break;
|
||||||
case '8':
|
case '8':
|
||||||
|
die_if(eeprom_type, "EEPROM type switch (-8 or -16) used twice");
|
||||||
eeprom_type = EEPROM_TYPE_8BIT_ADDR;
|
eeprom_type = EEPROM_TYPE_8BIT_ADDR;
|
||||||
break;
|
break;
|
||||||
case 'f':
|
case 'f':
|
||||||
force++;
|
force++;
|
||||||
break;
|
break;
|
||||||
|
case 'q':
|
||||||
|
g_quiet++;
|
||||||
|
break;
|
||||||
|
case 'h':
|
||||||
|
usage_if(1);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
die_if(op != 0, "Both read and write requested");
|
die_if(op != 0, "Both read and write requested");
|
||||||
arg = optarg;
|
arg = optarg;
|
||||||
op = ret;
|
op = ret;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if(!eeprom_type)
|
||||||
|
eeprom_type = EEPROM_TYPE_8BIT_ADDR; // default
|
||||||
|
|
||||||
usage_if(op == 0); // no switches
|
usage_if(op == 0); // no switches
|
||||||
// set device and i2c_addr reading from cmdline or env
|
// set device and i2c_addr reading from cmdline or env
|
||||||
device = i2c_addr_s = 0;
|
device = i2c_addr_s = 0;
|
||||||
@@ -212,7 +240,9 @@ int main(int argc, char** argv)
|
|||||||
usage_if(!device || !i2c_addr_s);
|
usage_if(!device || !i2c_addr_s);
|
||||||
i2c_addr = strtoul(i2c_addr_s, 0, 0);
|
i2c_addr = strtoul(i2c_addr_s, 0, 0);
|
||||||
|
|
||||||
fprintf(stderr, " Bus: %s, Address: 0x%x, Mode: %dbit\n",
|
print_info("eeprog %s, a 24Cxx EEPROM reader/writer\n", VERSION);
|
||||||
|
print_info("Copyright (c) 2003 by Stefano Barbato - All rights reserved.\n");
|
||||||
|
print_info(" Bus: %s, Address: 0x%x, Mode: %dbit\n",
|
||||||
device, i2c_addr,
|
device, i2c_addr,
|
||||||
(eeprom_type == EEPROM_TYPE_8BIT_ADDR ? 8 : 16) );
|
(eeprom_type == EEPROM_TYPE_8BIT_ADDR ? 8 : 16) );
|
||||||
if(dummy)
|
if(dummy)
|
||||||
@@ -229,16 +259,15 @@ int main(int argc, char** argv)
|
|||||||
confirm_action();
|
confirm_action();
|
||||||
size = 1; // default
|
size = 1; // default
|
||||||
parse_arg(arg, &memaddr, &size);
|
parse_arg(arg, &memaddr, &size);
|
||||||
fprintf(stderr,
|
print_info(" Reading %d bytes from 0x%x\n", size, memaddr);
|
||||||
" Reading %d bytes from 0x%x\n", size, memaddr);
|
|
||||||
read_from_eeprom(&e, memaddr, size, want_hex);
|
read_from_eeprom(&e, memaddr, size, want_hex);
|
||||||
break;
|
break;
|
||||||
case 'w':
|
case 'w':
|
||||||
if(force == 0)
|
if(force == 0)
|
||||||
confirm_action();
|
confirm_action();
|
||||||
parse_arg(arg, &memaddr, &size);
|
parse_arg(arg, &memaddr, &size);
|
||||||
fprintf(stderr,
|
print_info(" Writing stdin starting at address 0x%x\n",
|
||||||
" Writing stdin starting at address 0x%x\n", memaddr);
|
memaddr);
|
||||||
write_to_eeprom(&e, memaddr);
|
write_to_eeprom(&e, memaddr);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
Reference in New Issue
Block a user