summaryrefslogtreecommitdiff
path: root/chip/stm32/dfu_bootmanager_shared.h
blob: df920f16a5ad9f7d8a928e16d017a1fd78d96111 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/* Copyright 2022 The ChromiumOS Authors
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 *
 * DFU Boot Manager shared utilities for STM32
 *
 * These of utilities required by the Boot Manager Main and RW Application.
 * These allow the systems to start the sequence to enter DFU, clear the
 * state, and access the backup registers.
 */

#ifndef __DFU_BOOTMANAGER_SHARED_H
#define __DFU_BOOTMANAGER_SHARED_H

#include "common.h"

/* Registers to validate the backup memory region. */
#define DFU_BOOTMANAGER_VALUE_MASK 0x00FF
#define DFU_BOOTMANAGER_VALID_MASK 0xFF00
#define DFU_BOOTMANAGER_VALID_CHECK 0xAA00

#define DFU_BOOTMANAGER_VALUE_CLEAR 0
#define DFU_BOOTMANAGER_VALUE_DFU UINT8_MAX

/*
 * Reset and enter the DFU mode.
 *
 * The system will set flags to the backup memory to enter DFU and issue
 * a reset. The Boot Manager will send the system to DFU mode.
 *
 * @return           EC_SUCCESS, or non-zero if error.
 */
int dfu_bootmanager_enter_dfu(void);

/*
 * Clear the DFU Boot Manager backup memory state.
 *
 * If the CONFIG_DFU_BOOTMANAGER_MAX_REBOOT_COUNT setting is enabled, this
 * allows the RW application to clear the counter to indicate the application
 * is working as expected.
 */
void dfu_bootmanager_clear(void);

/*
 * Write the value to the backup registers and sets the bitmasks
 * indicating the field is valid.
 *
 * @param value  New value to store.
 */
void dfu_bootmanager_backup_write(uint8_t value);

/*
 * Reads the backup registers and performs validation. The value stored
 * within the VALUE_MASK is returned and the status code indicates
 * if the valid check passed.
 *
 * @param value[out] Value stored within the DFU_BOOTMANAGER_VALUE_MASK
 * @return           EC_SUCCESS, or non-zero if validation failed.
 */
int dfu_bootmanager_backup_read(uint8_t *value);

#endif /* __DFU_BOOTMANAGER_SHARED_H */