Commit Graph

19 Commits

Author SHA1 Message Date
Dominic Chen
d414c89a61 util: move console command argument parsing to util.c
move parse_offset_size() from flash.c to util.c for SPI flash driver usage

BRANCH=none
BUG=none
TEST=make buildall

Change-Id: Ib4824d2a7e2f5b8c3e4b918d6507c072ded8837d
Signed-off-by: Dominic Chen <ddchen@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/202530
Reviewed-by: Randall Spangler <rspangler@chromium.org>
2014-06-11 00:17:06 +00:00
Daisuke Nojiri
e381585619 Optimize memset
This speeds up memset by copying a word at a time.

Ran the unit test on Peppy:
  > runtest
  ...
  Running test_memset... (speed gain: 141532 -> 32136 us) OK
  ...

Ran make buildall:
  ...
  Running test_memset... (speed gain: 1338 -> 280 us) OK
  ...

TEST=Described above.
BUG=chrome-os-partner:23720
BRANCH=none
Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org>
Change-Id: If34b06ad70f448d950535a4bea4f6556627a9b6f
Tested-by: Daisuke Nojiri <dnojiri@google.com>
Reviewed-on: https://chromium-review.googlesource.com/185936
Reviewed-by: Randall Spangler <rspangler@chromium.org>
Commit-Queue: Daisuke Nojiri <dnojiri@google.com>
2014-03-01 20:15:59 +00:00
Daisuke Nojiri
e7e0cf2cae Optimize memmove
This speeds up memmove by copying a word at a time.

Ran the unit test on Peppy:
  > runtest
  ...
  Running test_memmove... (speed gain: 2156 -> 592 us) OK
  ...

Ran make buildall:
  ...
  Running test_memmove... (speed gain: 143918 -> 32367 us) OK
  ...

TEST=Described above.
BUG=chrome-os-partner:23720
BRANCH=none
Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org>
Tested-by: Daisuke Nojiri <dnojiri@google.com>
Change-Id: I6a3ac6aed27a404c3bef227b6c886a59414b51d7
Reviewed-on: https://chromium-review.googlesource.com/186020
Reviewed-by: Vic Yang <victoryang@chromium.org>
Reviewed-by: Randall Spangler <rspangler@chromium.org>
2014-02-13 20:37:05 +00:00
Daisuke Nojiri
d3facbd92f Optimize memcpy
This speeds up memcpy by copying a word at a time if source and destination are
aligned in mod 4. That is, if n and m are a positive integer:

  4n -> 4m: aligned, 4x speed.
  4n -> 4m+1: misaligned.
  4n+1 -> 4m+1: aligned in mod 4, 4x speed.

Ran the unit test on Peppy:

  > runtest
  ...
  Running test_memcpy... (speed gain: 120300 -> 38103 us) OK
  ...

Ran make buildall -j:

  ...
  Running test_memcpy... (speed gain: 2084 -> 549 us) OK
  ...

Note misaligned case is also optimized. Unit test runs in 298 us on Peppy while
it takes about 475 with the original memcpy.

TEST=Described above.
BUG=chrome-os-partner:23720
BRANCH=none
Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org>
Change-Id: Ic12260451c5efd0896d6353017cd45d29cb672db
Tested-by: Daisuke Nojiri <dnojiri@google.com>
Reviewed-on: https://chromium-review.googlesource.com/185618
Reviewed-by: Randall Spangler <rspangler@chromium.org>
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
Commit-Queue: Daisuke Nojiri <dnojiri@google.com>
2014-02-12 19:40:52 +00:00
Randall Spangler
6ab8e91658 cleanup: Remove checkpatch warnings
This make minor syntactic changes and renames some camel-cased symbols
to keep checkpatch from complaining.  The goal is to reduce the
temptation to use 'repo upload --no-verify'.

This is a big furball of find/replace, but no functional changes.

BUG=chromium:322144
BRANCH=none
TEST=build all boards; pass unit tests

Change-Id: I0269b7dd95836ef9a6e33f88c003ab0f24f842a0
Signed-off-by: Randall Spangler <rspangler@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/180495
2013-12-19 00:12:28 +00:00
Randall Spangler
2dc1418ccd cleanup: Assorted TODO comments
Remove comments if no longer applicable, or assign bug numbers if they
still are.  Tidy some debug output.  No code changes other than the
debug output.

BUG=chrome-os-partner:18343
BRANCH=none
TEST=build all platforms, pass unit tests

Change-Id: I2277e73fbf8cc93f3b1b35ee115e0f2f52eb8cf9
Signed-off-by: Randall Spangler <rspangler@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/175215
Reviewed-by: Bill Richardson <wfrichar@chromium.org>
2013-10-31 18:43:39 +00:00
Vic Yang
eff7a1910a Support multi-bit mask in STM32L's GPIO functions
The definition of GPIO interface allows passing in multi-bit mask, and
this is what's done by gpio_config_module(). Fix STM32L's function so
that it doesn't accidentally set incorrect GPIO register values.

BUG=chrome-os-partner:22605
TEST=On Kirby, do 'led r 0' and check the value of 0x40020800 is
0x01540000.
BRANCH=None

Change-Id: I9a1c8074aab7345485a590ecf138bf99d0742997
Signed-off-by: Vic Yang <victoryang@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/168739
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
Reviewed-by: Randall Spangler <rspangler@chromium.org>
Tested-by: Randall Spangler <rspangler@chromium.org>
2013-09-11 19:45:38 +00:00
Bill Richardson
0c8c2e453a Add abstract "cond_t" type to detect state transitions.
We often need to watch for transitions between one state and another, so
that we can issue warnings or take action ONCE. This abstracts that "have I
already reacted to this" stuff into a single set of functions.

For example, this code reads a GPIO every time through the loop, but it only
generates an event when the GPIO value changes from 0 to 1:

    cond_t c;

    cond_init_false(&c);

    while(1) {
        int val = read_some_gpio();
        cond_set(&c, val);

        if (cond_went_true(&c))
            host_event(SOMETHING_HAPPENED);

        sleep(1);
    }

BUG=none
BRANCH=falco,peppy
TEST=manual

make BOARD=falco runtests

Change-Id: I42393fcf3c4eb71b9551118a0f442d55c0691315
Signed-off-by: Bill Richardson <wfrichar@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/65071
2013-08-09 15:44:09 -07:00
Vic Yang
5007bbc009 Use uintptr_t when converting integer from/to pointer
Perviously we use uint32_t for this, but this doesn't compile for 64-bit
environment (and likely doesn't for 16-bit either.) Use uintptr_t so that
we don't get size mismatch errors.

BUG=chrome-os-partner:19257
TEST=Run host emulated tests
BRANCH=None

Change-Id: I3cd66a745fa171c41a5f142514284ec106586acb
Signed-off-by: Vic Yang <victoryang@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/50358
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
2013-05-07 20:59:53 -07:00
Randall Spangler
97bf36c9d3 Add parse_bool() to centralize parsing boolean options
This way debug commands which previously took only yes/no or on/off or
enable/disable can take any of those options.

BUG=chrome-os-partner:18467
BRANCH=none
TEST=Try "on", "off", "yes", "no", "true", "false", "ena", "disable", for
each of the following commands:
  - ilim (spring)
  - pll (link)
  - power (spring/snow)
  - hcdebug (all)
  - kblog (link)
  - ksscan (all)
  - lp5562 (spring)

Change-Id: Ie8e0fae3775b1da711864bcba6682ba5e68a06f1
Signed-off-by: Randall Spangler <rspangler@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/46900
Reviewed-by: Bill Richardson <wfrichar@chromium.org>
2013-03-29 15:39:34 -07:00
Randall Spangler
1661f1cef0 Refactor flash module
This is a significant rewrite of the flash module, since it turns out
that much less of the flash logic is actually common between stm32 and
lm4.

BUG=chrome-os-partner:11699
TEST=on link,

(enable hardware wp)
flashinfo -> wp_gpio_asserted
flashwp enable
flashinfo -> wp_gpio_asserted ro_at_boot
reboot
flashinfo -> wp_gpio_asserted ro_at_boot ro_now
flashwp disable -> error 7
flashwp now
flashinfo -> wp_gpio_asserted ro_at_boot ro_now rw_now
reboot
flashinfo -> wp_gpio_asserted ro_at_boot ro_now
(disable hardware wp)
reboot
flashinfo -> ro_at_boot
flashwp disable
flashinfo -> (no flags)

Change-Id: If22b02373946ce1c080d49ccded4f8fa3e380115
Signed-off-by: Randall Spangler <rspangler@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/28200
Reviewed-by: Vic Yang <victoryang@chromium.org>
2012-07-23 23:30:33 -07:00
Randall Spangler
e27e2f0229 Add console functionality
Keys I keep hitting should work like I expect them to.

Home or Ctrl+A = move to beginning of line
End or Ctrl+E = move to end of line
Del = delete-right
Ctrl+K = delete to end of line
Ctrl+L = clear screen and reprint current line
Ctrl+N = next command
Ctrl+P = previous command

Also, improve filtering of escape sequences and non-printable
characters, so hitting unsupported keys or control codes doesn't mess
up the current line of input.

BUG=chrome-os-partner:11666
TEST=manual

  type 'fhelpbar'
  home -> cursor moves to beginning of line
  Ctrl+E -> cursor moves to end of line
  Ctrl+A -> cursor moves to beginning of line
    (of course, if you're using Minicom, you'll need to type Ctrl+A A, since
     Minicom uses Ctrl+A as its control key)
  del -> 'helpbar'
  end -> cursor moves to end of line
  left-arrow 3 times -> cursor moves under 'b'
  Ctrl+L -> screen clears, cursor still under 'b'
  Ctrl+K -> 'help'
  Ctrl+Y Page-Up Page-Down -> nothing printed
  enter -> prints known commands (output of 'help' command)
  Ctrl+P -> 'help'
  Ctrl+N -> empty command line

Change-Id: Id893c93b26db8f3deed6ea8be5aab88a3daaead4
Signed-off-by: Randall Spangler <rspangler@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/28143
2012-07-23 11:03:33 -07:00
Vic Yang
fda2466816 Prevent strzcpy access out-of-bound
When parameter 'len' is smaller or equal to 0, do not null-terminate.

BUG=chrome-os-partner:11041
TEST=Build success.

Change-Id: Ia5267e7d31e3ade8828ba0bc2d68405b4cd236be
Reviewed-on: https://gerrit.chromium.org/gerrit/26640
Reviewed-by: Randall Spangler <rspangler@chromium.org>
Commit-Ready: Vic Yang <victoryang@chromium.org>
Tested-by: Vic Yang <victoryang@chromium.org>
2012-07-03 10:50:45 -07:00
Vadim Bendebury
6a324c1de5 Allow console commands abbreviation
The EC console input handling code is being enhanced to accept
abbreviated command names.

If the abbreviation is unique, the appropriate command is used, if the
abbreviation is ambiguous, the command is handled as nonexistent. The
error message is being modified to mention that the command either
does not exist or is ambiguous.

This change also makes it impossible to have command names matching
the beginning of other command names. Two such cases are being fixed
(`ch' renamed to `chan' and `thermal' renamed to 'thermalconf').

BUG=none
TEST=manual
 . program the new EC image. Try entering at the console:
  > h
  Command 'h' either not found or ambiguous.
  Command returned error 1
  > he
  Known commands:
    adc            autofan        battery        ch             charger
  ...
  > help
  Known commands:
    adc            autofan        battery        ch             charger
  ...

Change-Id: Iaa3e91e1504e42daefb02d561e00c39003548197
Signed-off-by: Vadim Bendebury <vbendeb@chromium.org>
2012-05-14 13:35:03 -07:00
Randall Spangler
cbdd518422 Clean up sysjump struct parsing and add memmove()
Signed-off-by: Randall Spangler <rspangler@chromium.org>

BUG=chrome-os-partner:9447
TEST=update from old EC 517 to this one

Change-Id: I275b5bf6c4ae1ab6e0c0a05cf9260314d644c79b
2012-05-07 16:26:43 -07:00
Randall Spangler
9f552ff5aa Implement 64-bit integer printing in uart_printf()
Signed-off-by: Randall Spangler <rspangler@chromium.org>

BUG=chrome-os-partner:7490
TEST=timerinfo; numbers should look reasonable

Change-Id: I698be99c87bf311013427ac0ed9e93e5687f40c0
2012-04-20 14:01:11 -07:00
Bill Richardson
6e1cdb7898 Make strtoi() do the right thing for base==16
Before, strtoi("11", 0, 16) returned 11.
Now, strtoi("11", 0, 16) returns 17.

BUG=none
TEST=none
2012-02-10 16:11:30 -08:00
Randall Spangler
05bc7eca93 Eat terminal escape sequences
I keep hitting the darn arrow keys.  Until we can do something more
elegant like a real command history, this will at least keep me from
corrupting the display and input buffer.

Signed-off-by: Randall Spangler <rspangler@chromium.org>

BUG=none
TEST=type 'help' and some arrow keys, then enter.  Should print help, not an error.

Change-Id: Idb552e9c22876fc2dc1f349f0038e94048f00aa7
2012-01-27 13:58:49 -08:00
Randall Spangler
bdf7da5b08 Initial sources import 1/3
source files mainly done by Randall.

Signed-off-by: Randall Spangler <rspangler@chromium.org>

Change-Id: Iaff83a842b17f3350fb6f2a3f1597ad4c29bd12a
2011-12-07 19:10:02 +00:00