[Feature][T106]ZXW P56U09 code
Only Configure: Yes
Affected branch: master
Affected module: unknow
Is it affected on both ZXIC and MTK: only ZXIC
Self-test: No
Doc Update: No
Change-Id: I3cbd8b420271eb20c2b40ebe5c78f83059cd42f3
diff --git a/ap/lib/libdebug_info/debug_info.c b/ap/lib/libdebug_info/debug_info.c
new file mode 100755
index 0000000..03fe2b8
--- /dev/null
+++ b/ap/lib/libdebug_info/debug_info.c
@@ -0,0 +1,77 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <stdarg.h>
+
+#include "pub_debug_info.h"
+
+#define DEBUG_INFO_MAX_TOTAL_LEN (140)
+//#define DEBUG_INFO_MAX_DATA_LEN (128)
+//#define DEBUG_INFO_MEM_HEAD_LEN (8)
+
+ssize_t safe_write(int fd, const void *buf, size_t count)
+{
+ ssize_t n;
+
+ for (;;) {
+ n = write(fd, buf, count);
+ if (n >= 0 || errno != EINTR)
+ break;
+ /* Some callers set errno=0, are upset when they see EINTR.
+ * Returning EINTR is wrong since we retry write(),
+ * the "error" was transient.
+ */
+ errno = 0;
+ /* repeat the write() */
+ }
+
+ return n;
+}
+int sc_debug_info_record(char *id, const char *format, ...)
+{
+ int fd = -1;
+ ssize_t writelen;
+ int len;
+ va_list args;
+ char str_buf[DEBUG_INFO_MAX_TOTAL_LEN] __attribute__((aligned(4)));
+ char *ptmpstr = str_buf;
+
+ /* args是一个char*类型指针,指向format之后的第一个参数*/
+ if( id == NULL)
+ return -1;
+
+ len = snprintf((char *)ptmpstr, DEBUG_INFO_MAX_TOTAL_LEN, "[%s]",id);
+ ptmpstr += len;
+ va_start(args, format);
+ len += vsnprintf(ptmpstr, DEBUG_INFO_MAX_TOTAL_LEN - len, format, args);
+ va_end(args);
+ if (len < 0)
+ {
+ printf("[libdebug_info]: vsnprintf format error, %s.\n", strerror(errno));
+ return -1;
+ }
+
+ fd = open(DEBUG_INFO_DEV_PATH, O_WRONLY);
+ if (fd < 0)
+ {
+ printf("[libdebug_info]: sc_debug_info_record, open debug_info error, %s\n", strerror(errno));
+ return -1;
+ }
+
+ writelen = safe_write(fd, (char *)str_buf, len);
+ if (writelen < 0)
+ {
+ printf("[libdebug_info]: sc_debug_info_record, write debug_info error, %s\n", strerror(errno));
+ return -1;
+ }
+
+ if (fd >= 0)
+ {
+ close(fd);
+ }
+
+ return writelen;
+}