1
0
mirror of https://review.coreboot.org/flashrom.git synced 2025-04-27 15:12:36 +02:00

25 Commits

Author SHA1 Message Date
Edward O'Callaghan
0c774d6b6a tree/: Convert unlock func ptr into enumerate values
Converting the blockprotect unlock function pointer
within the flashchip struct into enum values allows for
the flashchips db to be turn into pure, declarative data.
A nice side-effect of this is to reduce link-time symbol
space of chipdrivers and increase modularity of the
spi25_statusreg.c and related implementations.

BUG=none
TEST=ninja test.

Change-Id: Ie5c5db1b09d07e1a549990d6f5a622fae4c83233
Signed-off-by: Edward O'Callaghan <quasisec@google.com>
Reviewed-on: https://review.coreboot.org/c/flashrom/+/69933
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Sam McNally <sammc@google.com>
Reviewed-by: Anastasia Klimchuk <aklm@chromium.org>
2023-03-20 00:36:56 +00:00
Edward O'Callaghan
dd41980f17 tests/: Assert on NULL heap allocations in tests
Change-Id: Id2adcfe859fb25d2a7f0734655c6b9a58c0890b6
Signed-off-by: Edward O'Callaghan <quasisec@google.com>
Reviewed-on: https://review.coreboot.org/c/flashrom/+/71919
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Anastasia Klimchuk <aklm@chromium.org>
2023-01-22 05:56:12 +00:00
Edward O'Callaghan
20400d6656 tests/chip{_wp}.c: Avoid unnecessary heap allocations
Just use a static string on the stack.

Change-Id: Ic6cb4f32094ae5868912ebcffc8ab21026c48d32
Signed-off-by: Edward O'Callaghan <quasisec@google.com>
Reviewed-on: https://review.coreboot.org/c/flashrom/+/71917
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Anastasia Klimchuk <aklm@chromium.org>
2023-01-22 05:32:22 +00:00
Edward O'Callaghan
3d76865fd5 tests/chip: Add non-aligned write within a region unit-test
A written region that is sized below that of the erasure granularity
can result in a incorrectly read region that does not include prior
content within the region before the write op. This was dealt with
in ChromeOS downstream by expanding out the read to match the erase
granularity however does not seem to impact upstream. Add a unit-test
to avoid regression as this is important behaviour to cover.

Change-Id: Id3ce5cd1936f0f348d34a6c77cee15e27a5c353f
Signed-off-by: Edward O'Callaghan <quasisec@google.com>
Reviewed-on: https://review.coreboot.org/c/flashrom/+/71659
Reviewed-by: Sam McNally <sammc@google.com>
Reviewed-by: Evan Benn <evanbenn@google.com>
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
2023-01-17 00:22:20 +00:00
Edward O'Callaghan
78e121b014 tests/chip.c: Set MOCK_CHIP_CONTENT non-ambiguously
A chip content setup as 0x00 is ambiguous from a zero'ed heap
or some erased chips and 0xFF is ambiguous from an erased chip.

Change-Id: I15905180141aee54c166ff1c0275d1a7dfde0a46
Signed-off-by: Edward O'Callaghan <quasisec@google.com>
Reviewed-on: https://review.coreboot.org/c/flashrom/+/71826
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Anastasia Klimchuk <aklm@chromium.org>
2023-01-15 10:29:09 +00:00
Edward O'Callaghan
3bba710d98 tree/: Convert flashchip erase_block func ptr to enumerate
This forges the way for flashchips.c to be pure declarative
data and lookup functions for dispatch to be pure. This
means that the flashchips data could be extracted out to
be agnostic data of the flashrom code and algorithms.

Change-Id: I02ae7e4c67c5bf34ec2fd7ffe4af8a2aba6fd5e5
Signed-off-by: Edward O'Callaghan <quasisec@google.com>
Reviewed-on: https://review.coreboot.org/c/flashrom/+/69133
Reviewed-by: Angel Pons <th3fanbus@gmail.com>
Reviewed-by: Anastasia Klimchuk <aklm@chromium.org>
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
2022-11-11 13:04:07 +00:00
Edward O'Callaghan
3c44e12a28 tree/: Convert flashchips db to use indirection for erase_block
This paves the way to allow for the conversion of flashchip erase_block
func ptr to enumerate values. This change should be a NOP.

TEST=`diff -u <(objdump -D flashchips.o_bk) <(objdump -D flashchips.o)`.

Change-Id: I122295ec9add0fe0efd27273c9725e5d64f6dbe2
Signed-off-by: Edward O'Callaghan <quasisec@google.com>
Reviewed-on: https://review.coreboot.org/c/flashrom/+/69131
Reviewed-by: Angel Pons <th3fanbus@gmail.com>
Reviewed-by: Anastasia Klimchuk <aklm@chromium.org>
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
2022-11-11 07:40:02 +00:00
Anastasia Klimchuk
af2ba601f4 tests: Add prefix to io_mock functions not to clash with macros
Flashrom I/O mock functions need to be renamed so that they do not
have name clash with standard I/O, because the latter are allowed
to be macros. Adding a prefix to flashrom mock functions avoids
them being accidentally expanded. Standard I/O functions are
expanded and flashrom mocks stay as they are.

BUG=b:237606255
TEST=ninja test
1) gcc 12.2.0 on Debian
2) clang 15.0 on Chromium OS

Ticket: https://ticket.coreboot.org/issues/411
Change-Id: I7998a8fb1b9e65621e12adbfab5460a245d5606b
Signed-off-by: Anastasia Klimchuk <aklm@chromium.org>
Reviewed-on: https://review.coreboot.org/c/flashrom/+/68433
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Felix Singer <felixsinger@posteo.net>
2022-11-08 21:09:42 +00:00
Edward O'Callaghan
594d3357b6 tree/: Convert flashchip read func ptr to enumerate
This forges the way for flashchips.c to be pure declarative
data and lookup functions for dispatch to be pure. This
means that the flashchips data could be extracted out to
be agnostic data of the flashrom code and algorithms.

TEST='R|W|E && --flash-name' on ARM, AMD & Intel DUT's.

Change-Id: I612d46fefedf2b69e7e2064aa857fa0756efb4e7
Signed-off-by: Edward O'Callaghan <quasisec@google.com>
Reviewed-on: https://review.coreboot.org/c/flashrom/+/66788
Reviewed-by: Nikolai Artemiev <nartemiev@google.com>
Reviewed-by: Felix Singer <felixsinger@posteo.net>
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
2022-11-01 01:16:26 +00:00
Edward O'Callaghan
985ad5623f tree/: Convert flashchip write func ptr to enumerate
This forges the way for flashchips.c to be pure declarative
data and lookup functions for dispatch to be pure. This
means that the flashchips data could be extracted out to
be agnostic data of the flashrom code and algorithms.

TEST='R|W|E && --flash-name' on ARM, AMD & Intel DUT's.

Change-Id: I80149de169464b204fb09f1424a86fc645b740fd
Signed-off-by: Edward O'Callaghan <quasisec@google.com>
Reviewed-on: https://review.coreboot.org/c/flashrom/+/66782
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Nikolai Artemiev <nartemiev@google.com>
Reviewed-by: Felix Singer <felixsinger@posteo.net>
2022-11-01 01:15:55 +00:00
Anastasia Klimchuk
c4784f1a9a tests: Add and include headers with function prototypes
Part 2 of fixing -Wmissing-prototypes warnings. This patch adds
headers with function prototypes and includes the headers into
source files. This fixes the warnings like this:

warning: no previous prototype for ‘function_name’
[-Wmissing-prototypes]

This patch is needed to sync compiler warning options between meson
and makefile.

TEST=running the following produces no warnings:
meson setup --wipe (to clean build directory)
ninja test

Change-Id: Ia1ff22deb2354569f277649c6575ef2d5ffbb6e0
Signed-off-by: Anastasia Klimchuk <aklm@chromium.org>
Reviewed-on: https://review.coreboot.org/c/flashrom/+/63489
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Thomas Heijligen <src@posteo.de>
Reviewed-by: Felix Singer <felixsinger@posteo.net>
Reviewed-by: Edward O'Callaghan <quasisec@chromium.org>
2022-04-29 04:30:38 +00:00
Anastasia Klimchuk
402e5d697c tests: Mark all static functions as static
Part 1 of fixing -Wmissing-prototypes warnings. This patch is
adding static to all functions which are actually static.
This fixes the warnings like this:

warning: no previous prototype for ‘function_name’
[-Wmissing-prototypes]

This patch is needed to sync compiler warning options between meson
and makefile.

TEST=running the following produces no warnings:
meson setup --wipe (to clean build directory)
ninja test

Change-Id: Ic54da5ac1b2a46f55e3e3bee4ed952bdf59e8444
Signed-off-by: Anastasia Klimchuk <aklm@chromium.org>
Reviewed-on: https://review.coreboot.org/c/flashrom/+/63571
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Thomas Heijligen <src@posteo.de>
Reviewed-by: Felix Singer <felixsinger@posteo.net>
Reviewed-by: Edward O'Callaghan <quasisec@chromium.org>
2022-04-29 04:24:33 +00:00
Edward O'Callaghan
8abe12e86e tests/: Add file path and flags validation to open() calls
With this change we add path and flag validation to many tests that do
not call open. Expected path is set to NULL, if the code indead calls
open then the assertion for non-NULL will make the test fail.

BUG=b:217629892,b:215255210
TEST=`ninja test`.

Change-Id: I892fa1ecee26ebce9640893edbb228fa9aa7b0b6
Signed-off-by: Edward O'Callaghan <quasisec@google.com>
Co-Author: Daniel Campello <campello@chromium.org>
Signed-off-by: Daniel Campello <campello@chromium.org>
Reviewed-on: https://review.coreboot.org/c/flashrom/+/62320
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Anastasia Klimchuk <aklm@chromium.org>
2022-04-18 23:16:37 +00:00
Anastasia Klimchuk
9a52d20b34 tests: Add tests for verify operation
This patch adds two tests which cover verify operation, and
adds io_mock for fread.

BUG=b:181803212
TEST=ninja test

Change-Id: I1cc6f73f9b1e385eb963adccf20759c13a40ed3b
Signed-off-by: Anastasia Klimchuk <aklm@chromium.org>
Reviewed-on: https://review.coreboot.org/c/flashrom/+/59239
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Edward O'Callaghan <quasisec@chromium.org>
Reviewed-by: Felix Singer <felixsinger@posteo.net>
2022-02-18 03:39:40 +00:00
Anastasia Klimchuk
9fb5812896 tests: Add comprehensive comment for chip.c
The following describes the two mechanisms of testing done for
flash chip operations.

BUG=b:181803212
TEST=ninja test

Change-Id: Ie498ec55cce8460fc0b2e1fe27254d3a9f763fac
Signed-off-by: Anastasia Klimchuk <aklm@chromium.org>
Reviewed-on: https://review.coreboot.org/c/flashrom/+/59238
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Felix Singer <felixsinger@posteo.net>
Reviewed-by: Edward O'Callaghan <quasisec@chromium.org>
2022-02-14 03:46:54 +00:00
Anastasia Klimchuk
3f8d1b4f2b tests: Set up mock chip memory in consistent and predictable way
This patch adds a macro MOCK_CHIP_CONTENT which represents a memory
state of a mock chip. The macro is used to initialise mock chip
memory at the beginning of a test (in setup_chip function).

Previously mock chip memory was not reset between tests. For
existing tests that did not matter, however new test for verify
operation (added later in this chain) needs mock chip memory to
be setup in a predictable way.

BUG=b:181803212
TEST=ninja test

Change-Id: I0d7623a601c207bfc62d54ab89d94cda56d85871
Signed-off-by: Anastasia Klimchuk <aklm@chromium.org>
Reviewed-on: https://review.coreboot.org/c/flashrom/+/59237
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Felix Singer <felixsinger@posteo.net>
Reviewed-by: Edward O'Callaghan <quasisec@chromium.org>
2022-02-14 03:15:57 +00:00
Anastasia Klimchuk
9aaa66cc7f tests: Convert write chip tests to libflashrom API
As a part of effort to convert command line (and everything else)
to be libflashrom users, chip tests need to be converted as well.

TEST=ninja test

Change-Id: I965598cfa74e3fb7d0780ad34491f4057617691e
Signed-off-by: Anastasia Klimchuk <aklm@chromium.org>
Reviewed-on: https://review.coreboot.org/c/flashrom/+/61139
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Edward O'Callaghan <quasisec@chromium.org>
2022-01-19 22:57:27 +00:00
Anastasia Klimchuk
df9aada04e tests: Convert read chip tests to libflashrom API
As a part of effort to convert command line (and everything else)
to be libflashrom users, chip tests need to be converted as well.

TEST=ninja test

Change-Id: I4493d4f269595783830c39a720b0a8963eab9daa
Signed-off-by: Anastasia Klimchuk <aklm@chromium.org>
Reviewed-on: https://review.coreboot.org/c/flashrom/+/61138
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Edward O'Callaghan <quasisec@chromium.org>
2022-01-19 22:56:48 +00:00
Anastasia Klimchuk
66f72d6ac9 tests: Convert erase chip tests to libflashrom API
As a part of effort to convert command line (and everything else)
to be libflashrom users, chip tests need to be converted as well.

TEST=ninja test

Change-Id: I38529a6b4d79882f50068b3628089b178dbe0a50
Signed-off-by: Anastasia Klimchuk <aklm@chromium.org>
Reviewed-on: https://review.coreboot.org/c/flashrom/+/61137
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Edward O'Callaghan <quasisec@chromium.org>
2022-01-19 22:56:28 +00:00
Anastasia Klimchuk
5020cf3a62 tests: Rename flash context in chip tests to flashctx
Flash context used to be named `flash` which was missing the
context part of it. Now it is renamed into flashctx for clarity.

BUG=b:181803212
TEST=ninja test

Change-Id: I3f4d9c4fe85752e16bab71ad22b0135a96cac28a
Signed-off-by: Anastasia Klimchuk <aklm@chromium.org>
Reviewed-on: https://review.coreboot.org/c/flashrom/+/58596
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Angel Pons <th3fanbus@gmail.com>
Reviewed-by: Edward O'Callaghan <quasisec@chromium.org>
2021-11-08 03:52:51 +00:00
Anastasia Klimchuk
8aaee03333 tests: Add tests to write on chip
This patch adds two tests and initialises page_size in mock chip
chip_W25Q128_V. page_size was not needed for previous tests
(erase and read). page_size only needed to execute writing on chip
with dummyflasher, so it is added here.

BUG=b:181803212
TEST=ninja test

Change-Id: I6f0336613ab16a7e59857006496e3590ddb14d00
Signed-off-by: Anastasia Klimchuk <aklm@chromium.org>
Reviewed-on: https://review.coreboot.org/c/flashrom/+/58357
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Edward O'Callaghan <quasisec@chromium.org>
2021-11-08 03:52:36 +00:00
Anastasia Klimchuk
caf6e0dcb2 tests: Revise mock chip definition and usage
This patch is doing few things:

1) Makes chip definitions static global so that they can be
reused between test functions.

2) Promotes existing mock chip from 8KiB to 8MiB and eraseblocks
are expanded accordingly. Old value of 8KiB was very small and it
was confusing. Mock chip looks more realistic now.

3) Uses KiB and MiB macros from flash.h for mock chip definition

4) Renames CHIP_TOTAL_SIZE to MOCK_CHIP_SIZE to avoid confusion
(there is also a W25Q128.V chip in the tests)

5) Makes chip definitions const so that every test can work on a
fresh copy on the stack.

BUG=b:181803212
TEST=builds and ninja test

Change-Id: Ia9b5fc71e30610684e68e9aca9fb1970da8f840a
Signed-off-by: Anastasia Klimchuk <aklm@chromium.org>
Reviewed-on: https://review.coreboot.org/c/flashrom/+/57437
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Nico Huber <nico.h@gmx.de>
2021-10-01 11:35:03 +00:00
Anastasia Klimchuk
1f62b8346e tests: Add tests to read from chip
Two tests cover the code which performs do_read operation.

First one works with fake chip and dummy programmer. Fake chip has all
operations defined, and a buffer to emulate chip memory.

Second one uses the chip which is closer to the real one, because
read/write/unlock/erase operations are real. The tests takes the
advantage of dummyflasher's capability of emulating a W25Q128.V chip.

BUG=b:181803212
TEST=builds and ninja test

Change-Id: Ia57781ebc670c7bd6197e56fe8a20651a425c756
Signed-off-by: Anastasia Klimchuk <aklm@chromium.org>
Reviewed-on: https://review.coreboot.org/c/flashrom/+/57326
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Nico Huber <nico.h@gmx.de>
2021-10-01 11:28:57 +00:00
Anastasia Klimchuk
2d538d87eb tests: Extract setup and teardown for chip tests
Steps to setup and teardown for a chip test are repeated for every
test, so they can be extracted into their own functions.

BUG=b:181803212
TEST=builds and ninja test

Change-Id: If59315646f06344664df08b145866d9ce846d751
Signed-off-by: Anastasia Klimchuk <aklm@chromium.org>
Reviewed-on: https://review.coreboot.org/c/flashrom/+/57436
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Nico Huber <nico.h@gmx.de>
Reviewed-by: Edward O'Callaghan <quasisec@chromium.org>
2021-10-01 11:28:41 +00:00
Anastasia Klimchuk
ed43237cfa tests: Add tests to erase a chip
Two tests cover the code which performs do_erase operation.

First one works with fake chip and dummy programmer. Fake chip has all
operations defined, and a buffer to emulate chip memory.

Second one uses the chip which is closer to the real one, because
read/write/unlock/erase operations are real. The tests takes the
advantage of dummyflasher's capability of emulating a W25Q128.V chip.

BUG=b:181803212
TEST=builds and ninja test

Change-Id: I6f74bfe4e02244d24d6c837cc3d551251e7b4898
Signed-off-by: Anastasia Klimchuk <aklm@chromium.org>
Reviewed-on: https://review.coreboot.org/c/flashrom/+/56501
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Edward O'Callaghan <quasisec@chromium.org>
2021-08-19 04:30:13 +00:00