Skip to contentSkip to conversation

Don't use SBI functions in fdt code

PATCH Superseded Daniel Schaefer 5 participants 13 messages May 17, 2021 – May 19, 2021

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover Don't use SBI functions in fdt code

My previous solution to build v0.9 in EDK2 wasn't correct:
http://lists.infradead.org/pipermail/opensbi/2021-May/000982.html

Abner reminded me that he had done a similar change before. It was to not use SBI functions in the FDT files but instead call those from libfdt_env.h.

See:
2cfd2fc9048806353298a1b967abf985901e36e8
2845d2d2cf4fb74a89452ba223995aa4a118c07e
8e47649eff96c303e02fbd58cdc6c4ed341066ec

Doing the same kinds of changes again, solves the issue.

Cc Abner Chang <[email protected]>
Cc Anup Patel <[email protected]>

Daniel Schaefer (3):
lib: utils: Add macro to libfdt_env.h for strncpy
lib: fdt: Don't use sbi_string functions
lib: utils: Replace strcmp with strcmp

 lib/utils/fdt/fdt_domain.c    | 7 ++++---
 lib/utils/libfdt/libfdt_env.h | 1 +
 2 files changed, 5 insertions(+), 3 deletions(-)
Signature · 1 line
2.30.1
#1 lore raw

PATCH 1/3 lib: utils: Add macro to libfdt_env.h for strncpy

Just like 2845d2d2cf4fb74a89452ba223995aa4a118c07e

---
 lib/utils/libfdt/libfdt_env.h | 1 +
 1 file changed, 1 insertion(+)
lib/utils/libfdt/libfdt_env.h +1 -0
index bc3e7588660a..f9d9c6783c52 100644
@@ -31,6 +31,7 @@
 #define strchr		sbi_strchr
 #define strrchr		sbi_strrchr
 #define strcpy		sbi_strcpy
+#define strncpy		sbi_strncpy
 #define strcmp		sbi_strcmp
 #define strncmp		sbi_strncmp
 #define strlen		sbi_strlen
Signature · 1 line
2.30.1
#2 lore raw

PATCH 1/3 lib: utils: Add macro to libfdt_env.h for strncpy

? 2021-05-17?? 19:33 +0800?Daniel Schaefer???

Quoted 5 lines

Just like 2845d2d2cf4fb74a89452ba223995aa4a118c07e

Look good to me.
This description doesn't look very clear.

I recommend reword:

lib: utils: Add a macro in libfdt_env.h for strncpy

This commit add a macro to replace strncpy with sbi_strncpy.

Regards
Xiang W

Quoted 21 lines
---
 lib/utils/libfdt/libfdt_env.h | 1 +
 1 file changed, 1 insertion(+)
lib/utils/libfdt/libfdt_env.h +1 -0
index bc3e7588660a..f9d9c6783c52 100644
@@ -31,6 +31,7 @@
 #define strchr		sbi_strchr
 #define strrchr		sbi_strrchr
 #define strcpy		sbi_strcpy
+#define strncpy		sbi_strncpy
 #define strcmp		sbi_strcmp
 #define strncmp		sbi_strncmp
 #define strlen		sbi_strlen
Signature · 1 line
2.30.1
#3 lore raw

PATCH 1/3 lib: utils: Add macro to libfdt_env.h for strncpy

Quoted 46 lines

-----Original Message-----
From: Xiang W [mailto:wxjstz at 126.com]
Sent: Monday, May 17, 2021 9:48 PM
To: Schaefer, Daniel <[email protected]>; opensbi at lists.infradead.org
Cc: Chang, Abner (HPS SW/FW Technologist) <[email protected]>; Anup Patel <[email protected]>
Subject: Re: [PATCH v1 1/3] lib: utils: Add macro to libfdt_env.h for strncpy

? 2021-05-17?? 19:33 +0800?Daniel Schaefer???

Quoted 5 lines

Just like 2845d2d2cf4fb74a89452ba223995aa4a118c07e

Look good to me.
This description doesn't look very clear.

I recommend reword:

lib: utils: Add a macro in libfdt_env.h for strncpy

This commit add a macro to replace strncpy with sbi_strncpy.

Regards
Xiang W

Quoted 21 lines
---
 lib/utils/libfdt/libfdt_env.h | 1 +
 1 file changed, 1 insertion(+)
lib/utils/libfdt/libfdt_env.h +1 -1
index bc3e7588660a..f9d9c6783c52 100644
@@ -31,6 +31,7 @@
 #define strchr		sbi_strchr
 #define strrchr		sbi_strrchr
 #define strcpy		sbi_strcpy
+#define strncpy		sbi_strncpy
 #define strcmp		sbi_strcmp
 #define strncmp		sbi_strncmp
 #define strlen		sbi_strlen
--

2.30.1

#4 lore raw

PATCH 2/3 lib: fdt: Don't use sbi_string functions

In reply to Daniel Schaefer

When SBI is built by external firmware, we need to use their functions, defined in libfdt_env.h.
Just like 2cfd2fc9048806353298a1b967abf985901e36e8

---
 lib/utils/fdt/fdt_domain.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
lib/utils/fdt/fdt_domain.c +4 -3
index 95c195d65238..c1f6a8c8a10b 100644
@@ -9,6 +9,7 @@
  */
 
 #include <libfdt.h>
+#include <libfdt_env.h>
 #include <sbi/sbi_domain.h>
 #include <sbi/sbi_error.h>
 #include <sbi/sbi_hartmask.h>
@@ -95,7 +96,7 @@ static int __fixup_find_domain_offset(void *fdt, int doff, void *p)
 {
 	struct __fixup_find_domain_offset_info *fdo = p;
 
-	if (!sbi_strcmp(fdo->name, fdt_get_name(fdt, doff, NULL)))
+	if (!strcmp(fdo->name, fdt_get_name(fdt, doff, NULL)))
 		*fdo->doffset = doff;
 
 	return 0;
@@ -287,7 +288,7 @@ static int __fdt_parse_domain(void *fdt, int domain_offset, void *opaque)
 	regions = &fdt_regions[fdt_domains_count][0];
 
 	/* Read DT node name */
-	sbi_strncpy(dom->name, fdt_get_name(fdt, domain_offset, NULL),
+	strncpy(dom->name, fdt_get_name(fdt, domain_offset, NULL),
 		    sizeof(dom->name));
 	dom->name[sizeof(dom->name) - 1] = '\0';
 
@@ -313,7 +314,7 @@ static int __fdt_parse_domain(void *fdt, int domain_offset, void *opaque)
 
 	/* Setup memregions from DT */
 	val32 = 0;
-	sbi_memset(regions, 0,
+	memset(regions, 0,
 		   sizeof(*regions) * (FDT_DOMAIN_REGION_MAX_COUNT + 1));
 	dom->regions = regions;
 	err = fdt_iterate_each_memregion(fdt, domain_offset, &val32,
Signature · 1 line
2.30.1
#5 lore raw

PATCH 2/3 lib: fdt: Don't use sbi_string functions

? 2021-05-17?? 19:33 +0800?Daniel Schaefer???

Quoted 8 lines

When SBI is built by external firmware, we need to use their functions,
defined in libfdt_env.h.
Just like 2cfd2fc9048806353298a1b967abf985901e36e8

Look good to me.

but lost sbi_memcpy in line 340.

Regards
Xiang W

Quoted 51 lines
---
 lib/utils/fdt/fdt_domain.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
lib/utils/fdt/fdt_domain.c +2 -1
index 95c195d65238..c1f6a8c8a10b 100644
@@ -9,6 +9,7 @@
  */
 
 #include <libfdt.h>
+#include <libfdt_env.h>
 #include <sbi/sbi_domain.h>
 #include <sbi/sbi_error.h>
 #include <sbi/sbi_hartmask.h>
@@ -95,7 +96,7 @@ static int __fixup_find_domain_offset(void *fdt,
 int doff, void *p)
 {
 	struct __fixup_find_domain_offset_info *fdo = p;
 
-	if (!sbi_strcmp(fdo->name, fdt_get_name(fdt, doff, NULL)))
+	if (!strcmp(fdo->name, fdt_get_name(fdt, doff, NULL)))
 		*fdo->doffset = doff;
 
lib/utils/fdt/fdt_domain.c +2 -2
 	return 0;
@@ -287,7 +288,7 @@ static int __fdt_parse_domain(void *fdt, int
 domain_offset, void *opaque)
 	regions = &fdt_regions[fdt_domains_count][0];
 
 	/* Read DT node name */
-	sbi_strncpy(dom->name, fdt_get_name(fdt, domain_offset, NULL),
+	strncpy(dom->name, fdt_get_name(fdt, domain_offset, NULL),
 		    sizeof(dom->name));
 	dom->name[sizeof(dom->name) - 1] = '\0';
@@ -313,7 +314,7 @@ static int __fdt_parse_domain(void *fdt, int
 domain_offset, void *opaque)
 
 	/* Setup memregions from DT */
 	val32 = 0;
-	sbi_memset(regions, 0,
+	memset(regions, 0,
 		   sizeof(*regions) * (FDT_DOMAIN_REGION_MAX_COUNT +
 1));
lib/utils/fdt/fdt_domain.c +0 -0
 	dom->regions = regions;
 	err = fdt_iterate_each_memregion(fdt, domain_offset, &val32,
Signature · 1 line
2.30.1
#6 lore raw

PATCH 2/3 lib: fdt: Don't use sbi_string functions

After addressing Xiang's comment.

Quoted 74 lines

-----Original Message-----
From: Xiang W [mailto:wxjstz at 126.com]
Sent: Monday, May 17, 2021 9:54 PM
To: Schaefer, Daniel <[email protected]>; opensbi at lists.infradead.org
Cc: Chang, Abner (HPS SW/FW Technologist) <[email protected]>; Anup Patel <[email protected]>
Subject: Re: [PATCH v1 2/3] lib: fdt: Don't use sbi_string functions

? 2021-05-17?? 19:33 +0800?Daniel Schaefer???

Quoted 8 lines

When SBI is built by external firmware, we need to use their functions,
defined in libfdt_env.h.
Just like 2cfd2fc9048806353298a1b967abf985901e36e8

Look good to me.

but lost sbi_memcpy in line 340.

Regards
Xiang W

Quoted 51 lines
---
 lib/utils/fdt/fdt_domain.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
lib/utils/fdt/fdt_domain.c +2 -1
index 95c195d65238..c1f6a8c8a10b 100644
@@ -9,6 +9,7 @@
  */
 
 #include <libfdt.h>
+#include <libfdt_env.h>
 #include <sbi/sbi_domain.h>
 #include <sbi/sbi_error.h>
 #include <sbi/sbi_hartmask.h>
@@ -95,7 +96,7 @@ static int __fixup_find_domain_offset(void *fdt,
 int doff, void *p)
 {
 	struct __fixup_find_domain_offset_info *fdo = p;
 
-	if (!sbi_strcmp(fdo->name, fdt_get_name(fdt, doff, NULL)))
+	if (!strcmp(fdo->name, fdt_get_name(fdt, doff, NULL)))
 		*fdo->doffset = doff;
 
lib/utils/fdt/fdt_domain.c +2 -2
 	return 0;
@@ -287,7 +288,7 @@ static int __fdt_parse_domain(void *fdt, int
 domain_offset, void *opaque)
 	regions = &fdt_regions[fdt_domains_count][0];
 
 	/* Read DT node name */
-	sbi_strncpy(dom->name, fdt_get_name(fdt, domain_offset, NULL),
+	strncpy(dom->name, fdt_get_name(fdt, domain_offset, NULL),
 		    sizeof(dom->name));
 	dom->name[sizeof(dom->name) - 1] = '\0';
@@ -313,7 +314,7 @@ static int __fdt_parse_domain(void *fdt, int
 domain_offset, void *opaque)
 
 	/* Setup memregions from DT */
 	val32 = 0;
-	sbi_memset(regions, 0,
+	memset(regions, 0,
 		   sizeof(*regions) * (FDT_DOMAIN_REGION_MAX_COUNT +
 1));
lib/utils/fdt/fdt_domain.c +0 -1
 	dom->regions = regions;
 	err = fdt_iterate_each_memregion(fdt, domain_offset, &val32,
--

2.30.1

#7 lore raw

PATCH 2/3 lib: fdt: Don't use sbi_string functions

In reply to Xiang W
Quoted 6 lines · Xiang W

? 2021-05-17?? 19:33 +0800?Daniel Schaefer???

Quoted 5 lines

When SBI is built by external firmware, we need to use their functions,
defined in libfdt_env.h.
Just like 2cfd2fc9048806353298a1b967abf985901e36e8

Quoted 6 lines
Quoted 3 lines

Look good to me.

but lost sbi_memcpy in line 340.

Oh, good catch, thanks! I had made the changes based on v0.9 originally. I'll send out another series.

Quoted 54 lines

Regards
Xiang W

Quoted 51 lines
---
 lib/utils/fdt/fdt_domain.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
lib/utils/fdt/fdt_domain.c +2 -1
index 95c195d65238..c1f6a8c8a10b 100644
@@ -9,6 +9,7 @@
  */
 
 #include <libfdt.h>
+#include <libfdt_env.h>
 #include <sbi/sbi_domain.h>
 #include <sbi/sbi_error.h>
 #include <sbi/sbi_hartmask.h>
@@ -95,7 +96,7 @@ static int __fixup_find_domain_offset(void *fdt,
 int doff, void *p)
 {
 	struct __fixup_find_domain_offset_info *fdo = p;
 
-	if (!sbi_strcmp(fdo->name, fdt_get_name(fdt, doff, NULL)))
+	if (!strcmp(fdo->name, fdt_get_name(fdt, doff, NULL)))
 		*fdo->doffset = doff;
 
lib/utils/fdt/fdt_domain.c +2 -2
 	return 0;
@@ -287,7 +288,7 @@ static int __fdt_parse_domain(void *fdt, int
 domain_offset, void *opaque)
 	regions = &fdt_regions[fdt_domains_count][0];
 
 	/* Read DT node name */
-	sbi_strncpy(dom->name, fdt_get_name(fdt, domain_offset, NULL),
+	strncpy(dom->name, fdt_get_name(fdt, domain_offset, NULL),
 		    sizeof(dom->name));
 	dom->name[sizeof(dom->name) - 1] = '\0';
@@ -313,7 +314,7 @@ static int __fdt_parse_domain(void *fdt, int
 domain_offset, void *opaque)
 
 	/* Setup memregions from DT */
 	val32 = 0;
-	sbi_memset(regions, 0,
+	memset(regions, 0,
 		   sizeof(*regions) * (FDT_DOMAIN_REGION_MAX_COUNT +
 1));
lib/utils/fdt/fdt_domain.c +0 -0
 	dom->regions = regions;
 	err = fdt_iterate_each_memregion(fdt, domain_offset, &val32,
Signature · 1 line
2.30.1
#8 lore raw

PATCH 3/3 lib: utils: Replace strcmp with strcmp

In reply to Daniel Schaefer
---
 lib/utils/fdt/fdt_domain.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/utils/fdt/fdt_domain.c +1 -1
index c1f6a8c8a10b..a9ebbdca3c52 100644
@@ -96,7 +96,7 @@ static int __fixup_find_domain_offset(void *fdt, int doff, void *p)
 {
 	struct __fixup_find_domain_offset_info *fdo = p;
 
-	if (!strcmp(fdo->name, fdt_get_name(fdt, doff, NULL)))
+	if (!strncmp(fdo->name, fdt_get_name(fdt, doff, NULL), strlen(fdo->name)))
 		*fdo->doffset = doff;
 
 	return 0;
Signature · 1 line
2.30.1
#9 lore raw

PATCH 3/3 lib: utils: Replace strcmp with strcmp

s/strcmp with strcmp/strcmp with strncmp/

Andreas.

Signature · 3 lines
Andreas Schwab, schwab at linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."
#10 lore raw

PATCH 3/3 lib: utils: Replace strcmp with strcmp

In reply to Daniel Schaefer

? 2021-05-17?? 19:33 +0800?Daniel Schaefer???

Quoted 3 lines

Look good to me.

Quoted 23 lines
---
 lib/utils/fdt/fdt_domain.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/utils/fdt/fdt_domain.c +1 -1
index c1f6a8c8a10b..a9ebbdca3c52 100644
@@ -96,7 +96,7 @@ static int __fixup_find_domain_offset(void *fdt,
 int doff, void *p)
 {
 	struct __fixup_find_domain_offset_info *fdo = p;
 
-	if (!strcmp(fdo->name, fdt_get_name(fdt, doff, NULL)))
+	if (!strncmp(fdo->name, fdt_get_name(fdt, doff, NULL),
 strlen(fdo->name)))
 		*fdo->doffset = doff;

return 0;

Signature · 1 line
2.30.1
#11 lore raw

PATCH 3/3 lib: utils: Replace strcmp with strcmp

Quoted 38 lines

-----Original Message-----
From: Xiang W [mailto:wxjstz at 126.com]
Sent: Monday, May 17, 2021 9:58 PM
To: Schaefer, Daniel <[email protected]>; opensbi at lists.infradead.org
Cc: Chang, Abner (HPS SW/FW Technologist) <[email protected]>; Anup Patel <[email protected]>
Subject: Re: [PATCH v1 3/3] lib: utils: Replace strcmp with strcmp

? 2021-05-17?? 19:33 +0800?Daniel Schaefer???

Quoted 3 lines

Look good to me.

Quoted 23 lines
---
 lib/utils/fdt/fdt_domain.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/utils/fdt/fdt_domain.c +1 -1
index c1f6a8c8a10b..a9ebbdca3c52 100644
@@ -96,7 +96,7 @@ static int __fixup_find_domain_offset(void *fdt,
 int doff, void *p)
 {
 	struct __fixup_find_domain_offset_info *fdo = p;
 
-	if (!strcmp(fdo->name, fdt_get_name(fdt, doff, NULL)))
+	if (!strncmp(fdo->name, fdt_get_name(fdt, doff, NULL),
 strlen(fdo->name)))
 		*fdo->doffset = doff;

return 0;
--
2.30.1

#12 lore raw

cover Don't use SBI functions in fdt code

In reply to Daniel Schaefer

Hi Daniel,

Quoted 15 lines · Daniel Schaefer

My previous solution to build v0.9 in EDK2 wasn't correct:
http://lists.infradead.org/pipermail/opensbi/2021-May/000982.html

Abner reminded me that he had done a similar change before. It was to not use SBI functions in the FDT files but instead call those from libfdt_env.h.

See:
2cfd2fc9048806353298a1b967abf985901e36e8
2845d2d2cf4fb74a89452ba223995aa4a118c07e
8e47649eff96c303e02fbd58cdc6c4ed341066ec

Doing the same kinds of changes again, solves the issue.

Quoted 7 lines
Cc Abner Chang <[email protected]>
Cc Anup Patel <[email protected]>

Daniel Schaefer (3):
lib: utils: Add macro to libfdt_env.h for strncpy
lib: fdt: Don't use sbi_string functions
lib: utils: Replace strcmp with strcmp

You would be sending a v2 with comments addressed. Right ??

Quoted 5 lines
 lib/utils/fdt/fdt_domain.c    | 7 ++++---
 lib/utils/libfdt/libfdt_env.h | 1 +
 2 files changed, 5 insertions(+), 3 deletions(-)
Quoted 8 lines

--
2.30.1

--
opensbi mailing list
opensbi at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi

Regards,
Anup