summaryrefslogtreecommitdiff
path: root/common/printf.c
Commit message (Collapse)AuthorAgeFilesLines
* Update license boilerplate text in source code filesstabilize-quickfix-15278.72.B-ishstabilize-quickfix-15183.78.B-ishstabilize-15446.B-ishstabilize-15439.B-ishstabilize-15432.B-ishstabilize-15429.B-ishstabilize-15415.B-ishstabilize-15395.B-ishstabilize-15393.48.B-ishstabilize-15381.B-ishstabilize-15364.B-ishstabilize-15361.B-ishstabilize-15359.B-ishstabilize-15359.58.B-ishstabilize-15359.50.B-ishstabilize-15359.45.B-ishstabilize-15335.B-ishstabilize-15329.59.B-ishstabilize-15329.44.B-ishstabilize-15317.B-ishstabilize-15301.B-ishstabilize-15300.B-ishstabilize-15278.64.B-ishstabilize-15251.B-ishstabilize-15245.B-ishstabilize-15236.66.B-ishstabilize-15208.B-ishstabilize-15207.B-ishstabilize-15185.B-ishstabilize-15185.7.B-ishstabilize-15183.82.B-ishstabilize-15183.69.B-ishstabilize-15183.14.B-ishstabilize-15174.B-ishstabilize-15167.B-ishstabilize-15129.B-ishstabilize-15122.B-ishstabilize-15120.B-ishstabilize-15117.86.B-ishstabilize-15117.48.B-ishstabilize-15117.111.B-ishrelease-R114-15437.B-ishrelease-R113-15393.B-ishrelease-R112-15359.B-ishrelease-R111-15329.B-ishrelease-R110-15278.B-ishrelease-R109-15237.B-ishrelease-R109-15236.B-ishrelease-R108-15183.B-ishrelease-R107-15117.B-ishishfirmware-ti50-prepvt-15315.B-ishfirmware-skyrim-15390.B-ishfirmware-skyrim-15369.B-ishfirmware-nissa-15217.B-ishfirmware-nissa-15217.45.B-ishfirmware-nissa-15217.126.B-ishfirmware-duplo-15151.B-ishfirmware-corsola-15194.B-ishfactory-trogdor-15210.B-ishfactory-skyrim-15384.B-ishfactory-nissa-15199.B-ishfactory-corsola-15197.B-ishfactory-corsola-15196.B-ishfactory-brya-15231.B-ishMike Frysinger2022-09-141-2/+1
| | | | | | | | | | | | | | Normally we don't do this, but enough changes have accumulated that we're doing a tree-wide one-off update of the name & style. BRANCH=none BUG=chromium:1098010 TEST=`repo upload` works Change-Id: I5b357b85ae9473a192b80983871bef4ae0d4b16f Signed-off-by: Mike Frysinger <vapier@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3893394 Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
* zephyr: switch to using shell_*, not printkDawid Niedzwiecki2021-07-091-10/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Reimplement the printf functions for Zephyr to use shell_* functions instead of printk. The main differences are: -UART output is buffered by the shell layer. The size of the buffer should be adjusted per board (SHELL_BACKEND_SERIAL_TX_RING_BUFFER_SIZE) -The shell uses non-blocking UART FIFO operations while printk waits actively for every sent byte. -The shell prints can not be split by the other shell prints so it should increase the quality of the output. However the shell_* functions can not be used in interrupts, so use printk instead which can divide the shell output. The output may be messy for boards that have a lot of prints in interrupts e.g. volteer. EC uses unusual print format e.g. "%pT" to print a timestamp, so use the CrosEC's vfnprintf function and then pass the generated string to the shell_* print. Use the sprintf function for that purpose. Long term, the EC codebase should switch to a usual print format, so shell_* can be used directly and not 2 versions of vfnprintf. This change should also help to pass tests that wait for a certain pattern on output e.g. ECBootTime. BUG=b:191724484, b:178033156 BRANCH=none TEST=Verify the console output works Signed-off-by: Dawid Niedzwiecki <dn@semihalf.com> Change-Id: Ifaed2093ab8c43038c7d3e0ded1449a93f7f7da5 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2988194 Reviewed-by: Keith Short <keithshort@chromium.org> Commit-Queue: Keith Short <keithshort@chromium.org>
* zephyr: update snprintf signature to be compatible with zephyr 2.6Yuval Peress2021-06-181-2/+2
| | | | | | | | | | | | | | | | Also update the tests for printf since the documentation makes no guarantee about negative size values. BRANCH=none BUG=b:190731415 TEST=build brya TEST=make run-printf Signed-off-by: Yuval Peress <peress@chromium.org> Change-Id: I5e773362f1f30a1beb95284e589e49db3a1d8800 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2970989 Commit-Queue: Denis Brockus <dbrockus@chromium.org> Reviewed-by: Denis Brockus <dbrockus@chromium.org>
* zephyr: switch to platform/ec printf format implementationJack Rosenthal2021-01-091-1/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | Prior to this change, the cprints and cprintf shim implementations used Zephyr's printk to do the output formatting. Our EC code has some custom printf specifiers not supported by Zephyr's printk. We've already attempted to send some of our custom specifiers upstream, but upstream does not want them: https://github.com/zephyrproject-rtos/zephyr/pull/28882 The logical thing to do would be to bring in the vfnprintf function from our EC to the Zephyr build, and use that to do the output formatting instead. That's what this CL does. The binary cost of brining in this second printf implementation appears to be minimal (952 bytes on volteer). BUG=b:177065615 BRANCH=none TEST=on posix-ec and volteer, run gettime and observe output no longer contains %.6lld, but instead the correct system time Signed-off-by: Jack Rosenthal <jrosenth@chromium.org> Change-Id: I53cd4edf129223c12a2c5e7d0519623a8d07a328 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2618575
* ec: change usage of "sane" per inclusive languagePaul Fagerburg2020-07-221-2/+2
| | | | | | | | | | | | | | | | Google is working to change its source code to use more inclusive language. To that end, replace the terms "sane", "sanity check", and similar with inclusive/non-stigmatizing alternatives. BUG=b:161832469 BRANCH=None TEST=`make buildall -j` succeeds. `grep -Eir "sane|sanity" .` shows results only in third-party code or documentation. Signed-off-by: Paul Fagerburg <pfagerburg@chromium.org> Change-Id: I29e78ab27f84f17b1ded75cfa10868fa4e5ae88c Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2311169 Reviewed-by: Jett Rink <jettrink@chromium.org>
* printf: Avoid null pointer dereferenceEdward Hill2020-05-201-0/+7
| | | | | | | | | | | | | | | Avoid null pointer dereference for %ph and %pb. %pT and %pP can accept null. BUG=chromium:1076023 BRANCH=none TEST=make -j host-host_command_fuzz TEST_MSAN=1 Signed-off-by: Edward Hill <ecgh@chromium.org> Change-Id: I0248d03cff428b8dd1aded84417d8ea2f3efe3b9 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2209367 Reviewed-by: Jack Rosenthal <jrosenth@chromium.org> Reviewed-by: Evan Green <evgreen@chromium.org>
* printf: be consistent using PRINTF_TIMESTAMP_NOWVadim Bendebury2019-11-091-2/+1
| | | | | | | | | | | | | | | | | PRINTF_TIMESTAMP_NOW is used to indicate that %pT format specifier means 'current time'. Let's use it at the point where format is analyzed to be consistent with the rest of the EC tree. BRANCH=none BUG=none TEST=make buildall succeeds, 'ccprintf ("%pT", PRINTF_TIMESTAMP_NOW);' still prints the current time. Change-Id: I42e80039a4335015f5504830070ca36abfb2487c Signed-off-by: Vadim Bendebury <vbendeb@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1906994 Reviewed-by: Jack Rosenthal <jrosenth@chromium.org> Reviewed-by: Evan Green <evgreen@chromium.org>
* printf: Deprecate %lEvan Green2019-10-051-1/+17
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The semantics of %l changed during the enabling of compile-time printf format checking. Old firmware branches will treat something like %lx as a 64-bit value, but new code on master will enforce at compile-time that a long (32-bits on our ECs) is passed in as the argument. This creates a dangerous and difficult to notice situation if the following code is cherry-picked from master into an old firmware branch: printf("%lx %s", myval32, mystr); On master, this behaves correctly. On the old firmware branch, this would swallow myval32 and mystr for %lx, and then %s would grab a random stack pointer and print a string from it. Deprecating %l is our mechanism for keeping such a printf from creeping into master in the future. Obviously we can't protect against someone that checks in code that's never tested, but anyone who tests a printf with %l in it will notice their printf comes out with ERROR instead of what they want. BUG=chromium:984041 TEST=make -j buildall BRANCH=None Change-Id: I0267430363af7954c2ec5d2c45222759fe0ec2c1 Signed-off-by: Evan Green <evgreen@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1834604 Reviewed-by: Jack Rosenthal <jrosenth@chromium.org>
* printf: Correct semantics of %lEvan Green2019-10-051-11/+0
| | | | | | | | | | | | | | | | | | | | | In the standard, %l[dioux] takes an integer of type long. In the EC up until now, we had been using it as shorthand for a 64-bit long. Now that we're enabling the compile-time printf format checker, it's time to correct the semantics of %l. This is a breaking change. I would advise against cherry-picking this commit into any firmware branches. The reasoning is that the specifier now swallows a different number of arguments, causing any subsequent specifiers to be wrong. BUG=chromium:984041 TEST=make -j buildall BRANCH=None Change-Id: Ia5630e59611097dc0deda648498c7f43b9c62ac9 Signed-off-by: Evan Green <evgreen@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1829576 Reviewed-by: Jack Rosenthal <jrosenth@chromium.org>
* printf: Convert %l to %llEvan Green2019-10-051-0/+20
| | | | | | | | | | | | | | | | | | | | | In order to make our printf more standard, utilize %ll for long long arguments, rather than %l. This does cost a little bit in flash space for that extra l in a couple of places, but enables us to turn on compile-time printf format checking. For this commit only, the semantics are such that both %l and %ll take 64-bit arguments. In the next commit, %l goes to its correct behavior of taking a sizeof(long) argument. BUG=chromium:984041 TEST=make -j buildall BRANCH=none Cq-Depend:chrome-internal:1863686,chrome-internal:1860161,chrome-internal:1914029 Change-Id: I18081b55a8dbf5ef8ec15fc499ca75e59d31da58 Signed-off-by: Evan Green <evgreen@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1819652 Reviewed-by: Jack Rosenthal <jrosenth@chromium.org>
* printf: Add support for %zEvan Green2019-10-051-1/+9
| | | | | | | | | | | | | | | | When printing size_t sized integers, utilize the standard %z modifier so that the specifier format is correct. This will enable us to turn on compile-time printf format verification. BUG=chromium:984041 TEST=make -j buildall BRANCH=none Cq-Depend:chrome-internal:1860160 Change-Id: I2c95df5c0d87677cb9fcbde33ab8846708a774a1 Signed-off-by: Evan Green <evgreen@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1819651 Reviewed-by: Jack Rosenthal <jrosenth@chromium.org>
* printf: Convert %b to %pbEvan Green2019-10-051-3/+15
| | | | | | | | | | | | | | | | | | | | | | | | In order to turn on compile-time printf format checking, non-standard specifiers like %b (binary) must be removed. Convert that into %pb, which takes a pointer to a structure containing the value to print, and how many bits to print. Use the convenience macro BINARY_VALUE() to package these values up into a struct whose pointer is passed to printf(). Technically this is slightly more limited functionality than we used to support given all the possible flags, field width, and precision. However every existing instance in our codebase was using %0NNb, where NN is some number. If more variants are needed, the parameters structure can be expanded in the future. BUG=chromium:984041 TEST=make -j buildall BRANCH=None Change-Id: I8ef995dcf97af688fbca98ab6ff59b84092b69e3 Signed-off-by: Evan Green <evgreen@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1733100 Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
* printf: Convert %h to %phEvan Green2019-10-051-45/+73
| | | | | | | | | | | | | | | | | | | | | In order to make printf more standard, use %ph. Pass a pointer to a struct describing the buffer, including its size. Add a convenience macro so that conversion between the old style and new style is purely mechanical. The old style of %h cannot be converted directly to %ph as-is because the C standard doesn't allow flags, precision, or field width on %p. Ultimately the goal is to enable compile-time printf format checking. This gets us one step closer to that. BUG=chromium:984041 TEST=make -j buildall BRANCH=None Cq-Depend:chrome-internal:1559798,chrome-internal:1560598 Change-Id: I9c0ca124a048314c9b62d64bd55b36be55034e0e Signed-off-by: Evan Green <evgreen@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1730605
* printf: Convert %T to %pTEvan Green2019-10-051-10/+33
| | | | | | | | | | | | | | | | | | | | | | In order to be more compliant to standards, and ultimately turn on compile-time printf format validation, switch the non-standard %T into %pT, which takes a pointer to a 64-bit timestamp as an argument. For convenience, define PRINTF_TIMESTAMP_NOW, which will use the current time as the timestamp value, rather than forcing everyone to pass a pointer to get_time().val. For a couple of instances, simply use CPRINTS instead. BUG=chromium:984041 TEST=make -j buildall BRANCH=None Cq-Depend:chrome-internal:1473305 Change-Id: I83e45b55a95ea27256dc147544ae3f7e39acc5dd Signed-off-by: Evan Green <evgreen@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1704216 Reviewed-by: Jack Rosenthal <jrosenth@chromium.org> Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
* vprintf: fix handling % in the end of the format stringVadim Bendebury2019-07-311-0/+4
| | | | | | | | | | | | | | | | | EC vprintf() implementation treats a single '%' character in the end of the format string as a literal per cent character. This is a special case, while processing it the terminated zero is getting lost. This patch fixes the problem. BRANCH=none BUG=none TEST=none Change-Id: I9abea74072b56edfbbace988b0b7a6d1f7d8cd5f Signed-off-by: Vadim Bendebury <vbendeb@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1726739 Reviewed-by: Andrey Pronin <apronin@chromium.org> Reviewed-by: Randall Spangler <rspangler@chromium.org>
* printf: Fix hexdump and string 0 precisionCraig Hesling2019-07-181-14/+44
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This patch addresses a few issues with the current formatter. The major points are as follows: 1. Cannot specify precision 0 (truncate all) for string or hexdump 2. Forced safe precision for malformed strings 3. No padding when using hexdump 4. Bad error EC_ERROR_INVAL in vsnprintf 5. Documentation errors For (1), no piece of code explicitly sets the precision to 0 in order to invoke the default behavior, which is currently no precision limit. You can check using the following grep line: grep -rI '%[\*0-9]\{0,20\}\.0\{1,20\}[a-zA-Z]' However, there are many cases where the precision is used to limit the character output (as it should be). grep -rI '%[\*0-9]\{0,20\}\.[\*0-9]\{1,20\}[a-zA-Z]' There are many more instances that use variable precision without checking if the precision is zero. One of which is the following: crrev.com/4a4e2c71a0f6aaa50e0728922f84a7d54c14380a/test/host_command_fuzz.c#116 https://clusterfuzz.com/testcase-detail/5699023975088128 Our current implementation will insert ERROR and stop processing, if a precision of zero is detected when using the hexdump flag. This results in a badly formatted console line or runtime string, when the intended behavior would be to simply read no bytes. In the aforementioned fuzzer case, outputting ERROR triggers a false positive. Our printf should handle explicit zero precision similar to stdlib's printf, which means truncating all the way to zero positions, if specified. For (2), our current implementation uses strlen to identify the length of the input string, regardless of the set precision. Since this is an embedded platform, we should use strnlen to impose safe limits, when a precision is specified. For (3), our implementation should support padding and adjusting of all formatter types, since that is a primary feature of a printf formatter. The remaining commented code highlights odd behavior that should be fixed at some point, but is not critical. BUG=chromium:974084 TEST=Checked for any format lines that rely on a set precision of 0 grep -rI '%[\*0-9]\{0,20\}\.[\*0-9]\{1,20\}[a-zA-Z]' TEST=make run-printf V=1 BRANCH=none Change-Id: I897c53cce20a701fcbe8fb9572eb878817525cc3 Signed-off-by: Craig Hesling <hesling@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1659835 Reviewed-by: Randall Spangler <rspangler@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>
* common: replace 1 << digits, with BIT(digits)Gwendal Grignou2019-03-261-4/+4
| | | | | | | | | | | | | | | | 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>
* common/printf: snprintf: Return number of bytes on successNicolas Boichat2018-06-281-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | As indicated in the man page: """ Upon successful return, these functions return the number of characters printed (excluding the null byte used to end output to strings). """ There are no users of the return value currently in the EC code, but this matters when doing fuzzing, as libFuzzer calls std::to_string, which expects the correct return value. BRANCH=none BUG=chromium:854975 TEST=make buildfuzztests -j && ASAN_OPTIONS="log_path=stderr" \ build/host/usb_pd_fuzz/usb_pd_fuzz.exe -jobs=10 actually creates 10 output files. TEST=make run-utils_str -j Change-Id: If6a040f690dd847f4c88c3b8566554afdfbabc32 Signed-off-by: Nicolas Boichat <drinkcat@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1116625 Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
* Add vsnprintf function.Jeff Andersen2018-03-201-3/+12
| | | | | | | | | | | | | | | | | This function enables variadic functions to take advantage of functionality provided by snprintf. Signed-off-by: Jeff Andersen <jeffandersen@google.com> BRANCH=none BUG=b:72360575 TEST=make buildall -j Change-Id: I0095a96339b374ef8030b87b5184fa4678b439eb Reviewed-on: https://chromium-review.googlesource.com/971761 Commit-Ready: Jeff Andersen <jeffandersen@google.com> Tested-by: Jeff Andersen <jeffandersen@google.com> Reviewed-by: Randall Spangler <rspangler@chromium.org>
* printf: add %li format for compatibilityVincent Palatin2017-12-251-0/+6
| | | | | | | | | | | | | | For compatibility/convenience, implement the '%li' printf format as a *32-bit* integer format, as it might be expected by non-EC code. Signed-off-by: Vincent Palatin <vpalatin@chromium.org> BRANCH=none BUG=b:70320279 TEST=run on Eve EVT with unspecified external binary and see its traces are correctly printed. Change-Id: Iac20e823c74aac4f659176416eebd804c321d47c
* console: Add non-verbose print config optionShawn Nematbakhsh2017-02-111-0/+5
| | | | | | | | | | | | | | | | | Shorten certain long prints and reduce the precision of timestamp prints when CONFIG_CONSOLE_VERBOSE is undef'd. BUG=chromium:688743 BRANCH=gru TEST=On kevin, cold reset the EC, boot to OS, and verify cros_ec.log contains all data since sysjump and is < 2K bytes (~1500 bytes). Change-Id: Ia9390867788d0ab3087f827b0296107b4e9d4bca Signed-off-by: Shawn Nematbakhsh <shawnn@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/438932 Commit-Ready: Shawn N <shawnn@chromium.org> Tested-by: Shawn N <shawnn@chromium.org> Reviewed-by: Shawn N <shawnn@chromium.org>
* printf: Add sign ('+') flagDaisuke Nojiri2016-07-291-5/+16
| | | | | | | | | | | | | | | | | | | | | | | | | | | | '+' flag can be used with signed integer type (%d) and causes positive integers to be prefixed with '+' (e.g. +1745). This emphasizes output values as a signed value. It can be mixed with left-justification flag '-': %-+8d. It's ignored when used with unsigned integer or non-integer types: %u, %x, %p, %s, %c, etc. BUG=none BRANCH=none TEST=make buildall && int32_t d = 1745; CPRINTS("'%-+8d'", -d); /* '-1745 ' */ CPRINTS("'%-+8d'", d); /* '+1745 ' */ CPRINTS("'%d'", d); /* '1745' */ CPRINTS("'%+08d'", -d); /* '000-1745' */ CPRINTS("'%+08d'", d); /* '000+1745' */ CPRINTS("'%+d'", -d); /* '-1745' */ CPRINTS("'%+d'", d); /* '+1745' */ CPRINTS("'%+s'", "foo"); /* 'foo' */ CPRINTS("'%-+8s'", "foo"); /* 'foo ' */ CPRINTS("'%+08x'", d); /* '000006d1' */ CPRINTS("'%+u'", d); /* '1745' */ Change-Id: I8dcd34b0cf03dbefc500b9c98fea235d85bde8d3 Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/363924
* stm32: add synchronous debug printfAlec Berg2015-10-191-2/+2
| | | | | | | | | | | | | | | | | | Allow use of a synchronous debug printf instead of using the full console task to save space. This can be turned on with CONFIG_DEBUG_PRINTF, and will provide essentially a one-way console for debugging. This is essentially expanding upon the debug_printf work done for zinger. BUG=chrome-os-partner:41959 BRANCH=none TEST=tested with following CLs on glados_pd by verifying we get a one-way console. Change-Id: If028b5d873261890de5b270bbc00e06bdcaa7431 Signed-off-by: Alec Berg <alecaberg@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/306782 Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
* optimize printf size without the common runtimeVincent Palatin2015-04-101-3/+25
| | | | | | | | | | | | | | | | | | | | | | | When a platform is built without the common runtime to optimize for flash size, remove the 64-bit support in printf to save more space (mainly by getting rid of the uint64divmod helper). This saves 376 bytes of flash on Zinger/MiniMuffin. Signed-off-by: Vincent Palatin <vpalatin@chromium.org> BRANCH=none BUG=none TEST=make buildall and compare flash size with and without the change. the common runtime binaries are identical excepted the version information. Change-Id: I1e7237e693df9ea23291c8c0fe414c3b5c716848 Reviewed-on: https://chromium-review.googlesource.com/265052 Trybot-Ready: Vincent Palatin <vpalatin@chromium.org> Tested-by: Vincent Palatin <vpalatin@chromium.org> Reviewed-by: Alec Berg <alecaberg@chromium.org> Commit-Queue: Vincent Palatin <vpalatin@chromium.org>
* cleanup: Remove checkpatch warningsRandall Spangler2013-12-191-1/+1
| | | | | | | | | | | | | | | | 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
* Reduce stack space used by vfnprintf()Randall Spangler2013-11-201-36/+51
| | | | | | | | | | | | | | | | | | | | Converting some of the boolean variables in vfnprintf() to a single flags word reduces stack usage by 8 bytes and function size by 12 bytes. So it's slightly more efficient in both respects. Confirmed size and stack usage improvements via 'make BOARD=rambi all dis' and looking at the disassembly for vfnprintf() BUG=chrome-os-partner:24148 BRANCH=none TEST=Run taskinfo command twice and compare stack used by CONSOLE task. Run timerinfo and charger commands and verify output looks reasonable; those exercise binary and 64-bit number printing. Change-Id: Ie4396bb0bc01dc155956fa2d8ca84c6630006729 Signed-off-by: Randall Spangler <rspangler@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/177400 Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
* Clean up printf moduleRandall Spangler2012-10-251-10/+22
| | | | | | | | | | | | | No functional changes. BUG=chrome-os-partner:15579 BRANCH=none TEST=boot system; debug output still shows up on EC console Change-Id: I63f4f9481f5393aaff065b37a274236bd78622d9 Signed-off-by: Randall Spangler <rspangler@chromium.org> Reviewed-on: https://gerrit.chromium.org/gerrit/36581 Reviewed-by: Bill Richardson <wfrichar@chromium.org>
* Enhance printf()Randall Spangler2012-07-301-22/+88
| | | | | | | | | | | | | | | | | | | 1. Add precision to limit string length. ccprintf("%.4s", "foobar") prints "foob" 2. Handle '*' for length, precision fields. ccprintf("%.*s", 3, "foobar") prints "foo" 3. Add hex-dump code "%h" ccprintf("%.*s", 4, "foobar") prints 666f6f62 BUG=none TEST=at ec console, 'hash' prints the current hash Change-Id: I568310f2727495b021081bf58df2a0bbb3c74e73 Signed-off-by: Randall Spangler <rspangler@chromium.org> Reviewed-on: https://gerrit.chromium.org/gerrit/28704 Reviewed-by: Bill Richardson <wfrichar@chromium.org>
* Fix printing hex numbersRandall Spangler2012-06-071-2/+2
| | | | | | | | | | | | | | | | Off-by-one is not my friend. BUG=chrome-os-partner:10206 TEST=manual 1. rw 0x20000000 2. ww back the same number printed 3. rw 0x20000000. should match Signed-off-by: Randall Spangler <rspangler@chromium.org> Change-Id: I61e0d26cf4cb274a88326d4e7d24ff1c82d6e515 Reviewed-on: https://gerrit.chromium.org/gerrit/24756 Reviewed-by: Simon Glass <sjg@chromium.org>
* Move printf() formatting to its own file to enable re-useRandall Spangler2012-06-071-0/+236
Also add snprintf(), and %X format code. BUG=chrome-os-partner:10206 TEST=timerinfo; should print correctly. 'ectool battery' on host side should print same serial as 'battery' on EC console. Change-Id: I5c9f69d1a20ee5d0a59440c122655adbf62c9aea Signed-off-by: Randall Spangler <rspangler@chromium.org> Reviewed-on: https://gerrit.chromium.org/gerrit/24635 Reviewed-by: Simon Glass <sjg@chromium.org> Reviewed-by: Rong Chang <rongchang@chromium.org>