summaryrefslogtreecommitdiff
path: root/extra
diff options
context:
space:
mode:
authorEric Caruso <ejcaruso@chromium.org>2014-09-17 16:52:31 -0700
committerchrome-internal-fetch <chrome-internal-fetch@google.com>2014-09-25 07:59:16 +0000
commitfb5ff7b1bb59174ea140d18cb84ce1d6599337c1 (patch)
tree9e78996ca8d6fbe6c51cf272b94e5b5e00727f2b /extra
parent2939b986cfc4fc3f8b46b37b4d345bec270418ca (diff)
downloadchrome-ec-fb5ff7b1bb59174ea140d18cb84ce1d6599337c1.tar.gz
lightbar: add seq type PROGRAM for user-programmable sequences
This diff allows the user to send small programs to the EC and gain control of the lightbar. Right now, this is only exposed through ectool, and sysfs support will come later. To send a program to the EC, use $ ectool lightbar program /path/to/program.bin and then start running the program with $ ectool lightbar seq program BUG=None BRANCH=ToT TEST=Using the above steps with hand-assembled programs. Checked that infinite bytecode loops do not hang the EC. Checked that bad opcodes exit with an error. Stress tested pushing programs and changing sequences. Signed-off-by: Eric Caruso <ejcaruso@chromium.org> Change-Id: I635fb041a5dc5c403f7c26fb9a41b5563be9b6b7 Reviewed-on: https://chromium-review.googlesource.com/219558 Reviewed-by: Bill Richardson <wfrichar@chromium.org> Reviewed-by: Randall Spangler <rspangler@chromium.org>
Diffstat (limited to 'extra')
-rw-r--r--extra/lightbar/main.c37
-rw-r--r--extra/lightbar/simulation.h1
2 files changed, 38 insertions, 0 deletions
diff --git a/extra/lightbar/main.c b/extra/lightbar/main.c
index 38234e743c..6014719f0b 100644
--- a/extra/lightbar/main.c
+++ b/extra/lightbar/main.c
@@ -290,3 +290,40 @@ done:
fclose(fp);
return r;
}
+
+int lb_load_program(const char *filename, struct lb_program *prog)
+{
+ FILE *fp;
+ size_t got;
+ int rc;
+
+ fp = fopen(filename, "rb");
+ if (!fp) {
+ fprintf(stderr, "Can't open %s: %s\n",
+ filename, strerror(errno));
+ return 1;
+ }
+
+ rc = fseek(fp, 0, SEEK_END);
+ if (rc) {
+ fprintf(stderr, "Couldn't find end of file %s",
+ filename);
+ fclose(fp);
+ return 1;
+ }
+ rc = (int) ftell(fp);
+ if (rc > LB_PROG_LEN) {
+ fprintf(stderr, "File %s is too long, aborting\n", filename);
+ fclose(fp);
+ return 1;
+ }
+ rewind(fp);
+
+ memset(prog->data, 0, LB_PROG_LEN);
+ got = fread(prog->data, 1, LB_PROG_LEN, fp);
+ if (rc != got)
+ fprintf(stderr, "Warning: did not read entire file\n");
+ prog->size = got;
+ fclose(fp);
+ return 0;
+}
diff --git a/extra/lightbar/simulation.h b/extra/lightbar/simulation.h
index 569107023b..2abfae230b 100644
--- a/extra/lightbar/simulation.h
+++ b/extra/lightbar/simulation.h
@@ -23,6 +23,7 @@ void *entry_lightbar(void *);
void init_windows(void);
int lb_read_params_from_file(const char *filename,
struct lightbar_params_v1 *p);
+int lb_load_program(const char *filename, struct lb_program *prog);
/* Interfaces to the EC code that we're encapsulating */
void lightbar_task(void);
int fake_consolecmd_lightbar(int argc, char *argv[]);