summaryrefslogtreecommitdiff
path: root/common/util.c
Commit message (Collapse)AuthorAgeFilesLines
* cortex-m mpu: support configuring regions with difficult alignmentPeter Marheine2020-12-111-0/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The existing configuration code assumes that provided addresses are at least as aligned as the requested size, which is not true on NPCX797WC (and likely others) where RAM regions are only 64k-aligned but have larger sizes (like 256k). Use a new greedy approach to configuring the MPU which handles these situations corrently: for any given request take the largest possible chunk from the bottom of the memory region (subject to size and address alignment). Maximize the space by aggressively using MPU subregions- this means that in many well-aligned situations this algorithm selects a larger region than the requested size and enables one subregion, but in more difficult situations it is capable of enabling subregions with more exotic positions. BUG=b:169276765 BRANCH=zork TEST=With a test harness to print out computed configurations, manually verified the correctness of a variety taken from real chip configurations (request first, MPU region(s) indented): 0x20000000 size 0x1000 # stm32f03x 0x20000000 size 0x8000 srd fe 0x20000000 size 0x2000 # stm32f03x 0x20000000 size 0x10000 srd fe 0x20000000 size 0x2800 # stm32l100 0x20000000 size 0x4000 srd e0 0x20000000 size 0x4000 # stm32f412 0x20000000 size 0x20000 srd fe 0x80000 size 0xc000 # it8320 0x80000 size 0x20000 srd f8 0xff200000 size 0xa0000 # ish5p4 0xff200000 size 0x100000 srd e0 0x200b0000 size 0x20000 # npcx797wb 0x20080000 size 0x80000 srd e7 0x10070000 size 0x40000 # npcx797wb 0x10000000 size 0x80000 srd 7f 0x10080000 size 0x80000 srd f8 0x200c0000 size 0x10000 # npcx796f 0x20080000 size 0x80000 srd ef 0x10090000 size 0x30000 # npcx796f 0x10080000 size 0x80000 srd f1 0x10090000 size 0x20 0x10090000 size 0x100 srd fe Further verified MPU configuration with the new algorithm succeeds on Dalboz, and test/mpu.c passes on Dragonclaw. Signed-off-by: Peter Marheine <pmarheine@chromium.org> Change-Id: I71d8e2b37c7e20fc7a39166b90eea0b7f7ebcf43 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2434601 Reviewed-by: Edward Hill <ecgh@chromium.org>
* tree: rename strtoul to strtoull since it is 64-bitJett Rink2020-11-111-1/+3
| | | | | | | | | | | | | | | A long is 32-bit, but a long long is 64-bit. The function name should be strtoull if it is returning 64 bits of data. BRANCH=none BUG=b:172592963 TEST=builds Signed-off-by: Jett Rink <jettrink@chromium.org> Change-Id: I04c40f9256ed37eb1cf9b6bd1b0ef0320fe49b0c Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2530874 Commit-Queue: Jack Rosenthal <jrosenth@chromium.org> Reviewed-by: Jack Rosenthal <jrosenth@chromium.org>
* Make wait_for_ready available for allDaisuke Nojiri2020-07-281-0/+12
| | | | | | | | | | | | | | | | | | | wait_for_ready is a generic function which loops until bits in a register are set. This patch move it to util.c to make it available for all. There are more places where the function is applicable but this CL keeps the scope under chip/stm32/clock-stm32. There is no functionality change. BUG=none BRANCH=none TEST=buildall Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org> Change-Id: I796599344c1d86ab7144d1d6b434ec54cf1cc55d Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2317887 Reviewed-by: Scott Collyer <scollyer@chromium.org>
* fuzz: Fix varargs/printf with MSANEdward Hill2020-06-231-0/+6
| | | | | | | | | | | | | | | | | | Remove our implementations of memcpy/memset/memmove for MSAN and ASAN since they are intercepted by the sanitizers. This was breaking varargs, causing va_arg() to return 0, which was most obvious in printf() with MSAN enabled. BUG=chromium:963303 BRANCH=none TEST=make -j host-host_command_fuzz TEST_MSAN=1 Signed-off-by: Edward Hill <ecgh@chromium.org> Change-Id: Id65d88b79bbb1834babe62c90078ec92a6aa5fba Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2220160 Reviewed-by: Evgenii Stepanov <eugenis@chromium.org> Reviewed-by: Manoj Gupta <manojgupta@chromium.org> Commit-Queue: Manoj Gupta <manojgupta@chromium.org>
* common/util: Add is_alignedTom Hughes2020-05-151-0/+8
| | | | | | | | | | | | | | | Helper function to check power-of-two alignment. BRANCH=none BUG=b:155229277, b:156501835 TEST=make buildall -j TEST=make run-utils Signed-off-by: Tom Hughes <tomhughes@chromium.org> Change-Id: Iadcdaeb59e496f10035bd6c7f9660a3cc33a4898 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2202849 Commit-Queue: Ting Shen <phoenixshen@chromium.org> Reviewed-by: Ting Shen <phoenixshen@chromium.org>
* util: Add function to check whether a buffer is trivial (all 0x00 or all 0xff)Yicheng Li2019-10-041-0/+12
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This function's execution time depends only on the buffer length but not on the specific bytes in the buffer. BRANCH=nocturne BUG=chromium:927095 TEST=make -j buildall TEST=timed the execution of bytes_are_trivial() on a long array with the following contents: Array 1: 0x01, 0x00, 0x00, 0x00, ..., 0x00, 0x00 (first byte nontrivial) Array 2: 0x00, 0x00, 0x00, 0x00, ..., 0x00, 0x02 (last byte nontrivial) Array 3: 0x00, 0x00, ... , 0x00, 0x03, 0x00, ..., (middle byte nontrivial) Array 4: 0x00, 0x00 , ... (trivial) (These 4 arrays have the same length.) Verified that execution on these arrays take similar amount of time, proportional to the length of the array, specifically: For 256k bytes, takes 21~40 microseconds For 128k bytes, takes 10~17 microseconds For 64k bytes, takes 5~9 microseconds For 32k bytes, takes 2~5 microseconds Because the host timer inaccuracy and potential process scheduling variations, the execution time for arrays 1-4 are sometimes not exactly the same. To avoid test flakiness, this timing test is not written to unit tests. But it should prove that bytes_are_trivial() is a constant time algorithm. Change-Id: I131748e1a4ee3a3e19a105dba5dc443bb2371d30 Signed-off-by: Yicheng Li <yichengli@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1787870
* utils: Add strstrDaisuke Nojiri2019-10-011-0/+25
| | | | | | | | | | | | | | | | | | The strstr API searches for s2 in s1 and returns the pointer to the substring found in s1. Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org> BUG=none BRANCH=none TEST=make run-utils_str Change-Id: I30f5e8d03e304d28dd6e9bfeebfcaeee2e79ea85 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1818727 Tested-by: Daisuke Nojiri <dnojiri@chromium.org> Auto-Submit: Daisuke Nojiri <dnojiri@chromium.org> Reviewed-by: Jett Rink <jettrink@chromium.org> Commit-Queue: Jett Rink <jettrink@chromium.org>
* util: Move __stdlib_compat to function definitionsCraig Hesling2019-07-301-22/+23
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Putting a visibility-hidden attribute in the header file is ambiguous. The compiler cannot determine which definition should be hidden (our implementation or stdlib). This serves as a slight correction to the work in crrev.com/c/1180401 . In particular, this fixes test/fuzz builds with code coverage enabled: make runtests TEST_COVERAGE=1 -j Before this fix, enabling coverage would trigger build errors, like the following: In file included from common/test_util.c:19: include/util.h:82:1: error: attribute declaration must precede definition [-Werror,-Wignored-attributes] __stdlib_compat int atoi(const char *nptr); ^ include/common.h:267:40: note: expanded from macro '__stdlib_compat' #define __stdlib_compat __attribute__((visibility("hidden"))) ^ /usr/include/stdlib.h:361:8: note: previous definition is here __NTH (atoi (const char *__nptr)) Note that enabling sanitizer on some unit tests is still broken (as it was before this CL). For example, these unit tests fail when compiling with sanitizers: make host-charge_manager_drp_charging TEST_ASAN=1 make host-charge_manager_drp_charging TEST_MSAN=1 BRANCH=none BUG=none TEST=make runtests TEST_COVERAGE=1 -j TEST=make buildall -j Change-Id: I74462c964c0ff9d3ee131450e6826cbbd6c89319 Signed-off-by: Craig Hesling <hesling@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1724936 Reviewed-by: Aseda Aboagye <aaboagye@chromium.org> Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
* LICENSE: remove unnecessary (c) after CopyrightTom Hughes2019-06-191-1/+1
| | | | | | | | | | | | | | | | Ran the following command: git grep -l 'Copyright (c)' | \ xargs sed -i 's/Copyright (c)/Copyright/g' BRANCH=none BUG=none TEST=make buildall -j Change-Id: I6cc4a0f7e8b30d5b5f97d53c031c299f3e164ca7 Signed-off-by: Tom Hughes <tomhughes@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1663262 Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org> Reviewed-by: Aseda Aboagye <aaboagye@chromium.org>
* Align behavior of strtoi() and strtoul() to match Linux manpage description ↵Jes Klinke2019-05-141-28/+31
| | | | | | | | | | | | | | | | | | | | | | | | | | | of strtol(). Behavior changes: 1) Initial '+' character is tolerated. 2) Hexadecimal strings prefixed with "0x" are rejected, if given base parameter is anything other than 16 or 0, rather than parsed as hex, diregarding the given base. 3) If given base is 0, strings starting with leading zero will be parsed as octal, rather than decimal. 4) Initial '-' character allowed before "0x" on hexadecimal numbers. (Note: This is my first time using git or gerrit, please let me know if there is some policy or customs that I am not properly adhering to.) BRANCH=none TEST=make run-utils_str V=1 Bug: 940329 Change-Id: I71654471b77f0df071a58ff6bed7028f00cd46b5 Signed-off-by: Jes Bodi Klinke <jbk@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1577750 Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com> Tested-by: Jes Klinke <jbk@chromium.org> Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
* common: bit change 1 << constants with BIT(constants)Gwendal Grignou2019-03-261-1/+1
| | | | | | | | | | | | | | | | | Mechanical replacement of bit operation where operand is a constant. More bit operation exist, but prone to errors. Reveal a bug in npcx: chip/npcx/system-npcx7.c:114:54: error: conversion from 'long unsigned int' to 'uint8_t' {aka 'volatile unsigned char'} changes value from '16777215' to '255' [-Werror=overflow] BUG=None BRANCH=None TEST=None Change-Id: I006614026143fa180702ac0d1cc2ceb1b3c6eeb0 Signed-off-by: Gwendal Grignou <gwendal@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1518660 Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
* common: replace 1 << digits, with BIT(digits)Gwendal Grignou2019-03-261-3/+3
| | | | | | | | | | | | | | | | Requested for linux integration, use BIT instead of 1 << First step replace bit operation with operand containing only digits. Fix an error in motion_lid try to set bit 31 of a signed integer. BUG=None BRANCH=None TEST=compile Change-Id: Ie843611f2f68e241f0f40d4067f7ade726951d29 Signed-off-by: Gwendal Grignou <gwendal@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1518659 Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
* Util: Add hexdump APIDaisuke Nojiri2019-02-151-0/+26
| | | | | | | | | | | | | | | | | | | | | | This patch adds the hexdump API, which prints binary data in hex and ASCII. Sample output of hexdump(image_data.version, 30): 6e 61 6d 69 5f 76 32 2e 30 2e 37 37 34 2d 63 66 |nami_v2.0.774-cf| 34 62 64 33 34 38 30 00 00 00 00 00 00 00 |4bd3480....... | Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org> BUG=none BRANCH=none TEST=Verify image_data.version is printed as expected on Nami Change-Id: I8a10a9ac4d329657bf65b64117448cb9b3e75a52 Reviewed-on: https://chromium-review.googlesource.com/1457577 Commit-Ready: Daisuke Nojiri <dnojiri@chromium.org> Tested-by: Daisuke Nojiri <dnojiri@chromium.org> Reviewed-by: Jett Rink <jettrink@chromium.org>
* util: add isupper() library functionDino Li2018-10-311-0/+5
| | | | | | | | | | | | | This function checks whether a character is an uppercase alphabet or not. BRANCH=none BUG=none TEST=The return value is non-zero if argument is an uppercase alphabet. Change-Id: I8c7be3f8852be103b8f853caa426de7843c4ee40 Signed-off-by: Dino Li <Dino.Li@ite.com.tw> Reviewed-on: https://chromium-review.googlesource.com/1307280 Reviewed-by: Jonathan Brandmeyer <jbrandmeyer@chromium.org>
* host_events: Bump up host events and masks to 64-bitFurquan Shaikh2017-11-211-0/+39
| | | | | | | | | | | | | | | | | | | | | | | | | | | | With the upcoming change to add a new command to get/set/clear host events and masks, it seems to be the right time to bump up the host events and masks to 64-bit. We are already out of available host events. This change opens up at least 32 bits for new host events. Old EC commands to operate on host events/masks will still deal with lower 32-bits of the events/mask. On the other hand, the new command being added will take care of the entire 64-bit events/masks. This ensures that old BIOS and kernel versions can still work with the newer EC versions. BUG=b:69329196 BRANCH=None TEST=make -j buildall. Verified: 1. hostevent set 0x4000 ==> Sets correct bit in host events 2. hostevent clear 0x4000 ==> Clears correct bit in host events 3. Kernel is able to query and read correct host event bits from EC. Verified using evtest. 4. Coreboot is able to read correct wake reason from EC. Verified using mosys eventlog list. Change-Id: Idcb24ea364ac6c491efc2f8dd9e29a9df6149e07 Signed-off-by: Furquan Shaikh <furquan@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/770925 Reviewed-by: Randall Spangler <rspangler@chromium.org>
* common: Use SVr4/4.3BSD/C89/C99 prototype for strlenStefan Reinauer2017-08-181-1/+1
| | | | | | | | | | | | | | | | | | SVr4/4.3BSD/C89/C99 use a return value of size_t. To make interaction with code running on both userland and on the EC easier, change our function prototype to return size_t as well. Signed-off-by: Stefan Reinauer <reinauer@google.com> BRANCH=none BUG=none TEST=make buildall -j works Change-Id: I0f097c4d0db4232d888e1d54e6c1d22f4859a112 Reviewed-on: https://chromium-review.googlesource.com/618269 Commit-Ready: Stefan Reinauer <reinauer@google.com> Tested-by: Stefan Reinauer <reinauer@google.com> Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
* util: add constant-time memcmpVincent Palatin2017-02-231-0/+19
| | | | | | | | | | | | | | | | | Import from vboot_reference the constant-time memcmp implementation for safer usage in cryptography code. Signed-off-by: Vincent Palatin <vpalatin@chromium.org> BRANCH=none BUG=chrome-os-partner:62991 TEST=run curve25519 test Change-Id: I9c4c61e15912c978e13b6cc002af879c8ae8f630 Reviewed-on: https://chromium-review.googlesource.com/446098 Commit-Ready: Vincent Palatin <vpalatin@chromium.org> Tested-by: Vincent Palatin <vpalatin@chromium.org> Reviewed-by: Randall Spangler <rspangler@chromium.org>
* builtin: Expands string.h / stdint.hNadim Taha2017-02-171-0/+56
| | | | | | | | | | | | | | Declares UINT8_MAX, INT8_MAX and defines strnlen(), strncpy(), strncmp() & memchr(). Needed by a module I'm integrating into cr51. BRANCH=none BUG=none TEST=make buildall -j Change-Id: I894b0297216df1b945b36fc77cd3bc5c4ef8aa2b Signed-off-by: Nadim Taha <ntaha@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/436786 Reviewed-by: Randall Spangler <rspangler@chromium.org>
* Cr50: Use parse_bool() for boolean argsBill Richardson2016-08-221-3/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | The parse_bool() function exists so we don't have to litter our console commands with stuff like this: if (!strncasecmp(argv[1], "on") || !strncasecmp(argv[1], "enable" || !strncasecmp(argv[1], "true" || [...] This CL uses parse_bool instead of that kind of thing so I don't have to remember which commands use "enable" and which use "on" and so forth. I only changed the commands that Cr50 uses. BUG=none BRANCH=none TEST=make buildall; test on Cr50 hardware I tested all the affected commands to ensure that they still work correctly: usb, ccd, flashwp (which doesn't do anything anyway). Change-Id: I7d875ab22934fb4b500e3d0f62ebe3e04101272d Signed-off-by: Bill Richardson <wfrichar@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/373658 Reviewed-by: Randall Spangler <rspangler@chromium.org>
* CR50: move utility method reverse() to common/util.cnagendra modadugu2016-03-071-0/+15
| | | | | | | | | | | | | | | | | reverse() swaps the endian-ness of a buffer of specified length. This change moves the implementation to a common location. BRANCH=none BUG=chrome-os-partner:43025,chrome-os-partner:47524 TEST=compilation succeeds Change-Id: If8c97f53cc199d63c1caebbd999e1c099814387e Signed-off-by: nagendra modadugu <ngm@google.com> Reviewed-on: https://chromium-review.googlesource.com/331333 Commit-Ready: Nagendra Modadugu <ngm@google.com> Tested-by: Nagendra Modadugu <ngm@google.com> Reviewed-by: Vadim Bendebury <vbendeb@chromium.org>
* Queue: Add methods that accept a memcpy routineAnton Staaf2015-01-081-5/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | These versions of the queue add and remove methods support using memcpy like routines to access regions of memory with specific requirements. In particular, this will allow for transfers between queues and USB packet RAM on the STM32 which has specific access requirements. This change also includes an update to the mem* util routines to make their prototypes compatible with C89 and POSIX standards. Signed-off-by: Anton Staaf <robotboy@chromium.org> BRANCH=None BUG=None TEST=make buildall -j Test USB Echo functionality on discovery-stm32f072 board to ensure that queues still function correctly. Change-Id: I557064d99abfc3e8cfc98099a1d94334a976550c Reviewed-on: https://chromium-review.googlesource.com/239217 Tested-by: Anton Staaf <robotboy@chromium.org> Reviewed-by: Randall Spangler <rspangler@chromium.org> Commit-Queue: Anton Staaf <robotboy@chromium.org> Trybot-Ready: Anton Staaf <robotboy@chromium.org>
* util: move console command argument parsing to util.cDominic Chen2014-06-111-0/+35
| | | | | | | | | | | | | 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>
* Optimize memsetDaisuke Nojiri2014-03-011-7/+30
| | | | | | | | | | | | | | | | | | | | | | | | | 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>
* Optimize memmoveDaisuke Nojiri2014-02-131-8/+36
| | | | | | | | | | | | | | | | | | | | | | | | | 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>
* Optimize memcpyDaisuke Nojiri2014-02-121-7/+35
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* cleanup: Remove checkpatch warningsRandall Spangler2013-12-191-4/+5
| | | | | | | | | | | | | | | | 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
* cleanup: Assorted TODO commentsRandall Spangler2013-10-311-3/+12
| | | | | | | | | | | | | | | 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>
* Support multi-bit mask in STM32L's GPIO functionsVic Yang2013-09-111-0/+7
| | | | | | | | | | | | | | | | | | 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>
* Add abstract "cond_t" type to detect state transitions.Bill Richardson2013-08-091-1/+57
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* Use uintptr_t when converting integer from/to pointerVic Yang2013-05-071-2/+2
| | | | | | | | | | | | | | | 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>
* Add parse_bool() to centralize parsing boolean optionsRandall Spangler2013-03-291-0/+14
| | | | | | | | | | | | | | | | | | | | | | 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>
* Refactor flash moduleRandall Spangler2012-07-231-0/+16
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* Add console functionalityRandall Spangler2012-07-231-1/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* Prevent strzcpy access out-of-boundVic Yang2012-07-031-0/+2
| | | | | | | | | | | | | 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>
* Allow console commands abbreviationVadim Bendebury2012-05-141-0/+16
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* Clean up sysjump struct parsing and add memmove()Randall Spangler2012-05-071-0/+21
| | | | | | | | | 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
* Implement 64-bit integer printing in uart_printf()Randall Spangler2012-04-201-1/+45
| | | | | | | | | Signed-off-by: Randall Spangler <rspangler@chromium.org> BUG=chrome-os-partner:7490 TEST=timerinfo; numbers should look reasonable Change-Id: I698be99c87bf311013427ac0ed9e93e5687f40c0
* Make strtoi() do the right thing for base==16Bill Richardson2012-02-101-2/+2
| | | | | | | | Before, strtoi("11", 0, 16) returned 11. Now, strtoi("11", 0, 16) returns 17. BUG=none TEST=none
* Eat terminal escape sequencesRandall Spangler2012-01-271-0/+6
| | | | | | | | | | | | | 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
* Initial sources import 1/3Randall Spangler2011-12-071-0/+151
source files mainly done by Randall. Signed-off-by: Randall Spangler <rspangler@chromium.org> Change-Id: Iaff83a842b17f3350fb6f2a3f1597ad4c29bd12a