Skip to contentSkip to conversation

API: Use stack pointer as API signature search hint in the glue layer.

PATCH New Rafal Jaworowski 2 participants 8 messages Jan 23, 2009 – Feb 17, 2009

lore
Share & tools
lore
#0 lore raw

PATCH 1/4 API: Use stack pointer as API signature search hint in the glue layer.

De-hardcode range in RAM we search for the API signature. Instead use the stack pointer as a hint to narrow down the range in which the signature could reside (it is malloc'ed on the U-Boot heap, and is hoped to remain in some proximity from stack area). Adjust PowerPC code in API demo to the new scheme.

---
 api_examples/crt0.S |   14 ++++++++++----
 api_examples/glue.c |   11 +++++++++--
 api_examples/glue.h |    8 ++++----
 3 files changed, 23 insertions(+), 10 deletions(-)
api_examples/crt0.S +10 -4
index 8d4f706..3129a07 100644
@@ -29,6 +29,9 @@
 
 	.globl _start
 _start:
+	lis	%r11, search_hint at ha
+	addi	%r11, %r11, search_hint at l
+	stw	%r1, 0(%r11)
 	b	main
 
 
@@ -39,12 +42,15 @@ syscall:
 	lwz	%r11, 0(%r11)
 	mtctr	%r11
 	bctr
-
+#else
+#error No support for this arch!
+#endif
 
 	.globl syscall_ptr
 syscall_ptr:
 	.align	4
 	.long	0
-#else
-#error No support for this arch!
-#endif
+
+	.globl search_hint
+search_hint:
+	.long   0
api_examples/glue.c +9 -2
index 2bf47ae..200b163 100644
@@ -60,13 +60,20 @@ static int valid_sig(struct api_signature *sig)
 int api_search_sig(struct api_signature **sig) {
 
 	unsigned char *sp;
+	uint32_t search_start = 0;
+	uint32_t search_end = 0;
 
 	if (sig == NULL)
 		return 0;
 
-	sp = (unsigned char *)API_SEARCH_START;
+	if (search_hint == 0)
+		search_hint = 255 * 1024 * 1024;
 
-	while ((sp + (int)API_SIG_MAGLEN) < (unsigned char *)API_SEARCH_END) {
+	search_start = search_hint & ~0x000fffff;
+	search_end = search_start + API_SEARCH_LEN - API_SIG_MAGLEN;
+
+	sp = (unsigned char *)search_start;
+	while ((sp + API_SIG_MAGLEN) < (unsigned char *)search_end) {
 		if (!memcmp(sp, API_SIG_MAGIC, API_SIG_MAGLEN)) {
 			*sig = (struct api_signature *)sp;
 			if (valid_sig(*sig))
api_examples/glue.h +4 -4
index a82f783..0adb8b3 100644
@@ -30,12 +30,12 @@
 #ifndef _API_GLUE_H_
 #define _API_GLUE_H_
 
-#define API_SEARCH_START	(255 * 1024 * 1024)	/* start@1MB below top RAM */
-#define API_SEARCH_END		(256 * 1024 * 1024 - 1)	/* ...and search to the end */
+#define API_SEARCH_LEN		(3 * 1024 * 1024)	/* 3MB search range */
 
-int	syscall(int, int *, ...);
-void *	syscall_ptr;
+extern void *syscall_ptr;
+extern uint32_t search_hint;
 
+int	syscall(int, int *, ...);
 int	api_search_sig(struct api_signature **sig);
 
 /*
Signature · 1 line
1.5.2.2
#1 lore raw

PATCH 2/4 API: Provide syscall entry point for the ARM architecture.

---
 api_examples/Makefile |    7 +++----
 api_examples/crt0.S   |   17 ++++++++++++++++-
 lib_arm/board.c       |    5 +++++
 3 files changed, 24 insertions(+), 5 deletions(-)
api_examples/Makefile +3 -4
index 5666f48..4c01437 100644
@@ -23,10 +23,9 @@
 ifeq ($(ARCH),ppc)
 LOAD_ADDR = 0x40000
 endif
-
-#ifeq ($(ARCH),arm)
-#LOAD_ADDR = 0xc100000
-#endif
+ifeq ($(ARCH),arm)
+LOAD_ADDR = 0x1000000
+endif
 
 include $(TOPDIR)/config.mk
 
api_examples/crt0.S +16 -1
index 3129a07..6daf127 100644
@@ -26,7 +26,6 @@
 #if defined(CONFIG_PPC)
 
 	.text
-
 	.globl _start
 _start:
 	lis	%r11, search_hint at ha
@@ -42,6 +41,22 @@ syscall:
 	lwz	%r11, 0(%r11)
 	mtctr	%r11
 	bctr
+
+#elif defined(CONFIG_ARM)
+
+	.text
+	.globl _start
+_start:
+	ldr	ip, =search_hint
+	str	sp, [ip]
+	b	main
+
+
+	.globl syscall
+syscall:
+	ldr	ip, =syscall_ptr
+	ldr	pc, [ip]
+
 #else
 #error No support for this arch!
 #endif
lib_arm/board.c +5 -0
index 2358beb..4cb3f2e 100644
@@ -404,6 +404,11 @@ void start_armboot (void)
 
 	jumptable_init ();
 
+#if defined(CONFIG_API)
+	/* Initialize API */
+	api_init ();
+#endif
+
 	console_init_r ();	/* fully init console as a device */
 
 #if defined(CONFIG_MISC_INIT_R)
Signature · 1 line
1.5.2.2
#2 lore raw

PATCH 2/4 API: Provide syscall entry point for the ARM architecture.

Dear Rafal Jaworowski,

Quoted 7 lines · In message <[email protected]> you wrote:
---
 api_examples/Makefile |    7 +++----
 api_examples/crt0.S   |   17 ++++++++++++++++-
 lib_arm/board.c       |    5 +++++
 3 files changed, 24 insertions(+), 5 deletions(-)

Applied, thanks.

Best regards,

Wolfgang Denk

Signature · 4 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
Nothing ever becomes real until it is experienced.       - John Keats
#3 lore raw

PATCH 3/4 API: Only output test data when reading was successful.

In reply to Rafal Jaworowski
---
 api_examples/demo.c |    8 +++++---
 1 files changed, 5 insertions(+), 3 deletions(-)
api_examples/demo.c +5 -3
index 69ac318..2510ed8 100644
@@ -135,9 +135,10 @@ int main(int argc, char *argv[])
 
 		else if ((rv = ub_dev_read(i, buf, 1, 0)) != 0)
 			errf("could not read from device %d, error %d\n", i, rv);
-
-		printf("Sector 0 dump (512B):\n");
-		test_dump_buf(buf, 512);
+		else {
+			printf("Sector 0 dump (512B):\n");
+			test_dump_buf(buf, 512);
+		}
 
 		ub_dev_close(i);
 	}
@@ -178,6 +179,7 @@ int main(int argc, char *argv[])
 		printf("%s = %s\n", env, ub_env_get(env));
 
 	/* reset */
+	printf("\n*** Resetting board ***\n");
 	ub_reset();
 	printf("\nHmm, reset returned...?!\n");
 
Signature · 1 line
1.5.2.2
#4 lore raw

PATCH 3/4 API: Only output test data when reading was successful.

Dear Rafal Jaworowski,

Quoted 4 lines · In message <[email protected]> you wrote:
---
 api_examples/demo.c |    8 +++++---
 1 files changed, 5 insertions(+), 3 deletions(-)

Applied, thanks.

Best regards,

Wolfgang Denk

Signature · 5 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
Keep your head and your heart going in the right  direction  and  you
will not have to worry about your feet.
#5 lore raw

PATCH 4/4 API: Improve glue mid-layer of the API demo application.

In reply to Rafal Jaworowski

- Extend ub_dev_read() and ub_dev_recv() so they return the length actually read, which allows for better control and error handling (this introduces additional error code API_ESYSC returned by the glue mid-layer).

- Clean up definitions naming and usage.

- Other minor cosmetics.

Note these changes do not touch the API proper, so the interface between U-Boot and standalone applications remains unchanged.

---
 api_examples/demo.c  |    8 ++----
 api_examples/glue.c  |   58 +++++++++++++++++++++----------------------------
 api_examples/glue.h  |   16 ++++++++-----
 include/api_public.h |    1 +
 4 files changed, 39 insertions(+), 44 deletions(-)
api_examples/demo.c +3 -5
index 2510ed8..df9c4bd 100644
@@ -43,12 +43,11 @@ static char buf[BUF_SZ];
 
 int main(int argc, char *argv[])
 {
-	int rv = 0;
-	int h, i, j;
-	int devs_no;
+	int rv = 0, h, i, j, devs_no;
 	struct api_signature *sig = NULL;
 	ulong start, now;
 	struct device_info *di;
+	lbasize_t rlen;
 
 	if (!api_search_sig(&sig))
 		return -1;
@@ -96,7 +95,6 @@ int main(int argc, char *argv[])
 	if (devs_no == 0)
 		return -1;
 
-
 	printf("\n*** Show devices ***\n");
 	for (i = 0; i < devs_no; i++) {
 		test_dump_di(i);
@@ -133,7 +131,7 @@ int main(int argc, char *argv[])
 		if ((rv = ub_dev_open(i)) != 0)
 			errf("open device %d error %d\n", i, rv);
 
-		else if ((rv = ub_dev_read(i, buf, 1, 0)) != 0)
+		else if ((rv = ub_dev_read(i, buf, 1, 0, &rlen)) != 0)
 			errf("could not read from device %d, error %d\n", i, rv);
 		else {
 			printf("Sector 0 dump (512B):\n");
api_examples/glue.c +25 -33

162 lines not on this page · raw message

api_examples/glue.h +10 -6
index 0adb8b3..6bf47d0 100644
@@ -32,6 +32,9 @@
 
 #define API_SEARCH_LEN		(3 * 1024 * 1024)	/* 3MB search range */
 
+#define UB_MAX_MR	5	/* max mem regions number */
+#define UB_MAX_DEV	6	/* max devices number */
+
 extern void *syscall_ptr;
 extern uint32_t search_hint;
 
@@ -39,9 +42,10 @@ int	syscall(int, int *, ...);
 int	api_search_sig(struct api_signature **sig);
 
 /*
- * ub_ library calls are part of the application, not U-Boot code!  They are
- * front-end wrappers that are used by the consumer application: they prepare
- * arguments for particular syscall and jump to the low level syscall()
+ * The ub_ library calls are part of the application, not U-Boot code!  They
+ * are front-end wrappers that are used by the consumer application: they
+ * prepare arguments for particular syscall and jump to the low level
+ * syscall()
  */
 
 /* console */
@@ -67,10 +71,10 @@ const char *	ub_env_enum(const char *last);
 int			ub_dev_enum(void);
 int			ub_dev_open(int handle);
 int			ub_dev_close(int handle);
-int			ub_dev_read(int handle, void *buf,
-				lbasize_t len, lbastart_t start);
+int			ub_dev_read(int handle, void *buf, lbasize_t len,
+				lbastart_t start, lbasize_t *rlen);
 int			ub_dev_send(int handle, void *buf, int len);
-int			ub_dev_recv(int handle, void *buf, int len);
+int			ub_dev_recv(int handle, void *buf, int len, int *rlen);
 struct device_info *	ub_dev_get(int);
 
 #endif /* _API_GLUE_H_ */
include/api_public.h +1 -0
index d3164f6..5940d81 100644
@@ -57,6 +57,7 @@
 #define API_ENOMEM		3	/* no memory		*/
 #define API_EBUSY		4	/* busy, occupied etc.	*/
 #define API_EIO			5	/* I/O error		*/
+#define API_ESYSC		6	/* syscall error	*/
 
 typedef	int (*scp_t)(int, int *, ...);
 
Signature · 1 line
1.5.2.2
#6 lore raw

PATCH 4/4 API: Improve glue mid-layer of the API demo application.

Dear Rafal Jaworowski,

Quoted 11 lines · In message <[email protected]> you wrote:

- Extend ub_dev_read() and ub_dev_recv() so they return the length actually read, which allows for better control and error handling (this introduces additional error code API_ESYSC returned by the glue mid-layer).

- Clean up definitions naming and usage.

- Other minor cosmetics.

Note these changes do not touch the API proper, so the interface between U-Boot and standalone applications remains unchanged.

Quoted 7 lines
---
 api_examples/demo.c  |    8 ++----
 api_examples/glue.c  |   58 +++++++++++++++++++++----------------------------
 api_examples/glue.h  |   16 ++++++++-----
 include/api_public.h |    1 +
 4 files changed, 39 insertions(+), 44 deletions(-)

Applied, thanks.

Best regards,

Wolfgang Denk

Signature · 5 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
How long does it take a  DEC  field  service  engineer  to  change  a
lightbulb?       It depends on how many bad ones he brought with him.
#7 lore raw

PATCH 1/4 API: Use stack pointer as API signature search hint in the glue layer.

In reply to Rafal Jaworowski

Dear Rafal Jaworowski,

Quoted 5 lines · In message <[email protected]> you wrote:

De-hardcode range in RAM we search for the API signature. Instead use the stack pointer as a hint to narrow down the range in which the signature could reside (it is malloc'ed on the U-Boot heap, and is hoped to remain in some proximity from stack area). Adjust PowerPC code in API demo to the new scheme.

Quoted 7 lines
---
 api_examples/crt0.S |   14 ++++++++++----
 api_examples/glue.c |   11 +++++++++--
 api_examples/glue.h |    8 ++++----
 3 files changed, 23 insertions(+), 10 deletions(-)

Applied, thanks.

Best regards,

Wolfgang Denk

Signature · 5 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
If the facts don't fit the theory, change the facts.
                                                   -- Albert Einstein