diff mbox series

[OpenWrt-Devel,v2,12/14] package/base-files: add caldata_sysfsload_from_file()

Message ID 20200420133503.18700-13-hacks@slashdirt.org
State Accepted
Delegated to: Koen Vandeputte
Headers show
Series RouterBOARD sysfs driver for RouterBoot data | expand

Commit Message

Thibaut April 20, 2020, 1:35 p.m. UTC
This routine enables loading caldata binary via the kernel sysfs loader

Signed-off-by: Thibaut VARÈNE <hacks@slashdirt.org>
---
 package/base-files/Makefile                       |  2 +-
 package/base-files/files/lib/functions/caldata.sh | 15 +++++++++++++++
 2 files changed, 16 insertions(+), 1 deletion(-)

Comments

Adrian Schmutzler April 20, 2020, 2:14 p.m. UTC | #1
Hi,

> -----Original Message-----
> From: openwrt-devel [mailto:openwrt-devel-bounces@lists.openwrt.org]
> On Behalf Of Thibaut VARÈNE
> Sent: Montag, 20. April 2020 15:35
> To: openwrt-devel@lists.openwrt.org
> Cc: Thibaut VARÈNE <hacks@slashdirt.org>; koen.vandeputte@ncentric.com
> Subject: [OpenWrt-Devel] [PATCH v2 12/14] package/base-files: add
> caldata_sysfsload_from_file()
> 
> This routine enables loading caldata binary via the kernel sysfs loader
> 
> Signed-off-by: Thibaut VARÈNE <hacks@slashdirt.org>
> ---
>  package/base-files/Makefile                       |  2 +-
>  package/base-files/files/lib/functions/caldata.sh | 15 +++++++++++++++
>  2 files changed, 16 insertions(+), 1 deletion(-)
> 
> diff --git a/package/base-files/Makefile b/package/base-files/Makefile index
> f1f0f17a60..d8e7c31878 100644
> --- a/package/base-files/Makefile
> +++ b/package/base-files/Makefile
> @@ -12,7 +12,7 @@ include $(INCLUDE_DIR)/version.mk  include
> $(INCLUDE_DIR)/feeds.mk
> 
>  PKG_NAME:=base-files
> -PKG_RELEASE:=219
> +PKG_RELEASE:=220
>  PKG_FLAGS:=nonshared
> 
>  PKG_FILE_DEPENDS:=$(PLATFORM_DIR)/
> $(GENERIC_PLATFORM_DIR)/base-files/
> diff --git a/package/base-files/files/lib/functions/caldata.sh b/package/base-
> files/files/lib/functions/caldata.sh
> index e9349c7eee..a64f07778d 100644
> --- a/package/base-files/files/lib/functions/caldata.sh
> +++ b/package/base-files/files/lib/functions/caldata.sh
> @@ -68,6 +68,21 @@ caldata_from_file() {
>  		caldata_die "failed to extract calibration data from $source"
>  }
> 
> +caldata_sysfsload_from_file() {

Didn't get that at first. Maybe choose something like
caldata_file_to_sysfs()?

> +	local source=$1
> +	local offset=$(($2))
> +	local count=$(($3))
> +
> +	# test extract to /dev/null first
> +	dd if=$source of=/dev/null iflag=skip_bytes bs=$count skip=$offset
> count=1 2>/dev/null || \
> +		caldata_die "failed to extract calibration data from $source"
> +
> +	# can't fail now
> +	echo 1 > /sys/$DEVPATH/loading

Maybe make $DEVPATH or /sys/$DEVPATH an argument?

Best

Adrian

> +	dd if=$source of=/sys/$DEVPATH/data iflag=skip_bytes bs=$count
> skip=$offset count=1 2>/dev/null
> +	echo 0 > /sys/$DEVPATH/loading
> +}
> +
>  caldata_valid() {
>  	local expected="$1"
>  	local target=$2
> --
> 2.11.0
> 
> 
> _______________________________________________
> openwrt-devel mailing list
> openwrt-devel@lists.openwrt.org
> https://lists.openwrt.org/mailman/listinfo/openwrt-devel
Adrian Schmutzler April 20, 2020, 2:21 p.m. UTC | #2
Hi again,

> -----Original Message-----
> From: openwrt-devel [mailto:openwrt-devel-bounces@lists.openwrt.org]
> On Behalf Of mail@adrianschmutzler.de
> Sent: Montag, 20. April 2020 16:14
> To: 'Thibaut VARÈNE' <hacks@slashdirt.org>; openwrt-
> devel@lists.openwrt.org
> Cc: koen.vandeputte@ncentric.com
> Subject: Re: [OpenWrt-Devel] [PATCH v2 12/14] package/base-files: add
> caldata_sysfsload_from_file()
> 
> Hi,
> 
> > -----Original Message-----
> > From: openwrt-devel [mailto:openwrt-devel-bounces@lists.openwrt.org]
> > On Behalf Of Thibaut VARÈNE
> > Sent: Montag, 20. April 2020 15:35
> > To: openwrt-devel@lists.openwrt.org
> > Cc: Thibaut VARÈNE <hacks@slashdirt.org>;
> koen.vandeputte@ncentric.com
> > Subject: [OpenWrt-Devel] [PATCH v2 12/14] package/base-files: add
> > caldata_sysfsload_from_file()
> >
> > This routine enables loading caldata binary via the kernel sysfs
> > loader
> >
> > Signed-off-by: Thibaut VARÈNE <hacks@slashdirt.org>
> > ---
> >  package/base-files/Makefile                       |  2 +-
> >  package/base-files/files/lib/functions/caldata.sh | 15
> > +++++++++++++++
> >  2 files changed, 16 insertions(+), 1 deletion(-)
> >
> > diff --git a/package/base-files/Makefile b/package/base-files/Makefile
> > index
> > f1f0f17a60..d8e7c31878 100644
> > --- a/package/base-files/Makefile
> > +++ b/package/base-files/Makefile
> > @@ -12,7 +12,7 @@ include $(INCLUDE_DIR)/version.mk  include
> > $(INCLUDE_DIR)/feeds.mk
> >
> >  PKG_NAME:=base-files
> > -PKG_RELEASE:=219
> > +PKG_RELEASE:=220
> >  PKG_FLAGS:=nonshared
> >
> >  PKG_FILE_DEPENDS:=$(PLATFORM_DIR)/
> > $(GENERIC_PLATFORM_DIR)/base-files/
> > diff --git a/package/base-files/files/lib/functions/caldata.sh
> > b/package/base- files/files/lib/functions/caldata.sh
> > index e9349c7eee..a64f07778d 100644
> > --- a/package/base-files/files/lib/functions/caldata.sh
> > +++ b/package/base-files/files/lib/functions/caldata.sh
> > @@ -68,6 +68,21 @@ caldata_from_file() {
> >  		caldata_die "failed to extract calibration data from $source"
> >  }
> >
> > +caldata_sysfsload_from_file() {
> 
> Didn't get that at first. Maybe choose something like caldata_file_to_sysfs()?
> 
> > +	local source=$1
> > +	local offset=$(($2))
> > +	local count=$(($3))
> > +
> > +	# test extract to /dev/null first
> > +	dd if=$source of=/dev/null iflag=skip_bytes bs=$count skip=$offset
> > count=1 2>/dev/null || \
> > +		caldata_die "failed to extract calibration data from $source"
> > +
> > +	# can't fail now
> > +	echo 1 > /sys/$DEVPATH/loading
> 
> Maybe make $DEVPATH or /sys/$DEVPATH an argument?

On a second thought: That's not so much different from how we handle /lib/firmware/$FIRMWARE in this file.

Can you comment on whether the implementation of /sys/$DEVPATH will be as generic as /lib/firmware/$FIRMWARE? (Then we could keep it your way)
Or is this dependent on your driver implementation, and thus specific to mikrotik? Then, we could still keep it in base-files, but should reflect that in the function name.

Best

Adrian

> 
> Best
> 
> Adrian
> 
> > +	dd if=$source of=/sys/$DEVPATH/data iflag=skip_bytes bs=$count
> > skip=$offset count=1 2>/dev/null
> > +	echo 0 > /sys/$DEVPATH/loading
> > +}
> > +
> >  caldata_valid() {
> >  	local expected="$1"
> >  	local target=$2
> > --
> > 2.11.0
> >
> >
> > _______________________________________________
> > openwrt-devel mailing list
> > openwrt-devel@lists.openwrt.org
> > https://lists.openwrt.org/mailman/listinfo/openwrt-devel
Thibaut April 20, 2020, 2:23 p.m. UTC | #3
Hi,

> Le 20 avr. 2020 à 16:21, <mail@adrianschmutzler.de> <mail@adrianschmutzler.de> a écrit :
> 
> Hi again,
> 
>> -----Original Message-----
>> From: openwrt-devel [mailto:openwrt-devel-bounces@lists.openwrt.org]
>> On Behalf Of mail@adrianschmutzler.de
>> Sent: Montag, 20. April 2020 16:14
>> To: 'Thibaut VARÈNE' <hacks@slashdirt.org>; openwrt-
>> devel@lists.openwrt.org
>> Cc: koen.vandeputte@ncentric.com
>> Subject: Re: [OpenWrt-Devel] [PATCH v2 12/14] package/base-files: add
>> caldata_sysfsload_from_file()
>> 
>> Hi,
>> 
>>> -----Original Message-----
>>> From: openwrt-devel [mailto:openwrt-devel-bounces@lists.openwrt.org]
>>> On Behalf Of Thibaut VARÈNE
>>> Sent: Montag, 20. April 2020 15:35
>>> To: openwrt-devel@lists.openwrt.org
>>> Cc: Thibaut VARÈNE <hacks@slashdirt.org>;
>> koen.vandeputte@ncentric.com
>>> Subject: [OpenWrt-Devel] [PATCH v2 12/14] package/base-files: add
>>> caldata_sysfsload_from_file()
>>> 
>>> This routine enables loading caldata binary via the kernel sysfs
>>> loader
>>> 
>>> Signed-off-by: Thibaut VARÈNE <hacks@slashdirt.org>
>>> ---
>>> package/base-files/Makefile                       |  2 +-
>>> package/base-files/files/lib/functions/caldata.sh | 15
>>> +++++++++++++++
>>> 2 files changed, 16 insertions(+), 1 deletion(-)
>>> 
>>> diff --git a/package/base-files/Makefile b/package/base-files/Makefile
>>> index
>>> f1f0f17a60..d8e7c31878 100644
>>> --- a/package/base-files/Makefile
>>> +++ b/package/base-files/Makefile
>>> @@ -12,7 +12,7 @@ include $(INCLUDE_DIR)/version.mk  include
>>> $(INCLUDE_DIR)/feeds.mk
>>> 
>>> PKG_NAME:=base-files
>>> -PKG_RELEASE:=219
>>> +PKG_RELEASE:=220
>>> PKG_FLAGS:=nonshared
>>> 
>>> PKG_FILE_DEPENDS:=$(PLATFORM_DIR)/
>>> $(GENERIC_PLATFORM_DIR)/base-files/
>>> diff --git a/package/base-files/files/lib/functions/caldata.sh
>>> b/package/base- files/files/lib/functions/caldata.sh
>>> index e9349c7eee..a64f07778d 100644
>>> --- a/package/base-files/files/lib/functions/caldata.sh
>>> +++ b/package/base-files/files/lib/functions/caldata.sh
>>> @@ -68,6 +68,21 @@ caldata_from_file() {
>>> 		caldata_die "failed to extract calibration data from $source"
>>> }
>>> 
>>> +caldata_sysfsload_from_file() {
>> 
>> Didn't get that at first. Maybe choose something like caldata_file_to_sysfs()?
>> 
>>> +	local source=$1
>>> +	local offset=$(($2))
>>> +	local count=$(($3))
>>> +
>>> +	# test extract to /dev/null first
>>> +	dd if=$source of=/dev/null iflag=skip_bytes bs=$count skip=$offset
>>> count=1 2>/dev/null || \
>>> +		caldata_die "failed to extract calibration data from $source"
>>> +
>>> +	# can't fail now
>>> +	echo 1 > /sys/$DEVPATH/loading
>> 
>> Maybe make $DEVPATH or /sys/$DEVPATH an argument?
> 
> On a second thought: That's not so much different from how we handle /lib/firmware/$FIRMWARE in this file.
> 
> Can you comment on whether the implementation of /sys/$DEVPATH will be as generic as /lib/firmware/$FIRMWARE? (Then we could keep it your way)
> Or is this dependent on your driver implementation, and thus specific to mikrotik? Then, we could still keep it in base-files, but should reflect that in the function name.

This is using the standard kernel fallback mechanism:
https://www.kernel.org/doc/html/v4.19/driver-api/firmware/fallback-mechanisms.html#firmware-kobject-uevent-fallback-mechanism

$DEVPATH is provided by the kernel, and refers to the sysfs path.

HTH
diff mbox series

Patch

diff --git a/package/base-files/Makefile b/package/base-files/Makefile
index f1f0f17a60..d8e7c31878 100644
--- a/package/base-files/Makefile
+++ b/package/base-files/Makefile
@@ -12,7 +12,7 @@  include $(INCLUDE_DIR)/version.mk
 include $(INCLUDE_DIR)/feeds.mk
 
 PKG_NAME:=base-files
-PKG_RELEASE:=219
+PKG_RELEASE:=220
 PKG_FLAGS:=nonshared
 
 PKG_FILE_DEPENDS:=$(PLATFORM_DIR)/ $(GENERIC_PLATFORM_DIR)/base-files/
diff --git a/package/base-files/files/lib/functions/caldata.sh b/package/base-files/files/lib/functions/caldata.sh
index e9349c7eee..a64f07778d 100644
--- a/package/base-files/files/lib/functions/caldata.sh
+++ b/package/base-files/files/lib/functions/caldata.sh
@@ -68,6 +68,21 @@  caldata_from_file() {
 		caldata_die "failed to extract calibration data from $source"
 }
 
+caldata_sysfsload_from_file() {
+	local source=$1
+	local offset=$(($2))
+	local count=$(($3))
+
+	# test extract to /dev/null first
+	dd if=$source of=/dev/null iflag=skip_bytes bs=$count skip=$offset count=1 2>/dev/null || \
+		caldata_die "failed to extract calibration data from $source"
+
+	# can't fail now
+	echo 1 > /sys/$DEVPATH/loading
+	dd if=$source of=/sys/$DEVPATH/data iflag=skip_bytes bs=$count skip=$offset count=1 2>/dev/null
+	echo 0 > /sys/$DEVPATH/loading
+}
+
 caldata_valid() {
 	local expected="$1"
 	local target=$2