OpenOCD
read_only.c
Go to the documentation of this file.
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 
3 /*
4  * Copyright (C) 2019 by Tomas Vanek <vanekt@fbl.cz>
5  *
6  * To declare a read-only region for GDB memory map.
7  */
8 
9 #ifdef HAVE_CONFIG_H
10 #include "config.h"
11 #endif
12 
13 #include "imp.h"
14 
15 FLASH_BANK_COMMAND_HANDLER(rom_bank_command)
16 {
17  bank->read_only = true;
18  return ERROR_OK;
19 }
20 
21 static int rom_erase(struct flash_bank *bank, unsigned int first, unsigned int last)
22 {
23  LOG_ERROR("Erase of read-only memory refused");
24  return ERROR_FAIL;
25 }
26 
27 static int rom_write(struct flash_bank *bank, const uint8_t *buffer,
28  uint32_t offset, uint32_t count)
29 {
30  LOG_ERROR("Write to read-only memory refused");
31  return ERROR_FAIL;
32 }
33 
34 static int rom_probe(struct flash_bank *bank)
35 {
36  return ERROR_OK;
37 }
38 
39 const struct flash_driver read_only_flash = {
40  .name = "read_only",
41  .flash_bank_command = rom_bank_command,
42  .erase = rom_erase,
43  .write = rom_write,
44  .read = default_flash_read,
45  .probe = rom_probe,
46  .auto_probe = rom_probe,
47  .erase_check = default_flash_blank_check,
48 
49  // ROM driver doesn't set driver_priv, free(NULL) makes no harm
50  .free_driver_priv = default_flash_free_driver_priv,
51 };
uint64_t buffer
Pointer to data buffer to send over SPI.
Definition: dw-spi-helper.h:0
uint8_t bank
Definition: esirisc.c:135
int default_flash_blank_check(struct flash_bank *bank)
Provides default erased-bank check handling.
int default_flash_read(struct flash_bank *bank, uint8_t *buffer, uint32_t offset, uint32_t count)
Provides default read implementation for flash memory.
void default_flash_free_driver_priv(struct flash_bank *bank)
Deallocates bank->driver_priv.
#define ERROR_FAIL
Definition: log.h:188
#define LOG_ERROR(expr ...)
Definition: log.h:147
#define ERROR_OK
Definition: log.h:182
static int rom_probe(struct flash_bank *bank)
Definition: read_only.c:34
static int rom_write(struct flash_bank *bank, const uint8_t *buffer, uint32_t offset, uint32_t count)
Definition: read_only.c:27
const struct flash_driver read_only_flash
Definition: read_only.c:39
FLASH_BANK_COMMAND_HANDLER(rom_bank_command)
Definition: read_only.c:15
static int rom_erase(struct flash_bank *bank, unsigned int first, unsigned int last)
Definition: read_only.c:21
Provides details of a flash bank, available either on-chip or through a major interface.
Definition: nor/core.h:75
Provides the implementation-independent structure that defines all of the callbacks required by OpenO...
Definition: nor/driver.h:39
const char * name
Gives a human-readable name of this flash driver, This field is used to select and initialize the dri...
Definition: nor/driver.h:44
uint8_t offset[4]
Definition: vdebug.c:9
uint8_t count[4]
Definition: vdebug.c:22