summaryrefslogtreecommitdiff
path: root/util/cbi-util.c
Commit message (Collapse)AuthorAgeFilesLines
* cbi-util: Allow field size to be specifiedDaisuke Nojiri2018-05-161-31/+55
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Currently, field sizes are automatically set to the smallest size which can fit a given value. This patch makes cbi-util allow field sizes to be specified. Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org> BUG=b:79514391 BRANCH=none TEST=Tested as follows: 1. Create CBI image: $ cbi-util create --file cbi.bin --board_version 0x202 \ --oem_id 0xabcd:2 --sku_id 0xff:4 --size 256 2. Verify the image: $ cbi-util show --file cbi.bin CBI image: /home/dnojiri/tmp/nami/tmp/cbi.new.bin TOTAL_SIZE: 22 Data Field: name: value (hex, tag, size) BOARD_VERSION: 514 (0x202, 0, 2) OEM_ID: 43981 (0xabcd, 1, 2) SKU_ID: 255 (0xff, 2, 4) 3. Verify the output matches with the previous output if field sizes are not specified. Change-Id: Ic7149274d6e4a118ea12bbf03199b548b7089a3e Reviewed-on: https://chromium-review.googlesource.com/1056201 Commit-Ready: Daisuke Nojiri <dnojiri@chromium.org> Tested-by: Daisuke Nojiri <dnojiri@chromium.org> Reviewed-by: Aaron Durbin <adurbin@chromium.org>
* cbi-util: Refactor the toolDaisuke Nojiri2018-05-161-168/+185
| | | | | | | | | | | | | | | | | This patch moves argument parsing code in each sub-command routine. Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org> CQ-DEPEND=CL:*625723 BUG=b:79514391 BRANCH=none TEST=Verify cbi-util show and create produce the same results. Change-Id: I8842f16394210399ff55c75adb16dadcae8642e7 Reviewed-on: https://chromium-review.googlesource.com/1056200 Commit-Ready: Daisuke Nojiri <dnojiri@chromium.org> Tested-by: Daisuke Nojiri <dnojiri@chromium.org> Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
* CBI: Make cbi-util set field size automaticallyDaisuke Nojiri2018-03-071-26/+41
| | | | | | | | | | | | | | | | | | | | | Currently cbi-util accepts only fixed length values. This patch makes it automatically calculate the required field size to accomodate the given integer value. The stored values are expanded to uint32_t when they're read. BUG=b:74174598,b:70702820 BRANCH=none TEST=Run cbi-util with --sku_id set to the followings: 0x10 -> field size = 1, 0x1000 -> field size = 2, 0x10000 -> field size = 4, 0x100000000 -> Error Change-Id: I2221ebfa18260bae2c574d9ebb794dbe645579e5 Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/951711 Reviewed-by: Randall Spangler <rspangler@chromium.org>
* CBI: Share common code between host tool and firmwareDaisuke Nojiri2018-02-231-34/+4
| | | | | | | | | | | | | | This patch makes EC firmware and cbi-util share the common code. BUG=b:70294260 BRANCH=none TEST=Set fields using ectool. Verify the contents by cbi command. Verify cbi-util creates the same binary as before. Verify emerge ec-utils ec-devutils pass. Change-Id: If5e65e48dd03960e0adf23ef775f67aecf785d85 Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/932001
* CBI: Update cbi-util printing formatDaisuke Nojiri2018-02-201-14/+41
| | | | | | | | | | | | | | | | | | | | | | | This patch makes cbi-util print the tag and the size of each field. It also fixes help message and adds indendation for readability. BUG=b:70294260 BRANCH=none TEST=Run the command as follows: $ cbi-util --show /tmp/cbi.bin CBI blob: /tmp/cbi2.bin TOTAL_SIZE: 18 CBI_VERSION: 0 Data Field: name: value (hex, tag, size) BOARD_VERSION: 514 (0x202, 0, 2) OEM_ID: 2 (0x2, 1, 1) SKU_ID: 3 (0x3, 2, 1) Data validated successfully Change-Id: I5f0fde4690c29c0ee58c798e8cc35bac3ed1b6f8 Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/926781 Reviewed-by: Randall Spangler <rspangler@chromium.org>
* CBI: Update cbi-util to support variable data offset & sizeDaisuke Nojiri2018-02-161-23/+72
| | | | | | | | | | | | | | | | | | | | | | | This patch makes cbi-util support variable data offset & size. BUG=b:70294260 BRANCH=none TEST=Run the command as follows: $ cbi-util --create /tmp/cbi.bin \ --board_version 0x202 --oem_id 2 --sku_id 3 --size 256 $ cbi-util --show /tmp/cbi.bin CBI blob: /tmp/cbi2.bin TOTAL_SIZE: 18 CBI_VERSION: 0 BOARD_VERSION: 514 (0x202) OEM_ID: 1 (0x1) SKU_ID: 2 (0x2) Data validated successfully Change-Id: Id290c33e8625223c8f3fa34fdf8a13ea9308c42e Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/922272 Reviewed-by: Randall Spangler <rspangler@chromium.org>
* cbi-util: Help GCC determine that variable is initializedMartin Roth2018-02-051-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | GCC 6.3 can't tell that we enforce the variable 'size' being set, so initialize it to 0 to make the warning go away. The code does actually verify that size is set, but not by checking the size variable itself. util/cbi-util.c: In function 'main': util/cbi-util.c:139:8: error: 'size' may be used uninitialized in this function [-Werror=maybe-uninitialized] buf = malloc(size); ^~~~~~~~~~~~ util/cbi-util.c:233:11: note: 'size' was declared here uint32_t size; ^~~~ BUG=b:72609872 BRANCH=None TEST=Build with coreboot toolchain. Change-Id: Ide41a0fce40254f2fa3a8626dec75840a728d967 Signed-off-by: Martin Roth <martinroth@google.com> Reviewed-on: https://chromium-review.googlesource.com/890703 Commit-Ready: Martin Roth <martinroth@chromium.org> Tested-by: Martin Roth <martinroth@chromium.org> Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org> Reviewed-by: Edward Hill <ecgh@chromium.org> Reviewed-by: Patrick Georgi <pgeorgi@chromium.org> Reviewed-by: Jett Rink <jettrink@chromium.org>
* CBI: Add cbi-utilDaisuke Nojiri2018-01-181-0/+338
cbi-util is a build command line tool, which creates a blob containing board information. When invoked with '--show' option, it prints the information stored in a blob and validates the data. BUG=b:70294260 BRANCH=none TEST=Run the command as follows: $ cbi-util --create /path/to/cbi.bin \ --board_version 0xabcd --oem_id 2 --sku_id 3 --size 256 $ cbi-util --show /path/to/cbi.bin CBI blob: /path/to/cbi.bin BOARD_VERSION: 0.1 (0xab.cd) OEM_ID: 2 (0x02) SKU_ID: 3 (0x03) Data validated successfully $ cbi-util --create /path/to/cbi.bin \ --board_version 0xabcd --oem_id 2 --sku_id 3 Missing required arguments $ cbi-util --create /path/to/cbi.bin --board_version 0xabcde Invalid --board_version Change-Id: I7e7b439c50943523039c3cafda3bdf7d08962c61 Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/860961 Reviewed-by: Randall Spangler <rspangler@chromium.org>