ghnotgood opened a new pull request, #17478:
URL: https://github.com/apache/nuttx/pull/17478
## Summary
We need a way to set Block Protect of an EEPROM.
I am happy to discuss other possibilities.
## Impact
EEPROM driver may use ioctl to set Block Protect bits.
## Testing
I wrote a program `foo` to test read/write to the EEPROM:
```
$ tio /dev/ttyUSB0
[17:16:22.306] tio 3.9
[17:16:22.306] Press ctrl-t q to quit
[17:16:22.323] Connected to /dev/ttyUSB0
__start: Reset status: 00:00
NuttShell (NSH) NuttX-12.11.0
nsh> foo r &
foo [3:100]
nsh> IAI21121AR06,BR07,CR05
J24,J25,J29:2-3
closed with 0
foo w &
foo [4:100]
nsh> written 3
closed with 0
nsh> foo r &
foo [5:100]
nsh> barIAI21121AR06,BR07,CR05
J24,J25,J29:2-3
closed with 0
nsh> foo v &
foo [6:100]
nsh> written 3
closed with 0
nsh> foo r &
foo [7:100]
nsh> IAI21121AR06,BR07,CR05
J24,J25,J29:2-3
closed with 0
nsh> foo 1
ioctl returns 0
closed with 0
nsh> foo r &
foo [9:100]
nsh> IAI21121AR06,BR07,CR05
J24,J25,J29:2-3
closed with 0
nsh> foo w &
foo [10:100]
nsh> written 3
closed with 0
nsh> foo r &
foo [11:100]
nsh> IAI21121AR06,BR07,CR05
J24,J25,J29:2-3
closed with 0
nsh>
```
the `foo` is compiled from the `main.c` (just test app, not to be included
in NuttX):
```
#include <fcntl.h> /* open */
#include <unistd.h> /* close, read, write */
#include <stdio.h> /* printf */
#include <sys/ioctl.h> /* ioctl */
#include <nuttx/eeprom/eeprom.h> /* EEPIOC_BLOCKPROTECT */
#define BLEN 100
static void
print_buff(char const *b, size_t len)
{
while (len--) {
putchar(*b++);
}
putchar('\n');
putchar('\n');
}
int
main(int argc, char **argv)
{
int r;
char b[BLEN];
int fd = open("/dev/eeprom0", O_RDWR);
if (-1 == fd) {
printf("ERROR: Failed to open /dev/eeprom0");
return 1;
}
if (2 == argc) {
switch (argv[1][0]) {
case 'a':
while (0 < (r = read(fd, b, BLEN))) {
print_buff(b, BLEN);
}
break;
case 'r':
r = read(fd, b, BLEN);
print_buff(b, BLEN);
break;
case 'w':
r = write(fd, "bar", 3);
printf("written %d\n", r);
break;
case 'v':
b[0] = 0x00;
b[1] = 0x00;
b[2] = 0x00;
r = write(fd, b, 3);
printf("written %d\n", r);
break;
case '0':
r = ioctl(fd, EEPIOC_BLOCKPROTECT, 0);
printf("ioctl returns %d\n", r);
break;
case '1':
r = ioctl(fd, EEPIOC_BLOCKPROTECT, 3);
printf("ioctl returns %d\n", r);
break;
default:
printf("just chilling\n");
}
}
r = close(fd);
printf("closed with %d\n", r);
return 0;
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]