Message ID | 20200715103105.8622-3-igor.opaniuk@gmail.com |
---|---|
State | Accepted |
Commit | c2e969378d7710fe4ffd36f44437833f83e9488a |
Delegated to: | Stefano Babic |
Headers | show |
Series | toradex: imx: fixes and updates for v2020.10 | expand |
Hi Igor, On 15.07.20 12:30, Igor Opaniuk wrote: > From: Igor Opaniuk <igor.opaniuk@toradex.com> > > These functions wrap functionality for storing config blocks in EEPROM. > > Signed-off-by: Igor Opaniuk <igor.opaniuk@toradex.com> > --- > This breaks one of your (obsolete ?) board, colibri_pxa270 Reason is a side-effect in dm/read.h: arm: + colibri_pxa270 +In file included from include/dm.h:12, + from board/toradex/common/tdx-eeprom.c:6: +include/dm/read.h: In function 'dev_read_alias_seq': +include/dm/read.h:932:10: error: 'ENOTSUPP' undeclared (first use in this function) + 932 | return -ENOTSUPP; + | ^~~~~~~~ +include/dm/read.h:932:10: note: each undeclared identifier is reported only once for each function it appears in +make[2]: *** [scripts/Makefile.build:266: board/toradex/common/tdx-eeprom.o] Error 1 +make[1]: *** [Makefile:1793: board/toradex/common] Error 2 +make: *** [Makefile:167: sub-make] Error 2 Adding the include to dm/read.h, issue is solved: diff --git a/include/dm/read.h b/include/dm/read.h index f02ec95954..cc4ab22f65 100644 --- a/include/dm/read.h +++ b/include/dm/read.h @@ -12,6 +12,7 @@ #include <dm/fdtaddr.h> #include <dm/ofnode.h> #include <dm/uclass.h> +#include <linux/errno.h> struct resource; I could add it myself if there is a general agreement, but the usual way is to repost it. Best regards, Stefano > (no changes since v1) > > board/toradex/common/Makefile | 1 + > board/toradex/common/tdx-eeprom.c | 90 +++++++++++++++++++++++++++++++ > board/toradex/common/tdx-eeprom.h | 14 +++++ > 3 files changed, 105 insertions(+) > create mode 100644 board/toradex/common/tdx-eeprom.c > create mode 100644 board/toradex/common/tdx-eeprom.h > > diff --git a/board/toradex/common/Makefile b/board/toradex/common/Makefile > index 6b9fccb6b9..7b19b6e4c8 100644 > --- a/board/toradex/common/Makefile > +++ b/board/toradex/common/Makefile > @@ -8,4 +8,5 @@ obj- := __dummy__.o > else > obj-$(CONFIG_TDX_CFG_BLOCK) += tdx-cfg-block.o > obj-y += tdx-common.o > +obj-y += tdx-eeprom.o > endif > diff --git a/board/toradex/common/tdx-eeprom.c b/board/toradex/common/tdx-eeprom.c > new file mode 100644 > index 0000000000..fbc267dab6 > --- /dev/null > +++ b/board/toradex/common/tdx-eeprom.c > @@ -0,0 +1,90 @@ > +// SPDX-License-Identifier: GPL-2.0+ > +/* > + * Copyright (c) 2020 Toradex > + */ > + > +#include <dm.h> > +#include <i2c_eeprom.h> > +#include <linux/errno.h> > + > +DECLARE_GLOBAL_DATA_PTR; > + > +static int get_tdx_eeprom(u32 eeprom_id, struct udevice **devp) > +{ > + int ret = 0; > + int node; > + ofnode eeprom; > + char eeprom_str[16]; > + const char *path; > + > + if (!gd->fdt_blob) { > + printf("%s: don't have a valid gd->fdt_blob!\n", __func__); > + return -EFAULT; > + } > + > + node = fdt_path_offset(gd->fdt_blob, "/aliases"); > + if (node < 0) > + return -ENODEV; > + > + sprintf(eeprom_str, "eeprom%d", eeprom_id); > + > + path = fdt_getprop(gd->fdt_blob, node, eeprom_str, NULL); > + if (!path) { > + printf("%s: no alias for %s\n", __func__, eeprom_str); > + return -ENODEV; > + } > + > + eeprom = ofnode_path(path); > + if (!ofnode_valid(eeprom)) { > + printf("%s: invalid hardware path to EEPROM\n", __func__); > + return -ENODEV; > + } > + > + ret = uclass_get_device_by_ofnode(UCLASS_I2C_EEPROM, eeprom, devp); > + if (ret) { > + printf("%s: cannot find EEPROM by node\n", __func__); > + return ret; > + } > + > + return ret; > +} > + > +int read_tdx_eeprom_data(u32 eeprom_id, int offset, u8 *buf, > + int size) > +{ > + struct udevice *dev; > + int ret; > + > + ret = get_tdx_eeprom(eeprom_id, &dev); > + if (ret) > + return ret; > + > + ret = i2c_eeprom_read(dev, 0x0, buf, size); > + if (ret) { > + printf("%s: error reading data from EEPROM id: %d!, ret = %d\n", > + __func__, eeprom_id, ret); > + return ret; > + } > + > + return ret; > +} > + > +int write_tdx_eeprom_data(u32 eeprom_id, int offset, u8 *buf, > + int size) > +{ > + struct udevice *dev; > + int ret; > + > + ret = get_tdx_eeprom(eeprom_id, &dev); > + if (ret) > + return ret; > + > + ret = i2c_eeprom_write(dev, 0x0, buf, size); > + if (ret) { > + printf("%s: error writing data to EEPROM id: %d, ret = %d\n", > + __func__, eeprom_id, ret); > + return ret; > + } > + > + return ret; > +} > diff --git a/board/toradex/common/tdx-eeprom.h b/board/toradex/common/tdx-eeprom.h > new file mode 100644 > index 0000000000..a6772d2f3f > --- /dev/null > +++ b/board/toradex/common/tdx-eeprom.h > @@ -0,0 +1,14 @@ > +/* SPDX-License-Identifier: GPL-2.0+ */ > +/* > + * Copyright (c) 2020 Toradex > + */ > + > +#ifndef _TDX_EEPROM_H > +#define _TDX_EEPROM_H > + > +#include <i2c_eeprom.h> > + > +int read_tdx_eeprom_data(u32 eeprom_id, int offset, uint8_t *buf, int size); > +int write_tdx_eeprom_data(u32 eeprom_id, int offset, uint8_t *buf, int size); > + > +#endif /* _TDX_EEPROM_H */ >
On Mon, Jul 27, 2020 at 02:49:30PM +0200, Stefano Babic wrote: > Hi Igor, > > On 15.07.20 12:30, Igor Opaniuk wrote: > > From: Igor Opaniuk <igor.opaniuk@toradex.com> > > > > These functions wrap functionality for storing config blocks in EEPROM. > > > > Signed-off-by: Igor Opaniuk <igor.opaniuk@toradex.com> > > --- > > > > This breaks one of your (obsolete ?) board, colibri_pxa270 > > Reason is a side-effect in dm/read.h: > > arm: + colibri_pxa270 > +In file included from include/dm.h:12, > + from board/toradex/common/tdx-eeprom.c:6: > +include/dm/read.h: In function 'dev_read_alias_seq': > +include/dm/read.h:932:10: error: 'ENOTSUPP' undeclared (first use in > this function) > + 932 | return -ENOTSUPP; > + | ^~~~~~~~ > +include/dm/read.h:932:10: note: each undeclared identifier is reported > only once for each function it appears in > +make[2]: *** [scripts/Makefile.build:266: > board/toradex/common/tdx-eeprom.o] Error 1 > +make[1]: *** [Makefile:1793: board/toradex/common] Error 2 > +make: *** [Makefile:167: sub-make] Error 2 > > > Adding the include to dm/read.h, issue is solved: > > diff --git a/include/dm/read.h b/include/dm/read.h > index f02ec95954..cc4ab22f65 100644 > --- a/include/dm/read.h > +++ b/include/dm/read.h > @@ -12,6 +12,7 @@ > #include <dm/fdtaddr.h> > #include <dm/ofnode.h> > #include <dm/uclass.h> > +#include <linux/errno.h> > > struct resource; > > > I could add it myself if there is a general agreement, but the usual way > is to repost it. This is also fixed by: http://patchwork.ozlabs.org/project/uboot/patch/20200723120138.10625-1-dmurphy@ti.com/ as Dan also ran in to this problem. I assigned it to Simon but if you want to take it as part of being able to pick up Igor's series now I'm sure that's fine. Thanks!
On 27.07.20 15:35, Tom Rini wrote: > On Mon, Jul 27, 2020 at 02:49:30PM +0200, Stefano Babic wrote: >> Hi Igor, >> >> On 15.07.20 12:30, Igor Opaniuk wrote: >>> From: Igor Opaniuk <igor.opaniuk@toradex.com> >>> >>> These functions wrap functionality for storing config blocks in EEPROM. >>> >>> Signed-off-by: Igor Opaniuk <igor.opaniuk@toradex.com> >>> --- >>> >> >> This breaks one of your (obsolete ?) board, colibri_pxa270 >> >> Reason is a side-effect in dm/read.h: >> >> arm: + colibri_pxa270 >> +In file included from include/dm.h:12, >> + from board/toradex/common/tdx-eeprom.c:6: >> +include/dm/read.h: In function 'dev_read_alias_seq': >> +include/dm/read.h:932:10: error: 'ENOTSUPP' undeclared (first use in >> this function) >> + 932 | return -ENOTSUPP; >> + | ^~~~~~~~ >> +include/dm/read.h:932:10: note: each undeclared identifier is reported >> only once for each function it appears in >> +make[2]: *** [scripts/Makefile.build:266: >> board/toradex/common/tdx-eeprom.o] Error 1 >> +make[1]: *** [Makefile:1793: board/toradex/common] Error 2 >> +make: *** [Makefile:167: sub-make] Error 2 >> >> >> Adding the include to dm/read.h, issue is solved: >> >> diff --git a/include/dm/read.h b/include/dm/read.h >> index f02ec95954..cc4ab22f65 100644 >> --- a/include/dm/read.h >> +++ b/include/dm/read.h >> @@ -12,6 +12,7 @@ >> #include <dm/fdtaddr.h> >> #include <dm/ofnode.h> >> #include <dm/uclass.h> >> +#include <linux/errno.h> >> >> struct resource; >> >> >> I could add it myself if there is a general agreement, but the usual way >> is to repost it. > > This is also fixed by: > http://patchwork.ozlabs.org/project/uboot/patch/20200723120138.10625-1-dmurphy@ti.com/ > as Dan also ran in to this problem. I assigned it to Simon but if you > want to take it as part of being able to pick up Igor's series now I'm > sure that's fine. Thanks! Fine, thanks ! I pick up Dan's. Stefano
> From: Igor Opaniuk <igor.opaniuk@toradex.com> > These functions wrap functionality for storing config blocks in EEPROM. > Signed-off-by: Igor Opaniuk <igor.opaniuk@toradex.com> Applied to u-boot-imx, master, thanks ! Best regards, Stefano Babic
diff --git a/board/toradex/common/Makefile b/board/toradex/common/Makefile index 6b9fccb6b9..7b19b6e4c8 100644 --- a/board/toradex/common/Makefile +++ b/board/toradex/common/Makefile @@ -8,4 +8,5 @@ obj- := __dummy__.o else obj-$(CONFIG_TDX_CFG_BLOCK) += tdx-cfg-block.o obj-y += tdx-common.o +obj-y += tdx-eeprom.o endif diff --git a/board/toradex/common/tdx-eeprom.c b/board/toradex/common/tdx-eeprom.c new file mode 100644 index 0000000000..fbc267dab6 --- /dev/null +++ b/board/toradex/common/tdx-eeprom.c @@ -0,0 +1,90 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (c) 2020 Toradex + */ + +#include <dm.h> +#include <i2c_eeprom.h> +#include <linux/errno.h> + +DECLARE_GLOBAL_DATA_PTR; + +static int get_tdx_eeprom(u32 eeprom_id, struct udevice **devp) +{ + int ret = 0; + int node; + ofnode eeprom; + char eeprom_str[16]; + const char *path; + + if (!gd->fdt_blob) { + printf("%s: don't have a valid gd->fdt_blob!\n", __func__); + return -EFAULT; + } + + node = fdt_path_offset(gd->fdt_blob, "/aliases"); + if (node < 0) + return -ENODEV; + + sprintf(eeprom_str, "eeprom%d", eeprom_id); + + path = fdt_getprop(gd->fdt_blob, node, eeprom_str, NULL); + if (!path) { + printf("%s: no alias for %s\n", __func__, eeprom_str); + return -ENODEV; + } + + eeprom = ofnode_path(path); + if (!ofnode_valid(eeprom)) { + printf("%s: invalid hardware path to EEPROM\n", __func__); + return -ENODEV; + } + + ret = uclass_get_device_by_ofnode(UCLASS_I2C_EEPROM, eeprom, devp); + if (ret) { + printf("%s: cannot find EEPROM by node\n", __func__); + return ret; + } + + return ret; +} + +int read_tdx_eeprom_data(u32 eeprom_id, int offset, u8 *buf, + int size) +{ + struct udevice *dev; + int ret; + + ret = get_tdx_eeprom(eeprom_id, &dev); + if (ret) + return ret; + + ret = i2c_eeprom_read(dev, 0x0, buf, size); + if (ret) { + printf("%s: error reading data from EEPROM id: %d!, ret = %d\n", + __func__, eeprom_id, ret); + return ret; + } + + return ret; +} + +int write_tdx_eeprom_data(u32 eeprom_id, int offset, u8 *buf, + int size) +{ + struct udevice *dev; + int ret; + + ret = get_tdx_eeprom(eeprom_id, &dev); + if (ret) + return ret; + + ret = i2c_eeprom_write(dev, 0x0, buf, size); + if (ret) { + printf("%s: error writing data to EEPROM id: %d, ret = %d\n", + __func__, eeprom_id, ret); + return ret; + } + + return ret; +} diff --git a/board/toradex/common/tdx-eeprom.h b/board/toradex/common/tdx-eeprom.h new file mode 100644 index 0000000000..a6772d2f3f --- /dev/null +++ b/board/toradex/common/tdx-eeprom.h @@ -0,0 +1,14 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* + * Copyright (c) 2020 Toradex + */ + +#ifndef _TDX_EEPROM_H +#define _TDX_EEPROM_H + +#include <i2c_eeprom.h> + +int read_tdx_eeprom_data(u32 eeprom_id, int offset, uint8_t *buf, int size); +int write_tdx_eeprom_data(u32 eeprom_id, int offset, uint8_t *buf, int size); + +#endif /* _TDX_EEPROM_H */