[meta-intel] [PATCH 3/3] rmc: add database extraction functionality

2017-02-02 Thread Todor Minchev
The contents of an existing database file can be extracted in the
current working directory with the -E option. The top level of the
directory tree is rmc_db_dump and all files corresponding to
a given record will be saved in a separate sub-directory. The sub-directory
name of each record is the signature corresponding to the fingerprint for
that record.

Example:
./src/rmc -E -d rmc.db

Successfully extracted rmc.db

Signed-off-by: Todor Minchev 
---
 inc/rmc_api.h |  9 ++
 src/lib/api.c | 85 +--
 src/lib/common/rmcl.c |  3 +-
 src/rmc.c | 44 +++---
 4 files changed, 126 insertions(+), 15 deletions(-)

diff --git a/inc/rmc_api.h b/inc/rmc_api.h
index a484389..ce26220 100644
--- a/inc/rmc_api.h
+++ b/inc/rmc_api.h
@@ -74,6 +74,15 @@ extern int rmc_query_file_by_fp(rmc_fingerprint_t *fp, char 
*db_pathname, char *
  */
 extern int rmc_gimme_file(char* db_pathname, char *file_name, rmc_file_t 
*file);
 
+
+/* extract the contents of a database file and store the files corresponding to
+ * each record in a separate directory. The name of each directory is the 
signature
+ * of the fingerpring for that record
+ * (in) db_pathname: The path and file name of a RMC database file generated 
by RMC tool
+ * return: 0 on success, non-zero on failure.
+ */
+int dump_db(char *db_pathname) ;
+
 /* 1.3 - Helper APIs */
 
 /* Free allocated data referred in a fingerprint
diff --git a/src/lib/api.c b/src/lib/api.c
index 0adb390..aca8d99 100644
--- a/src/lib/api.c
+++ b/src/lib/api.c
@@ -3,6 +3,7 @@
  * RMC API implementation for Linux user space
  */
 
+#define _GNU_SOURCE
 #include 
 #include 
 #include 
@@ -14,8 +15,11 @@
 #include 
 #include 
 
-#define EFI_SYSTAB_PATH "/sys/firmware/efi/systab"
-#define SYSTAB_LEN 4096 /* assume 4kb is enough...*/
+#define EFI_SYSTAB_PATH  "/sys/firmware/efi/systab"
+#define SYSTAB_LEN   4096 /* assume 4kb is enough...*/
+#define DB_DUMP_DIR  "./rmc_db_dump"  /* directory to store db data dump */
+
+extern const rmc_uint8_t rmc_db_signature[RMC_DB_SIG_LEN];
 
 int read_file(const char *pathname, char **data, rmc_size_t* len) {
 int fd = -1;
@@ -325,3 +329,80 @@ int rmc_gimme_file(char* db_pathname, char *file_name, 
rmc_file_t *file) {
 
 return ret;
 }
+
+/*
+ * Dump contents of database file
+ * (in) rmc_db - input database file to extract
+ */
+int dump_db(char *db_pathname) {
+rmc_meta_header_t meta_header;
+rmc_db_header_t *db_header = NULL;
+rmc_record_header_t record_header;
+rmc_uint64_t record_idx = 0;   /* offset of each reacord in db*/
+rmc_uint64_t meta_idx = 0; /* offset of each meta in a record */
+rmc_uint64_t file_idx = 0; /* offset of file in a meta */
+rmc_file_t file;
+char *out_dir = NULL, *out_name = NULL;
+rmc_size_t db_len = 0;
+rmc_uint8_t *rmc_db = NULL;
+struct stat s = {0};
+
+if (read_file(db_pathname, (char **)_db, _len)) {
+fprintf(stderr, "Failed to read database file\n\n");
+return 1;
+}
+
+db_header = (rmc_db_header_t *)rmc_db;
+
+/* sanity check of db */
+if (strncmp((const char *)db_header->signature,
+(const char *)rmc_db_signature, RMC_DB_SIG_LEN))
+return 1;
+
+/* create the top level directory */
+if (stat(DB_DUMP_DIR, ) == -1) {
+if(mkdir(DB_DUMP_DIR, 0755)) {
+fprintf(stderr, "Failed to create %s directory\n\n", out_name);
+}
+}
+
+/* query the meta. idx: start of record */
+record_idx = sizeof(rmc_db_header_t);
+while (record_idx < db_header->length) {
+memcpy(_header, rmc_db + record_idx,
+sizeof(rmc_record_header_t));
+
+/* directory name is fingerprint signature */
+asprintf(_dir, "%s/%s/", DB_DUMP_DIR, record_header.signature.raw);
+if (stat(out_dir, ) == -1) {
+if(mkdir(out_dir, 0755)) {
+fprintf(stderr, "Failed to create %s directory\n\n", out_name);
+}
+}
+
+/* find meta */
+for (meta_idx = record_idx + sizeof(rmc_record_header_t);
+meta_idx < record_idx + record_header.length;) {
+memcpy(_header, rmc_db + meta_idx, sizeof(rmc_meta_header_t));
+file_idx = meta_idx + sizeof(rmc_meta_header_t);
+rmc_ssize_t name_len = strlen((char *)_db[file_idx]) + 1;
+file.blob = _db[file_idx + name_len];
+file.blob_len = meta_header.length - sizeof(rmc_meta_header_t) -
+name_len;
+file.next = NULL;
+file.type = RMC_GENERIC_FILE;
+asprintf(_name, "%s%s", out_dir, (char *)_db[file_idx]);
+/* write file to dump directory */
+if (write_file((const char *)out_name, file.blob, file.blob_len, 
0))
+return 1;
+
+/* next meta */
+meta_idx += 

[meta-intel] [PATCH 2/3] rmc: Enable reading the contents of an existing fingerprint file

2017-02-02 Thread Todor Minchev
The contents of an existing fingerprint file can be read and output on
the command line with the following options:

./rmc -F -i input_fingerprint_file

Signed-off-by: Todor Minchev 
---
 src/rmc.c | 121 +++---
 1 file changed, 76 insertions(+), 45 deletions(-)

diff --git a/src/rmc.c b/src/rmc.c
index 062dd36..a051ccf 100644
--- a/src/rmc.c
+++ b/src/rmc.c
@@ -14,33 +14,35 @@
 #include 
 
 #define USAGE "RMC (Runtime Machine configuration) Tool\n" \
-"NOTE: Most of usages require root permission (sudo)\n" \
-"rmc -F [-o output_fingerprint]\n" \
+"NOTE: Most of usages require root permission (sudo)\n\n" \
+"rmc -F [-o output_fingerprint] | -i input_fingerprint\n" \
 "rmc -R [-f ] -b  [-o output_record]\n" \
 "rmc -D  [-o output_database]\n" \
-   "rmc -B  -d  -o output_file\n" \
-   "\n" \
-   "-F: generate board rmc fingerprint of board\n" \
-   "-R: generate board rmc record of board with its fingerprint and file 
blobs.\n" \
-"-f: fingerprint file to be packed in record, rmc will create a 
fingerprint for board and use it internally to\n" \
-"generate record if -f is missed.\n" \
-"-b: files to be packed in record\n" \
-   "-G: generate rmc database file with records specified in record file 
list\n" \
-   "-B: get a flie blob with specified name associated to the board rmc is 
running on\n" \
-   "-d: database file to be queried\n" \
-   "-o: path and name of output file of a specific command\n" \
-   "\n" \
-"Examples (Steps in an order to add board support into rmc):\n" \
-"generate board fingerprint:\n" \
-"rmc -F\n\n" \
-"generate a rmc record for the board with two file blobs, output to:\n" \
-"a specified file:\n" \
-"rmc -R -f fingerprint -b file_1 file_2 -o my_board.record\n\n" \
-"generate a rmc database file with records from 3 different boards:\n" \
-"rmc -D board1_record board2_record board3_record\n\n" \
-"query a file blob named audio.conf associated to the board rmc is running 
on in database my_rmc.db and output\n" \
-"to /tmp/new_audio.conf:\n" \
-"rmc -B audio.conf -d my_rmc.db -o /tmp/new_audio.conf\n\n"
+"rmc -B  -d  -o output_file\n\n" \
+  "-F: manage fingerprint file\n" \
+"\t-o output_file: store RMC fingerprint of current board in 
output_file\n" \
+"\t-i input_file: print RMC fingerprint stored in input_file\n\n" \
+  "-R: generate board rmc record of board with its fingerprint and file 
blobs.\n" \
+"\t-f intput_file : input fingerprint file to be packed in record\n\n" \
+"\tNOTE: RMC will create a fingerprint for the board and use it to\n" \
+"\tgenerate record if an input fingerprint file is not provided.\n\n" \
+"\t-b: files to be packed in record\n\n" \
+  "-G: generate rmc database file with records specified in record file 
list\n\n" \
+  "-B: get a file blob with specified name associated to the board rmc is\n" \
+  "running on\n" \
+"\t-d: database file to be queried\n" \
+"\t-o: path and name of output file of a specific command\n\n" \
+"Examples (Steps in an order to add board support into rmc):\n\n" \
+"1. Generate board fingerprint:\n" \
+"\t./rmc -F\n\n" \
+"2. Generate a rmc record for the board with two file blobs and save it\n" 
\
+"to a specified file:\n" \
+"\t./rmc -R -f fingerprint -b file_1 file_2 -o my_board.record\n\n" \
+"3. Generate a rmc database file with records from 3 different boards:\n" \
+"\t./rmc -D board1_record board2_record board3_record\n\n" \
+"4. Query a file blob named audio.conf associated to the board rmc is\n" \
+"running on in database my_rmc.db and output to /tmp/new_audio.conf:\n" \
+"\t./rmc -B audio.conf -d my_rmc.db -o /tmp/new_audio.conf\n\n"
 
 
 #define RMC_OPT_CAP_F   (1 << 0)
@@ -51,6 +53,7 @@
 #define RMC_OPT_O   (1 << 5)
 #define RMC_OPT_B   (1 << 6)
 #define RMC_OPT_D   (1 << 7)
+#define RMC_OPT_I   (1 << 8)
 
 static void usage () {
 fprintf(stdout, USAGE);
@@ -78,7 +81,7 @@ static void dump_fingerprint(rmc_fingerprint_t *fp) {
 static int write_fingerprint_file(const char* pathname, rmc_fingerprint_t *fp) 
{
 int i;
 int first = 0;
-
+/* TODO - do we need to open/close file multiple times to write each field 
*/
 for (i = 0; i < RMC_FINGER_NUM; i++) {
 if (write_file(pathname, >rmc_fingers[i].type, 
sizeof(fp->rmc_fingers[i].type), first))
 return 1;
@@ -214,7 +217,6 @@ read_fp_done:
 static rmc_file_t *read_policy_file(char *pathname, int type) {
 rmc_file_t *tmp = NULL;
 rmc_size_t policy_len = 0;
-int ret;
 char *path_token;
 
 if ((tmp = calloc(1, sizeof(rmc_file_t))) == NULL) {
@@ -226,8 +228,7 @@ static rmc_file_t *read_policy_file(char *pathname, int 
type) {
 tmp->next = NULL;
 
 if (type == RMC_GENERIC_FILE) {
-ret = read_file(pathname, 

[meta-intel] [PATCH 1/3] Makefile: add verbosity and debug options to Makefile

2017-02-02 Thread Todor Minchev
By default Makefile verbosity is disabled (V=0). Verbosity can be enabled by
setting the V environment variable to any value not equal to 0 (e.g V=1)

Example:
make clean V=1; make V=1

A debug version of the rmc binary can be built by using the debug
Makefile target. This will include debug symbols and will disable compiler
optimizations when compiling rmc.

Example:

make debug

Signed-off-by: Todor Minchev 
---
 Makefile | 31 +--
 1 file changed, 21 insertions(+), 10 deletions(-)

diff --git a/Makefile b/Makefile
index 9ade775..d85d8e9 100644
--- a/Makefile
+++ b/Makefile
@@ -1,5 +1,12 @@
 # Copyright (C) 2016 Jianxun Zhang 
 
+V ?= 0
+ifeq ($(V),0)
+  VERBOSITY = @
+else
+  VERBOSITY =
+endif
+
 TOPDIR = $(shell if [ -z "$$PWD" ]; then pwd; else echo "$$PWD"; fi)
 
 RMC_TOOL_SRC := $(wildcard src/*.c)
@@ -20,28 +27,32 @@ RMC_INSTALL_HEADER_PATH := 
$(RMC_INSTALL_PREFIX)/include/rmc/
 
 ALL_OBJS := $(RMC_TOOL_OBJ) $(RMC_LIB_OBJ)
 
+
 RMC_CFLAGS := -Wall -I$(TOPDIR)/inc
 
 all: rmc
+debug: RMC_CFLAGS += -DDEBUG -g -O0
+debug: rmc
 
 $(ALL_OBJS): %.o: %.c
-   @$(CC) -c $(CFLAGS) $(RMC_CFLAGS) $< -o $@
+   $(VERBOSITY)$(CC) -c $(CFLAGS) $(RMC_CFLAGS) $< -o $@
 
 librmc: $(RMC_LIB_OBJ)
-   @$(AR) rcs src/lib/$@.a $^
+   $(VERBOSITY)$(AR) rcs src/lib/$@.a $^
 
 rmc: $(RMC_TOOL_OBJ) librmc
-   @$(CC) $(CFLAGS) $(RMC_CFLAGS) -Lsrc/lib/ -lrmc $(RMC_TOOL_OBJ) 
src/lib/librmc.a -o src/$@
+   $(VERBOSITY)$(CC) $(CFLAGS) $(RMC_CFLAGS) -Lsrc/lib/ -lrmc 
$(RMC_TOOL_OBJ) \
+  src/lib/librmc.a -o src/$@
 
 clean:
-   @rm -f $(ALL_OBJS) src/rmc src/lib/librmc.a
+   $(VERBOSITY)rm -f $(ALL_OBJS) src/rmc src/lib/librmc.a
 
 .PHONY: clean rmc librmc
 
 install:
-   @mkdir -p $(RMC_INSTALL_BIN_PATH)
-   @install -m 755 src/rmc $(RMC_INSTALL_BIN_PATH)
-   @mkdir -p $(RMC_INSTALL_LIB_PATH)
-   @install -m 644 src/lib/librmc.a $(RMC_INSTALL_LIB_PATH)
-   @mkdir -p $(RMC_INSTALL_HEADER_PATH)
-   @install -m 644 $(RMC_INSTALL_HEADERS) $(RMC_INSTALL_HEADER_PATH)
+   $(VERBOSITY)mkdir -p $(RMC_INSTALL_BIN_PATH)
+   $(VERBOSITY)install -m 755 src/rmc $(RMC_INSTALL_BIN_PATH)
+   $(VERBOSITY)mkdir -p $(RMC_INSTALL_LIB_PATH)
+   $(VERBOSITY)install -m 644 src/lib/librmc.a $(RMC_INSTALL_LIB_PATH)
+   $(VERBOSITY)mkdir -p $(RMC_INSTALL_HEADER_PATH)
+   $(VERBOSITY)install -m 644 $(RMC_INSTALL_HEADERS) 
$(RMC_INSTALL_HEADER_PATH)
-- 
2.11.0

-- 
___
meta-intel mailing list
meta-intel@yoctoproject.org
https://lists.yoctoproject.org/listinfo/meta-intel


[meta-intel] [PATCH 0/3] [yocto][rmc] Add fingerprint quering and database extraction functionality to RMC

2017-02-02 Thread Todor Minchev
This patchset adds database extraction and fingerprint quering
functionality to RMC

Example:

Output fingerprint contents to terminal:

./rmc -F -i rmc.fingerprint

Extract RMC database:

./rmc -E -d rmc.db

https://bugzilla.yoctoproject.org/show_bug.cgi?id=10092

Todor Minchev (3):
  Makefile: add verbosity and debug options to Makefile
  rmc: Enable reading the contents of an existing fingerprint file
  rmc: add database extraction functionality

 Makefile  |  31 ++
 inc/rmc_api.h |   9 +++
 src/lib/api.c |  85 ++-
 src/lib/common/rmcl.c |   3 +-
 src/rmc.c | 157 +-
 5 files changed, 219 insertions(+), 66 deletions(-)

-- 
2.11.0

-- 
___
meta-intel mailing list
meta-intel@yoctoproject.org
https://lists.yoctoproject.org/listinfo/meta-intel


Re: [meta-intel] [PATCH 1/2] systemd-boot: use RMC database in EFI stub

2017-02-02 Thread Ylinen, Mikko
Hi,

On Fri, Jan 27, 2017 at 6:05 PM, Wold, Saul  wrote:

> On Fri, 2017-01-27 at 15:36 +0200, Mikko Ylinen wrote:
> > systemd-boot's EFI stub can be built in an EFI executable
> > with the kernel, cmdline, and initrd.
> >
> > This commit enables the EFI stub code to use the RMC database
> > and appends the board specific cmdline (KBOOTPARAM) to the
> > built-in cmdline.
> >
> If we are going to expose the KBOOTPARAM this way, shouldn't that be
> done inside of RMC proper and a getter type of API to provide
> KBOOTPARAM directly?


Makes a lot of sense to me. However, until that API is in place, I'd suggest
we use what I'm proposing for the stub here (that's the same approach used
with
the full bootloader as well).

-- Mikko
-- 
___
meta-intel mailing list
meta-intel@yoctoproject.org
https://lists.yoctoproject.org/listinfo/meta-intel


[meta-intel] [PATCH] intel-quark: Add intel-quark-preempt-rt bsp configuration

2017-02-02 Thread Jan Kiszka
From: Christian Storm 

While there are intel-quark configurations for the KTYPEs standard and
tiny in bsp/intel-common, there's none for the preempt-rt KTYPE.
Trying to build preempt-rt enabled kernels such as linux-yocto-rt for
intel-quark yields a .config having a potentially misconfigured
architecture. More importantly, however, preempt-rt related CONFIG
options are not enabled. Hence, a build of, e.g., linux-yocto-rt, does
not result in a preempt-rt enabled kernel.

This patch qualifies to be (back)ported to other branches than master.

Signed-off-by: Christian Storm 
Signed-off-by: Jan Kiszka 
---

In particular, we would be interested in a 4.4 application as that is
currently in use by meta-iot2000.

 bsp/intel-common/intel-quark-preempt-rt.scc | 20 
 1 file changed, 20 insertions(+)
 create mode 100644 bsp/intel-common/intel-quark-preempt-rt.scc

diff --git a/bsp/intel-common/intel-quark-preempt-rt.scc 
b/bsp/intel-common/intel-quark-preempt-rt.scc
new file mode 100644
index ..8a00fae4
--- /dev/null
+++ b/bsp/intel-common/intel-quark-preempt-rt.scc
@@ -0,0 +1,20 @@
+# intel-quark-preempt-rt.scc
+#
+# preempt-rt ktype for 32 bit Quark / X1000 CPUs
+#
+
+define KMACHINE intel-quark
+define KARCH i386
+define KTYPE preempt-rt
+
+include ktypes/preempt-rt/preempt-rt.scc
+branch intel
+
+# Enable booting from USB for Standard Kernel Image
+include cfg/usb-mass-storage.scc
+include cfg/boot-live.scc
+
+include intel-common.scc
+include features/power/intel.scc
+include intel-common-drivers-32.scc
+include intel-quark.scc
-- 
2.11.0

-- 
___
meta-intel mailing list
meta-intel@yoctoproject.org
https://lists.yoctoproject.org/listinfo/meta-intel