0
\$\begingroup\$

Probably a very newbie question:

I have a Zynq 7100, zc706 board. I am playing around with the ARM Processing System with Xilinx's PetaLinux distro. What would happen if I added a device to the device tree, say and EEPROM on the I2C bus, but in reality I never physically attached the EEPROM to the bus. I then try to use the I2C Linux driver to read and write to the address in the device tree where the EEPROM is. Will the attempt to open the file just fail? If that is the case what is the point of the device tree, just to tell the kernel to look for the devices/include the driver and build a certain way?

if((file = open(I2C_ADAPTER, O_RDWR)) < 0) {
        printf("Failed to open the bus\n");
        return -1;
    }
buf[0] = addr;
buf[1] = reg_addr;
buf[2] = 0x10;
if(write(file, buf, 3) != 3) {
    printf("Failed to write to bus %s.\n\n", strerror(errno));
}
else {
    printf("Successful write\n");
    printf(buf);
    printf("\n\n");
}

if(read(file, buf, 3) != 3) {
    printf("Failed to read from the i2c bus.\n %s\n\n", strerror(errno));
}
else {
    printf("Successful read\n");
    printf("Buf = [%02X,%02X,%02X]\n", buf[0], buf[1], buf[2]);
    printf("\n\n");
}

Let's say I feed the code an I2C bus address (addr) of 0x5d and write to the base register reg_addr is 0x00, which is where my EEPROM is in the device tree. How does the system know the device location if I were to connect an EEPROM?

\$\endgroup\$
  • \$\begingroup\$ It would probably try to access the device, get no I2C acknowledge, and report failure. \$\endgroup\$ – Tom Carpenter Oct 31 '17 at 16:12
  • \$\begingroup\$ In that case what was the point of having it in the tree? \$\endgroup\$ – John Frye Oct 31 '17 at 16:14
  • 2
    \$\begingroup\$ You wrote "...I added a device to the device tree, [...], but in reality I never physically attached the EEPROM to the bus". You tell us what the point was, since you've added it. \$\endgroup\$ – Nick Alexeev Oct 31 '17 at 16:32
1
\$\begingroup\$

A device can fail anytime, and drivers have to handle such problems gracefully. So, don't oops and and don't run into endless loops. Instead, report an error code to userspace or upstream device driver. (This usually isn't a problem unless a device has VM-mapped RAM or doing DMA transfers.)

The purpose of the device tree is to take the knowledge of individual board designs out of the drivers, so one driver can handle any board which has a certain kind of device on it.

If you never plan to attach a certain I²C chip to the board, it's best to remove it from the device tree definition and recompile. If it's optional, you better place it into an overlay file so the user can decide if he had that hardware or not.

Look for the Raspberry Pi device tree stuff, it has numerous overlays for all kind of stuff to attach.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.