/* * This file is part of the flashrom project. * * Copyright 2021 Google LLC * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; version 2 of the License. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * This file contains tests for operations on flash chip. * * Two flash chip test variants are used: * * 1) Mock chip state backed by `g_chip_state`. * Example of test: erase_chip_test_success. * * 2) Mock chip operations backed by `dummyflasher` emulation. * Dummyflasher controls chip state and emulates read/write/unlock/erase. * `g_chip_state` is NOT used for this type of tests. * Example of test: erase_chip_with_dummyflasher_test_success. */ #include #include #include #include "tests.h" #include "chipdrivers.h" #include "flash.h" #include "io_mock.h" #include "libflashrom.h" #include "programmer.h" #define MOCK_CHIP_SIZE (8*MiB) #define MOCK_CHIP_CONTENT 0xff static struct { unsigned int unlock_calls; /* how many times unlock function was called */ uint8_t buf[MOCK_CHIP_SIZE]; /* buffer of total size of chip, to emulate a chip */ } g_chip_state = { .unlock_calls = 0, .buf = { 0 }, }; static int read_chip(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len) { printf("Read chip called with start=0x%x, len=0x%x\n", start, len); if (!g_chip_state.unlock_calls) { printf("Error while reading chip: unlock was not called.\n"); return 1; } assert_in_range(start + len, 0, MOCK_CHIP_SIZE); memcpy(buf, &g_chip_state.buf[start], len); return 0; } static int write_chip(struct flashctx *flash, const uint8_t *buf, unsigned int start, unsigned int len) { printf("Write chip called with start=0x%x, len=0x%x\n", start, len); if (!g_chip_state.unlock_calls) { printf("Error while writing chip: unlock was not called.\n"); return 1; } assert_in_range(start + len, 0, MOCK_CHIP_SIZE); memcpy(&g_chip_state.buf[start], buf, len); return 0; } static int unlock_chip(struct flashctx *flash) { printf("Unlock chip called\n"); g_chip_state.unlock_calls++; if (g_chip_state.unlock_calls > 1) { printf("Error: Unlock called twice\n"); return -1; } return 0; } static int block_erase_chip(struct flashctx *flash, unsigned int blockaddr, unsigned int blocklen) { printf("Block erase called with blockaddr=0x%x, blocklen=0x%x\n", blockaddr, blocklen); if (!g_chip_state.unlock_calls) { printf("Error while erasing chip: unlock was not called.\n"); return 1; } assert_in_range(blockaddr + blocklen, 0, MOCK_CHIP_SIZE); memset(&g_chip_state.buf[blockaddr], 0xff, blocklen); return 0; } static void setup_chip(struct flashrom_flashctx *flashctx, struct flashrom_layout **layout, struct flashchip *chip, const char *programmer_param, const struct io_mock *io) { io_mock_register(io); flashctx->chip = chip; g_chip_state.unlock_calls = 0; memset(g_chip_state.buf, MOCK_CHIP_CONTENT, sizeof(g_chip_state.buf)); printf("Creating layout with one included region... "); assert_int_equal(0, flashrom_layout_new(layout)); /* One region which covers total size of chip. */ assert_int_equal(0, flashrom_layout_add_region(*layout, 0, chip->total_size * KiB - 1, "region")); assert_int_equal(0, flashrom_layout_include_region(*layout, "region")); flashrom_layout_set(flashctx, *layout); printf("done\n"); /* * We need some programmer (any), and dummy is a very good one, * because it doesn't need any mocking. So no extra complexity * from a programmer side, and test can focus on working with the chip. */ printf("Dummyflasher initialising with param=\"%s\"... ", programmer_param); assert_int_equal(0, programmer_init(&programmer_dummy, programmer_param)); /* Assignment below normally happens while probing, but this test is not probing. */ flashctx->mst = ®istered_masters[0]; printf("done\n"); } static void teardown(struct flashrom_layout **layout) { printf("Dummyflasher shutdown... "); assert_int_equal(0, programmer_shutdown()); printf("done\n"); printf("Releasing layout... "); flashrom_layout_release(*layout); printf("done\n"); io_mock_register(NULL); } extern write_func_t *g_test_write_injector; extern read_func_t *g_test_read_injector; extern erasefunc_t *g_test_erase_injector; static const struct flashchip chip_8MiB = { .vendor = "aklm", .total_size = MOCK_CHIP_SIZE / KiB, .tested = TEST_OK_PREW, .read = TEST_READ_INJECTOR, .write = TEST_WRITE_INJECTOR, .unlock = unlock_chip, .block_erasers = {{ /* All blocks within total size of the chip. */ .eraseblocks = { {2 * MiB, 4} }, .block_erase = TEST_ERASE_INJECTOR, }}, }; /* Setup the struct for W25Q128.V, all values come from flashchips.c */ static const struct flashchip chip_W25Q128_V = { .vendor = "aklm&dummyflasher", .total_size = 16 * 1024, .tested = TEST_OK_PREW, .read = SPI_CHIP_READ, .write = SPI_CHIP_WRITE256, .unlock = spi_disable_blockprotect, .page_size = 256, .block_erasers = { { .eraseblocks = { {4 * 1024, 4096} }, .block_erase = SPI_BLOCK_ERASE_20, }, { .eraseblocks = { {32 * 1024, 512} }, .block_erase = SPI_BLOCK_ERASE_52, }, { .eraseblocks = { {64 * 1024, 256} }, .block_erase = SPI_BLOCK
from libghdl import libghdl


Get_Start_Location = libghdl.vhdl__elocations__get_start_location

Set_Start_Location = libghdl.vhdl__elocations__set_start_location

Get_Right_Paren_Location = libghdl.vhdl__elocations__get_right_paren_location

Set_Right_Paren_Location = libghdl.vhdl__elocations__set_right_paren_location

Get_End_Location = libghdl.vhdl__elocations__get_end_location

Set_End_Location = libghdl.vhdl__elocations__set_end_location

Get_Is_Location = libghdl.vhdl__elocations__get_is_location

Set_Is_Location = libghdl.vhdl__elocations__set_is_location

Get_Begin_Location = libghdl.vhdl__elocations__get_begin_location

Set_Begin_Location = libghdl.vhdl__elocations__set_begin_location

Get_Then_Location = libghdl.vhdl__elocations__get_then_location

Set_Then_Location = libghdl.vhdl__elocations__set_then_location

Get_Use_Location = libghdl.vhdl__elocations__get_use_location

Set_Use_Location = libghdl.vhdl__elocations__set_use_location

Get_Loop_Location = libghdl.vhdl__elocations__get_loop_location

Set_Loop_Location = libghdl.vhdl__elocations__set_loop_location

Get_Generate_Location = libghdl.vhdl__elocations__get_generate_location

Set_Generate_Location = libghdl.vhdl__elocations__set_generate_location

Get_Generic_Location = libghdl.vhdl__elocations__get_generic_location

Set_Generic_Location = libghdl.vhdl__elocations__set_generic_location

Get_Port_Location = libghdl.vhdl__elocations__get_port_location

Set_Port_Location = libghdl.vhdl__elocations__set_port_location

Get_Generic_Map_Location = libghdl.vhdl__elocations__get_generic_map_location

Set_Generic_Map_Location = libghdl.vhdl__elocations__set_generic_map_location

Get_Port_Map_Location = libghdl.vhdl__elocations__get_port_map_location

Set_Port_Map_Location = libghdl.vhdl__elocations__set_port_map_location

Get_Arrow_Location = libghdl.vhdl__elocations__get_arrow_location

Set_Arrow_Location = libghdl.vhdl__elocations__set_arrow_location

Get_Colon_Location = libghdl.vhdl__elocations__get_colon_location

Set_Colon_Location = libghdl.vhdl__elocations__set_colon_location

Get_Assign_Location = libghdl.vhdl__elocations__get_assign_location

Set_Assign_Location = libghdl.vhdl__elocations__set_assign_location