1/* 2 * Copyright (C) 2015 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17#ifndef _STM32_BL_H_ 18#define _STM32_BL_H_ 19 20/* 21 * cmd_erase, cmd_read_memory, cmd_write_memory - byte to send for cmd 22 * 23 * write_data - write length bytes of data 24 * (function must checksum data. space reserved for checksum in buffer) 25 * write_cmd - write cmd 26 * read_data - read length bytes of data 27 * read_ack - read ack 28 * functions return results of command 29 */ 30typedef struct handle 31{ 32 uint8_t cmd_erase; 33 uint8_t cmd_read_memory; 34 uint8_t cmd_write_memory; 35 36 uint8_t (*write_data)(struct handle *, uint8_t *buffer, int length); 37 uint8_t (*write_cmd)(struct handle *, uint8_t cmd); 38 uint8_t (*read_data)(struct handle *, uint8_t *buffer, int length); 39 uint8_t (*read_ack)(struct handle *); 40} handle_t; 41 42uint8_t checksum(handle_t *handle, uint8_t *bytes, int length); 43uint8_t erase_sector(handle_t *handle, uint16_t sector); 44uint8_t read_memory(handle_t *handle, uint32_t addr, uint32_t length, uint8_t *buffer); 45uint8_t write_memory(handle_t *handle, uint32_t addr, uint32_t length, uint8_t *buffer); 46 47/* 48 * Bootloader commands 49 * _NS versions are no-stretch. 50 * will return CMD_BUSY instead of stretching the clock 51 */ 52 53#define CMD_GET 0x00 54#define CMD_GET_VERSION 0x01 55#define CMD_GET_ID 0x02 56#define CMD_READ_MEMORY 0x11 57#define CMD_NACK 0x1F 58#define CMD_GO 0x21 59#define CMD_WRITE_MEMORY 0x31 60#define CMD_WRITE_MEMORY_NS 0x32 61#define CMD_ERASE 0x44 62#define CMD_ERASE_NS 0x45 63#define CMD_SOF 0x5A 64#define CMD_WRITE_PROTECT 0x63 65#define CMD_WRITE_PROTECT_NS 0x64 66#define CMD_WRITE_UNPROTECT 0x73 67#define CMD_WRITE_UNPROTECT_NS 0x74 68#define CMD_BUSY 0x76 69#define CMD_ACK 0x79 70#define CMD_READOUT_PROTECT 0x82 71#define CMD_READOUT_PROTECT_NS 0x83 72#define CMD_READOUT_UNPROTECT 0x92 73#define CMD_READOUT_UNPROTECT_NS 0x93 74#define CMD_SOF_ACK 0xA5 75 76#endif /* _STM32_BL_H_ */ 77