mirror of
https://github.com/pine64/blisp.git
synced 2026-09-20 10:31:29 +00:00
Compare commits
64
Commits
v0.0.2
...
error_codes
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5306720e5d | ||
|
|
bac4f4b49f | ||
|
|
6ec0e9e862 | ||
|
|
6e2d40b9c4 | ||
|
|
fced48570a | ||
|
|
179a4ea267 | ||
|
|
de4a9cd5e6 | ||
|
|
0b363c620a | ||
|
|
e7eeef5f85 | ||
|
|
aaf07b7724 | ||
|
|
8c3b93cbec | ||
|
|
cc9ef81934 | ||
|
|
9cb381d03e | ||
|
|
f47bc9f948 | ||
|
|
4b8713ecd4 | ||
|
|
935ee4a12c | ||
|
|
55198e9612 | ||
|
|
63dff45156 | ||
|
|
a98a5090b3 | ||
|
|
55f40caa60 | ||
|
|
7618f24c97 | ||
|
|
fb31f9a742 | ||
|
|
28d0743742 | ||
|
|
042b9a72f0 | ||
|
|
eb55ab4702 | ||
|
|
ca4aca7219 | ||
|
|
6f174eaffe | ||
|
|
a59d4f7a32 | ||
|
|
93703a7c2e | ||
|
|
6f508d3db8 | ||
|
|
565c9ff913 | ||
|
|
e219e50efb | ||
|
|
5a0ae8abc3 | ||
|
|
0275fad1db | ||
|
|
e63ca04be5 | ||
|
|
8c21c18b3a | ||
|
|
23ca06a336 | ||
|
|
5ebcf881b6 | ||
|
|
cda17f2713 | ||
|
|
933851a775 | ||
|
|
32e2a64390 | ||
|
|
c157261bf2 | ||
|
|
b54d820408 | ||
|
|
9d4294f308 | ||
|
|
44f5c12b40 | ||
|
|
f2605801a4 | ||
|
|
670ec95507 | ||
|
|
f8acfa2ac1 | ||
|
|
3d4dfe8b81 | ||
|
|
4afdfff4b7 | ||
|
|
7669ebbbcb | ||
|
|
6424f9ddf8 | ||
|
|
7fb2cc829c | ||
|
|
a67ab9d218 | ||
|
|
3fff531334 | ||
|
|
53b57c3158 | ||
|
|
884142932d | ||
|
|
5e09eca00d | ||
|
|
5a6cd281c3 | ||
|
|
2141e33c2b | ||
|
|
a7c69dbcee | ||
|
|
10b150ee76 | ||
|
|
cbac0733ee | ||
|
|
3325f3725e |
@@ -0,0 +1,66 @@
|
|||||||
|
name: Build
|
||||||
|
on: [push, pull_request]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build-windows:
|
||||||
|
runs-on: windows-2022
|
||||||
|
defaults:
|
||||||
|
run:
|
||||||
|
shell: cmd
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
- uses: lukka/get-cmake@latest
|
||||||
|
- name: Build blisp tool
|
||||||
|
run: |
|
||||||
|
git submodule update --init --recursive
|
||||||
|
mkdir build
|
||||||
|
cd build
|
||||||
|
cmake .. -DBLISP_BUILD_CLI=ON -DCMAKE_BUILD_TYPE=Release
|
||||||
|
cmake --build . --config Release
|
||||||
|
- name: Upload results
|
||||||
|
uses: actions/upload-artifact@v2
|
||||||
|
with:
|
||||||
|
name: blisp Windows x64 build
|
||||||
|
path: |
|
||||||
|
build/tools/blisp/Release/blisp.exe
|
||||||
|
if-no-files-found: error
|
||||||
|
|
||||||
|
build-macos:
|
||||||
|
runs-on: macos-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
- uses: lukka/get-cmake@latest
|
||||||
|
- name: Build blisp tool
|
||||||
|
run: |
|
||||||
|
git submodule update --init --recursive
|
||||||
|
mkdir build
|
||||||
|
cd build
|
||||||
|
cmake .. -DBLISP_BUILD_CLI=ON -DCMAKE_BUILD_TYPE=Release
|
||||||
|
cmake --build .
|
||||||
|
- name: Upload results
|
||||||
|
uses: actions/upload-artifact@v2
|
||||||
|
with:
|
||||||
|
name: blisp macOS x64 build
|
||||||
|
path: |
|
||||||
|
build/tools/blisp/blisp
|
||||||
|
if-no-files-found: error
|
||||||
|
|
||||||
|
build-linux:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
- uses: lukka/get-cmake@latest
|
||||||
|
- name: Build blisp tool
|
||||||
|
run: |
|
||||||
|
git submodule update --init --recursive
|
||||||
|
mkdir build
|
||||||
|
cd build
|
||||||
|
cmake .. -DBLISP_BUILD_CLI=ON -DCMAKE_BUILD_TYPE=Release
|
||||||
|
cmake --build .
|
||||||
|
- name: Upload results
|
||||||
|
uses: actions/upload-artifact@v2
|
||||||
|
with:
|
||||||
|
name: blisp Linux x64 build
|
||||||
|
path: |
|
||||||
|
build/tools/blisp/blisp
|
||||||
|
if-no-files-found: error
|
||||||
+11
-4
@@ -20,30 +20,33 @@ add_library(libblisp_static STATIC $<TARGET_OBJECTS:libblisp_obj>)
|
|||||||
|
|
||||||
set_target_properties(libblisp PROPERTIES
|
set_target_properties(libblisp PROPERTIES
|
||||||
PUBLIC_HEADER "include/blisp.h"
|
PUBLIC_HEADER "include/blisp.h"
|
||||||
VERSION 0.0.2
|
VERSION 0.0.3
|
||||||
SOVERSION 1
|
SOVERSION 1
|
||||||
LIBRARY_OUTPUT_DIRECTORY "shared"
|
LIBRARY_OUTPUT_DIRECTORY "shared"
|
||||||
OUTPUT_NAME "blisp")
|
OUTPUT_NAME "blisp")
|
||||||
|
|
||||||
set_target_properties(libblisp_static PROPERTIES
|
set_target_properties(libblisp_static PROPERTIES
|
||||||
PUBLIC_HEADER "include/blisp.h"
|
PUBLIC_HEADER "include/blisp.h"
|
||||||
VERSION 0.0.2
|
VERSION 0.0.3
|
||||||
SOVERSION 1
|
SOVERSION 1
|
||||||
ARCHIVE_OUTPUT_DIRECTORY "static"
|
ARCHIVE_OUTPUT_DIRECTORY "static"
|
||||||
OUTPUT_NAME "blisp")
|
OUTPUT_NAME "blisp")
|
||||||
|
|
||||||
|
if(NOT ${CMAKE_SYSTEM_NAME} STREQUAL "FreeBSD")
|
||||||
target_sources(libblisp_obj PRIVATE
|
target_sources(libblisp_obj PRIVATE
|
||||||
${CMAKE_SOURCE_DIR}/vendor/libserialport/serialport.c
|
${CMAKE_SOURCE_DIR}/vendor/libserialport/serialport.c
|
||||||
${CMAKE_SOURCE_DIR}/vendor/libserialport/timing.c)
|
${CMAKE_SOURCE_DIR}/vendor/libserialport/timing.c)
|
||||||
|
|
||||||
target_include_directories(libblisp_obj PRIVATE ${CMAKE_SOURCE_DIR}/vendor/libserialport)
|
target_include_directories(libblisp_obj PRIVATE ${CMAKE_SOURCE_DIR}/vendor/libserialport)
|
||||||
|
endif()
|
||||||
|
|
||||||
if(WIN32)
|
if(WIN32)
|
||||||
target_link_libraries(libblisp_obj PRIVATE Setupapi.lib)
|
target_link_libraries(libblisp PRIVATE Setupapi.lib)
|
||||||
|
target_link_libraries(libblisp_static PRIVATE Setupapi.lib)
|
||||||
target_compile_definitions(libblisp_obj PRIVATE LIBSERIALPORT_MSBUILD)
|
target_compile_definitions(libblisp_obj PRIVATE LIBSERIALPORT_MSBUILD)
|
||||||
target_sources(libblisp_obj PRIVATE
|
target_sources(libblisp_obj PRIVATE
|
||||||
${CMAKE_SOURCE_DIR}/vendor/libserialport/windows.c)
|
${CMAKE_SOURCE_DIR}/vendor/libserialport/windows.c)
|
||||||
elseif(UNIX AND NOT APPLE)
|
elseif(UNIX AND NOT APPLE AND NOT ${CMAKE_SYSTEM_NAME} STREQUAL "FreeBSD")
|
||||||
target_sources(libblisp_obj PRIVATE
|
target_sources(libblisp_obj PRIVATE
|
||||||
${CMAKE_SOURCE_DIR}/vendor/libserialport/linux.c
|
${CMAKE_SOURCE_DIR}/vendor/libserialport/linux.c
|
||||||
${CMAKE_SOURCE_DIR}/vendor/libserialport/linux_termios.c)
|
${CMAKE_SOURCE_DIR}/vendor/libserialport/linux_termios.c)
|
||||||
@@ -55,6 +58,10 @@ elseif(UNIX AND NOT APPLE)
|
|||||||
"SP_API=__attribute__((visibility(\"default\")))"
|
"SP_API=__attribute__((visibility(\"default\")))"
|
||||||
"SP_PRIV=__attribute__((visibility(\"hidden\")))")
|
"SP_PRIV=__attribute__((visibility(\"hidden\")))")
|
||||||
write_file(${CMAKE_SOURCE_DIR}/vendor/libserialport/config.h "// bypass errors.")
|
write_file(${CMAKE_SOURCE_DIR}/vendor/libserialport/config.h "// bypass errors.")
|
||||||
|
elseif(UNIX AND ${CMAKE_SYSTEM_NAME} STREQUAL "FreeBSD")
|
||||||
|
target_include_directories(libblisp_obj PRIVATE /usr/local/include/)
|
||||||
|
target_link_libraries(libblisp PRIVATE -L/usr/local/lib usb serialport)
|
||||||
|
target_link_libraries(libblisp_static PRIVATE -L/usr/local/lib usb serialport)
|
||||||
elseif(APPLE)
|
elseif(APPLE)
|
||||||
target_sources(libblisp_obj PRIVATE
|
target_sources(libblisp_obj PRIVATE
|
||||||
${CMAKE_SOURCE_DIR}/vendor/libserialport/macosx.c)
|
${CMAKE_SOURCE_DIR}/vendor/libserialport/macosx.c)
|
||||||
|
|||||||
@@ -1,34 +1,51 @@
|
|||||||
# Bouffalo Labs ISP tool & library
|
[](https://github.com/pine64/blisp/wiki/Update-Pinecil-V2)
|
||||||
|
[](https://github.com/pine64/blisp/releases/tag/v0.0.3)
|
||||||
|
[](https://discord.com/invite/pine64)
|
||||||
|
[](https://github.com/pine64/blisp/releases/tag/v0.0.3)
|
||||||
|
|
||||||
Open source tool and library for flashing Bouffalo RISC-V MCUs.
|
<img src="./img/Gradient-white-blue-03.png" align="left" width="60" > <br clear="left" />
|
||||||
|
# BLISP
|
||||||
|
|
||||||
|
Bouffalo Labs ISP (in-system-programming) tool & library: an open source tool to flash Bouffalo RISC-V MCUs.
|
||||||
|
|
||||||
**NOTE:** Library API and `blisp` tool cli arguments are not stable yet.
|
**NOTE:** Library API and `blisp` tool cli arguments are not stable yet.
|
||||||
|
<br>
|
||||||
|
|
||||||
# Supported MCUs
|
## Supported MCUs
|
||||||
|
- [x] `bl60x` - BL602 / BL604 / TG7100C / LF686 / LF688
|
||||||
- [x] `bl60x` - BL602 / BL604
|
|
||||||
- [x] `bl70x` - BL702 / BL704 / BL706
|
- [x] `bl70x` - BL702 / BL704 / BL706
|
||||||
- [ ] `bl606p` - BL606P
|
<br>
|
||||||
- [ ] `bl61x` - BL616 / BL618
|
|
||||||
- [ ] `bl808` - BL808
|
|
||||||
|
|
||||||
# Supported OS
|
## Supported Devices
|
||||||
- [x] Windows
|
| System | <img width="15" src="https://cdn.simpleicons.org/Windows11/5791ac" /> Windows | <img width="15" src="https://cdn.simpleicons.org/Apple/5791ac" /> MacOS| <img width="17" src="https://cdn.simpleicons.org/Linux/5791ac" /> Linux| <img width="15" src="https://cdn.simpleicons.org/Freebsd/5791ac" /> FreeBSD |
|
||||||
- [x] Linux
|
| :-----: | :------: | :------: | :------: | :------: |
|
||||||
- [ ] Apple (WIP: work-in-progress)
|
| Pinecil V2 |<img width="22" src="https://cdn.simpleicons.org/cachet/5791ac" />|<img width="22" src="https://cdn.simpleicons.org/cachet/5791ac" />| <img width="22" src="https://cdn.simpleicons.org/cachet/5791ac" />| <img width="22" src="https://cdn.simpleicons.org/cachet/5791ac" /> |
|
||||||
|
| Pinecone |<img width="22" src="https://cdn.simpleicons.org/cachet/5791ac" />|<img width="22" src="https://cdn.simpleicons.org/cachet/5791ac" />|<img width="22" src="https://cdn.simpleicons.org/cachet/5791ac" />| <img width="22" src="https://cdn.simpleicons.org/cachet/5791ac" /> |
|
||||||
|
<br>
|
||||||
|
|
||||||
|
## How to update Pinecil V2
|
||||||
|
|
||||||
# Building
|
Download the newest release of [Blisp updater here](https://github.com/pine64/blisp/releases/).
|
||||||
|
|
||||||
## Clone repository
|
Check out the [wiki page](https://github.com/pine64/blisp/wiki/Update-Pinecil-V2) for install instructions.
|
||||||
|
<br><br>
|
||||||
|
|
||||||
|
## Building from code
|
||||||
|
|
||||||
|
### Clone repository
|
||||||
|
|
||||||
If you have not cloned this repository locally; clone the git repository locally by running
|
If you have not cloned this repository locally; clone the git repository locally by running
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
git clone --recursive https://github.com/pine64/blisp.git
|
git clone --recursive https://github.com/pine64/blisp.git
|
||||||
cd blisp
|
cd blisp
|
||||||
|
git submodule update --init --recursive
|
||||||
```
|
```
|
||||||
|
|
||||||
## Build the library and command line utility
|
If vendor/argtable3 and vendor/libserialport/ are empty, this last step has
|
||||||
|
failed and should be investigated.
|
||||||
|
|
||||||
|
### Build the library and command line utility
|
||||||
|
|
||||||
For building `blisp` command line tool, use following commands:
|
For building `blisp` command line tool, use following commands:
|
||||||
|
|
||||||
@@ -37,21 +54,33 @@ mkdir build && cd build
|
|||||||
cmake -DBLISP_BUILD_CLI=ON ..
|
cmake -DBLISP_BUILD_CLI=ON ..
|
||||||
cmake --build .
|
cmake --build .
|
||||||
```
|
```
|
||||||
|
#### Need more build details? [See here](https://github.com/pine64/blisp/wiki/Update-Pinecil-V2#build-blisp-flasher-from-code).
|
||||||
|
|
||||||
# Usage
|
## Usage
|
||||||
|
|
||||||
For BL70X, BL61X, BL808 and BL606P, connected via USB, you can use following command, which will auto-detect serial port:
|
For BL70X, BL61X, BL808 and BL606P, connected via USB, you can use following command, which will auto-detect serial port on Windows:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
blisp write --chip bl70x --reset name_of_firmware.bin
|
.\blisp.exe write --chip=bl70x --reset .\name_of_firmware.bin
|
||||||
|
or
|
||||||
|
.\blisp.exe write -c bl70x --reset .\name_of_firmware.bin
|
||||||
```
|
```
|
||||||
|
|
||||||
For BL60X, you need to specify also the serial port path:
|
For BL60X, you need to specify also the serial port path:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
blisp --chip bl60x --reset -p /dev/ttyUSB0 name_of_firmware.bin
|
blisp write --chip bl60x --reset -p /dev/ttyUSB0 name_of_firmware.bin
|
||||||
```
|
```
|
||||||
|
|
||||||
# How to flash Pinecil V2
|
If you wish to see additional debugging, set the environmental
|
||||||
|
variable LIBSERIALPORT_DEBUG before running. You can either export this
|
||||||
|
in your shell or change it for a single run via
|
||||||
|
|
||||||
Check out the [wiki page](https://github.com/pine64/blisp/wiki/Update-Pinecil-V2).
|
```bash
|
||||||
|
LIBSERIALPORT_DEBUG=y ./a.out write -c bl70x -p /dev/tty.usbmodem0000000200001
|
||||||
|
```
|
||||||
|
|
||||||
|
Because this is done at the lowest level of serial communication, the
|
||||||
|
displays aren't packet-aware or know about the chip's command set or such.
|
||||||
|
This is really only useful for debugging systems-level issues withing
|
||||||
|
the device or blisp itself.
|
||||||
|
|||||||
Binary file not shown.
|
After Width: | Height: | Size: 30 KiB |
+1
-13
@@ -3,20 +3,8 @@
|
|||||||
#define _LIBBLISP_H
|
#define _LIBBLISP_H
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
#include "blisp_chip.h"
|
#include "blisp_chip.h"
|
||||||
|
#include "error_codes.h"
|
||||||
enum blisp_return {
|
|
||||||
BLISP_OK = 0,
|
|
||||||
BLISP_ERR_UNKNOWN = -1,
|
|
||||||
BLISP_ERR_NO_RESPONSE = -2,
|
|
||||||
BLISP_ERR_DEVICE_NOT_FOUND = -3,
|
|
||||||
BLISP_ERR_CANT_OPEN_DEVICE = -4,
|
|
||||||
// Can't auto-find device due it doesn't have native USB
|
|
||||||
BLISP_ERR_NO_AUTO_FIND_AVAILABLE = -5,
|
|
||||||
BLISP_ERR_PENDING = -6,
|
|
||||||
BLISP_ERR_CHIP_ERR = -7
|
|
||||||
};
|
|
||||||
|
|
||||||
struct blisp_segment_header {
|
struct blisp_segment_header {
|
||||||
uint32_t dest_addr;
|
uint32_t dest_addr;
|
||||||
|
|||||||
@@ -0,0 +1,30 @@
|
|||||||
|
#ifndef BLISP_S_RC_ERROR_CODES_H_
|
||||||
|
#define BLISP_S_RC_ERROR_CODES_H_
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
BLISP_OK = 0,
|
||||||
|
// All error states must be <0.
|
||||||
|
// Generic error return; for when we are unsure what failed
|
||||||
|
BLISP_ERR_UNKNOWN = -1,
|
||||||
|
// Device did not respond, if serial link, could be that its not in boot
|
||||||
|
// loader
|
||||||
|
BLISP_ERR_NO_RESPONSE = -2,
|
||||||
|
// Failed to open a device, likely libusb or permissions
|
||||||
|
BLISP_ERR_DEVICE_NOT_FOUND = -3, // We could not find a device
|
||||||
|
BLISP_ERR_CANT_OPEN_DEVICE =
|
||||||
|
-4, // Couldn't open device; could it be permissions or its in use?
|
||||||
|
// Can't auto-find device due it doesn't have native USB
|
||||||
|
BLISP_ERR_NO_AUTO_FIND_AVAILABLE = -5,
|
||||||
|
BLISP_ERR_PENDING = -6, // Internal error for device is busy and to come back
|
||||||
|
BLISP_ERR_CHIP_ERR = -7, // Chip returned an error to us
|
||||||
|
BLISP_ERR_INVALID_CHIP_TYPE = -8, // unsupported chip type provided
|
||||||
|
BLISP_ERR_OUT_OF_MEMORY =
|
||||||
|
-9, // System could not allocate enough ram (highly unlikely)
|
||||||
|
BLISP_ERR_INVALID_COMMAND = -10, // Invalid user command provided
|
||||||
|
BLISP_ERR_CANT_OPEN_FILE = -11, // Cant open the firmware file to flash
|
||||||
|
BLISP_ERR_NOT_IMPLEMENTED = -12, // Non implemented function called
|
||||||
|
BLISP_ERR_API_ERROR = -13, // Errors outside our control from api's we
|
||||||
|
// integrate (Generally serial port/OS related)
|
||||||
|
|
||||||
|
} blisp_return_t;
|
||||||
|
#endif
|
||||||
+75
-61
@@ -13,15 +13,22 @@
|
|||||||
|
|
||||||
#define DEBUG
|
#define DEBUG
|
||||||
|
|
||||||
int32_t blisp_device_init(struct blisp_device* device,
|
static void drain(struct sp_port* port) {
|
||||||
struct blisp_chip* chip) {
|
#if defined(__APPLE__) || defined(__FreeBSD__)
|
||||||
device->chip = chip;
|
sp_drain(port);
|
||||||
device->is_usb = false;
|
#endif
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t blisp_device_open(struct blisp_device* device, const char* port_name) {
|
blisp_return_t blisp_device_init(struct blisp_device* device,
|
||||||
int ret;
|
struct blisp_chip* chip) {
|
||||||
|
device->chip = chip;
|
||||||
|
device->is_usb = false;
|
||||||
|
return BLISP_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
blisp_return_t blisp_device_open(struct blisp_device* device,
|
||||||
|
const char* port_name) {
|
||||||
|
blisp_return_t ret;
|
||||||
struct sp_port* serial_port = NULL;
|
struct sp_port* serial_port = NULL;
|
||||||
|
|
||||||
if (port_name != NULL) {
|
if (port_name != NULL) {
|
||||||
@@ -38,7 +45,7 @@ int32_t blisp_device_open(struct blisp_device* device, const char* port_name) {
|
|||||||
ret = sp_list_ports(&port_list);
|
ret = sp_list_ports(&port_list);
|
||||||
if (ret != SP_OK) {
|
if (ret != SP_OK) {
|
||||||
blisp_dlog("Couldn't list ports, err: %d", ret);
|
blisp_dlog("Couldn't list ports, err: %d", ret);
|
||||||
return BLISP_ERR_UNKNOWN;
|
return BLISP_ERR_DEVICE_NOT_FOUND;
|
||||||
}
|
}
|
||||||
for (int i = 0; port_list[i] != NULL; i++) {
|
for (int i = 0; port_list[i] != NULL; i++) {
|
||||||
struct sp_port* port = port_list[i];
|
struct sp_port* port = port_list[i];
|
||||||
@@ -63,8 +70,7 @@ int32_t blisp_device_open(struct blisp_device* device, const char* port_name) {
|
|||||||
ret = sp_open(serial_port, SP_MODE_READ_WRITE);
|
ret = sp_open(serial_port, SP_MODE_READ_WRITE);
|
||||||
if (ret != SP_OK) {
|
if (ret != SP_OK) {
|
||||||
blisp_dlog("SP open failed: %d", ret);
|
blisp_dlog("SP open failed: %d", ret);
|
||||||
return BLISP_ERR_UNKNOWN; // TODO: Maybe this should be that it can't open
|
return BLISP_ERR_CANT_OPEN_DEVICE;
|
||||||
// device?
|
|
||||||
}
|
}
|
||||||
// TODO: Handle errors in following functions, although, none of them *should*
|
// TODO: Handle errors in following functions, although, none of them *should*
|
||||||
// fail
|
// fail
|
||||||
@@ -73,13 +79,13 @@ int32_t blisp_device_open(struct blisp_device* device, const char* port_name) {
|
|||||||
sp_set_stopbits(serial_port, 1);
|
sp_set_stopbits(serial_port, 1);
|
||||||
sp_set_flowcontrol(serial_port, SP_FLOWCONTROL_NONE);
|
sp_set_flowcontrol(serial_port, SP_FLOWCONTROL_NONE);
|
||||||
|
|
||||||
uint32_t vid, pid;
|
int vid, pid;
|
||||||
sp_get_port_usb_vid_pid(serial_port, &vid, &pid);
|
sp_get_port_usb_vid_pid(serial_port, &vid, &pid);
|
||||||
device->is_usb = pid == 0xFFFF;
|
device->is_usb = pid == 0xFFFF;
|
||||||
// if (device->is_usb) {
|
// if (device->is_usb) {
|
||||||
// device->current_baud_rate = 2000000;
|
// device->current_baud_rate = 2000000;
|
||||||
// } else {
|
// } else {
|
||||||
device->current_baud_rate = 500000;
|
device->current_baud_rate = 460800;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
@@ -93,19 +99,19 @@ int32_t blisp_device_open(struct blisp_device* device, const char* port_name) {
|
|||||||
#endif
|
#endif
|
||||||
ret = sp_set_baudrate(serial_port, device->current_baud_rate);
|
ret = sp_set_baudrate(serial_port, device->current_baud_rate);
|
||||||
if (ret != SP_OK) {
|
if (ret != SP_OK) {
|
||||||
blisp_dlog("Set baud rate failed: %d... Also hello macOS user :)", ret);
|
blisp_dlog("Set baud rate failed: %d... Also hello MacOS user :)", ret);
|
||||||
return BLISP_ERR_UNKNOWN;
|
return BLISP_ERR_API_ERROR;
|
||||||
}
|
}
|
||||||
device->serial_port = serial_port;
|
device->serial_port = serial_port;
|
||||||
|
|
||||||
return BLISP_OK;
|
return BLISP_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t blisp_send_command(struct blisp_device* device,
|
blisp_return_t blisp_send_command(struct blisp_device* device,
|
||||||
uint8_t command,
|
uint8_t command,
|
||||||
void* payload,
|
void* payload,
|
||||||
uint16_t payload_size,
|
uint16_t payload_size,
|
||||||
bool add_checksum) {
|
bool add_checksum) {
|
||||||
int ret;
|
int ret;
|
||||||
struct sp_port* serial_port = device->serial_port;
|
struct sp_port* serial_port = device->serial_port;
|
||||||
|
|
||||||
@@ -128,20 +134,22 @@ int32_t blisp_send_command(struct blisp_device* device,
|
|||||||
sp_blocking_write(serial_port, device->tx_buffer, 4 + payload_size, 1000);
|
sp_blocking_write(serial_port, device->tx_buffer, 4 + payload_size, 1000);
|
||||||
if (ret != (4 + payload_size)) {
|
if (ret != (4 + payload_size)) {
|
||||||
blisp_dlog("Received error or not written all data: %d", ret);
|
blisp_dlog("Received error or not written all data: %d", ret);
|
||||||
return BLISP_ERR_UNKNOWN;
|
return BLISP_ERR_API_ERROR;
|
||||||
}
|
}
|
||||||
|
drain(serial_port);
|
||||||
|
|
||||||
return BLISP_OK;
|
return BLISP_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t blisp_receive_response(struct blisp_device* device,
|
blisp_return_t blisp_receive_response(struct blisp_device* device,
|
||||||
bool expect_payload) {
|
bool expect_payload) {
|
||||||
// TODO: Check checksum
|
// TODO: Check checksum
|
||||||
int ret;
|
int ret;
|
||||||
struct sp_port* serial_port = device->serial_port;
|
struct sp_port* serial_port = device->serial_port;
|
||||||
ret = sp_blocking_read(serial_port, &device->rx_buffer[0], 2, 1000);
|
ret = sp_blocking_read(serial_port, &device->rx_buffer[0], 2, 1000);
|
||||||
if (ret < 2) {
|
if (ret < 2) {
|
||||||
blisp_dlog("Failed to receive response, ret: %d", ret);
|
blisp_dlog("Failed to receive response, ret: %d", ret);
|
||||||
return BLISP_ERR_UNKNOWN; // TODO: Terrible
|
return BLISP_ERR_NO_RESPONSE;
|
||||||
} else if (device->rx_buffer[0] == 'O' && device->rx_buffer[1] == 'K') {
|
} else if (device->rx_buffer[0] == 'O' && device->rx_buffer[1] == 'K') {
|
||||||
if (expect_payload) {
|
if (expect_payload) {
|
||||||
sp_blocking_read(serial_port, &device->rx_buffer[2], 2,
|
sp_blocking_read(serial_port, &device->rx_buffer[2], 2,
|
||||||
@@ -163,10 +171,11 @@ int32_t blisp_receive_response(struct blisp_device* device,
|
|||||||
}
|
}
|
||||||
blisp_dlog("Failed to receive any response (err: %d, %d - %d)", ret,
|
blisp_dlog("Failed to receive any response (err: %d, %d - %d)", ret,
|
||||||
device->rx_buffer[0], device->rx_buffer[1]);
|
device->rx_buffer[0], device->rx_buffer[1]);
|
||||||
return BLISP_ERR_UNKNOWN;
|
return BLISP_ERR_NO_RESPONSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t blisp_device_handshake(struct blisp_device* device, bool in_ef_loader) {
|
blisp_return_t blisp_device_handshake(struct blisp_device* device,
|
||||||
|
bool in_ef_loader) {
|
||||||
int ret;
|
int ret;
|
||||||
uint8_t handshake_buffer[600];
|
uint8_t handshake_buffer[600];
|
||||||
struct sp_port* serial_port = device->serial_port;
|
struct sp_port* serial_port = device->serial_port;
|
||||||
@@ -191,12 +200,15 @@ int32_t blisp_device_handshake(struct blisp_device* device, bool in_ef_loader) {
|
|||||||
if (!in_ef_loader) {
|
if (!in_ef_loader) {
|
||||||
if (device->is_usb) {
|
if (device->is_usb) {
|
||||||
sp_blocking_write(serial_port, "BOUFFALOLAB5555RESET\0\0", 22, 100);
|
sp_blocking_write(serial_port, "BOUFFALOLAB5555RESET\0\0", 22, 100);
|
||||||
|
drain(serial_port);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ret = sp_blocking_write(serial_port, handshake_buffer, bytes_count, 500);
|
ret = sp_blocking_write(serial_port, handshake_buffer, bytes_count, 500);
|
||||||
|
// not sure about Apple part, but FreeBSD needs it
|
||||||
|
drain(serial_port);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
blisp_dlog("Handshake write failed, ret %d", ret);
|
blisp_dlog("Handshake write failed, ret %d", ret);
|
||||||
return BLISP_ERR_UNKNOWN;
|
return BLISP_ERR_API_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!in_ef_loader && !device->is_usb) {
|
if (!in_ef_loader && !device->is_usb) {
|
||||||
@@ -215,9 +227,9 @@ int32_t blisp_device_handshake(struct blisp_device* device, bool in_ef_loader) {
|
|||||||
return BLISP_ERR_NO_RESPONSE;
|
return BLISP_ERR_NO_RESPONSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t blisp_device_get_boot_info(struct blisp_device* device,
|
blisp_return_t blisp_device_get_boot_info(struct blisp_device* device,
|
||||||
struct blisp_boot_info* boot_info) {
|
struct blisp_boot_info* boot_info) {
|
||||||
int ret;
|
blisp_return_t ret;
|
||||||
|
|
||||||
ret = blisp_send_command(device, 0x10, NULL, 0, false);
|
ret = blisp_send_command(device, 0x10, NULL, 0, false);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
@@ -228,7 +240,8 @@ int32_t blisp_device_get_boot_info(struct blisp_device* device,
|
|||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
memcpy(boot_info->boot_rom_version, &device->rx_buffer[0],
|
memcpy(boot_info->boot_rom_version, &device->rx_buffer[0],
|
||||||
4); // TODO: Endianess
|
4); // TODO: Endianess; this may break on big endian machines
|
||||||
|
|
||||||
if (device->chip->type == BLISP_CHIP_BL70X) {
|
if (device->chip->type == BLISP_CHIP_BL70X) {
|
||||||
memcpy(boot_info->chip_id, &device->rx_buffer[16], 8);
|
memcpy(boot_info->chip_id, &device->rx_buffer[16], 8);
|
||||||
}
|
}
|
||||||
@@ -237,9 +250,9 @@ int32_t blisp_device_get_boot_info(struct blisp_device* device,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Use struct instead of uint8_t*
|
// TODO: Use struct instead of uint8_t*
|
||||||
int32_t blisp_device_load_boot_header(struct blisp_device* device,
|
blisp_return_t blisp_device_load_boot_header(struct blisp_device* device,
|
||||||
uint8_t* boot_header) {
|
uint8_t* boot_header) {
|
||||||
int ret;
|
blisp_return_t ret;
|
||||||
ret = blisp_send_command(device, 0x11, boot_header, 176, false);
|
ret = blisp_send_command(device, 0x11, boot_header, 176, false);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
return ret;
|
return ret;
|
||||||
@@ -250,10 +263,10 @@ int32_t blisp_device_load_boot_header(struct blisp_device* device,
|
|||||||
return BLISP_OK;
|
return BLISP_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t blisp_device_load_segment_header(
|
blisp_return_t blisp_device_load_segment_header(
|
||||||
struct blisp_device* device,
|
struct blisp_device* device,
|
||||||
struct blisp_segment_header* segment_header) {
|
struct blisp_segment_header* segment_header) {
|
||||||
int ret;
|
blisp_return_t ret;
|
||||||
ret = blisp_send_command(device, 0x17, segment_header, 16, false);
|
ret = blisp_send_command(device, 0x17, segment_header, 16, false);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
return ret;
|
return ret;
|
||||||
@@ -264,10 +277,10 @@ int32_t blisp_device_load_segment_header(
|
|||||||
return BLISP_OK;
|
return BLISP_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t blisp_device_load_segment_data(struct blisp_device* device,
|
blisp_return_t blisp_device_load_segment_data(struct blisp_device* device,
|
||||||
uint8_t* segment_data,
|
uint8_t* segment_data,
|
||||||
uint32_t segment_data_length) {
|
uint32_t segment_data_length) {
|
||||||
int ret;
|
blisp_return_t ret;
|
||||||
ret = blisp_send_command(device, 0x18, segment_data, segment_data_length,
|
ret = blisp_send_command(device, 0x18, segment_data, segment_data_length,
|
||||||
false);
|
false);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
@@ -279,8 +292,8 @@ int32_t blisp_device_load_segment_data(struct blisp_device* device,
|
|||||||
return BLISP_OK;
|
return BLISP_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t blisp_device_check_image(struct blisp_device* device) {
|
blisp_return_t blisp_device_check_image(struct blisp_device* device) {
|
||||||
int ret;
|
blisp_return_t ret;
|
||||||
ret = blisp_send_command(device, 0x19, NULL, 0, false);
|
ret = blisp_send_command(device, 0x19, NULL, 0, false);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
return ret;
|
return ret;
|
||||||
@@ -291,11 +304,11 @@ int32_t blisp_device_check_image(struct blisp_device* device) {
|
|||||||
return BLISP_OK;
|
return BLISP_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t blisp_device_write_memory(struct blisp_device* device,
|
blisp_return_t blisp_device_write_memory(struct blisp_device* device,
|
||||||
uint32_t address,
|
uint32_t address,
|
||||||
uint32_t value,
|
uint32_t value,
|
||||||
bool wait_for_res) {
|
bool wait_for_res) {
|
||||||
int ret;
|
blisp_return_t ret;
|
||||||
uint8_t payload[8];
|
uint8_t payload[8];
|
||||||
*(uint32_t*)(payload) = address;
|
*(uint32_t*)(payload) = address;
|
||||||
*(uint32_t*)(payload + 4) = value; // TODO: Endianness
|
*(uint32_t*)(payload + 4) = value; // TODO: Endianness
|
||||||
@@ -311,8 +324,8 @@ int32_t blisp_device_write_memory(struct blisp_device* device,
|
|||||||
return BLISP_OK;
|
return BLISP_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t blisp_device_run_image(struct blisp_device* device) {
|
blisp_return_t blisp_device_run_image(struct blisp_device* device) {
|
||||||
int ret;
|
blisp_return_t ret;
|
||||||
|
|
||||||
if (device->chip->type == BLISP_CHIP_BL70X) { // ERRATA
|
if (device->chip->type == BLISP_CHIP_BL70X) { // ERRATA
|
||||||
ret = blisp_device_write_memory(device, 0x4000F100, 0x4E424845, true);
|
ret = blisp_device_write_memory(device, 0x4000F100, 0x4E424845, true);
|
||||||
@@ -339,14 +352,14 @@ int32_t blisp_device_run_image(struct blisp_device* device) {
|
|||||||
return BLISP_OK;
|
return BLISP_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t blisp_device_flash_erase(struct blisp_device* device,
|
blisp_return_t blisp_device_flash_erase(struct blisp_device* device,
|
||||||
uint32_t start_address,
|
uint32_t start_address,
|
||||||
uint32_t end_address) {
|
uint32_t end_address) {
|
||||||
uint8_t payload[8];
|
uint8_t payload[8];
|
||||||
*(uint32_t*)(payload + 0) = start_address;
|
*(uint32_t*)(payload + 0) = start_address;
|
||||||
*(uint32_t*)(payload + 4) = end_address;
|
*(uint32_t*)(payload + 4) = end_address;
|
||||||
|
|
||||||
int ret = blisp_send_command(device, 0x30, payload, 8, true);
|
blisp_return_t ret = blisp_send_command(device, 0x30, payload, 8, true);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
return ret;
|
return ret;
|
||||||
do {
|
do {
|
||||||
@@ -356,17 +369,18 @@ int32_t blisp_device_flash_erase(struct blisp_device* device,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t blisp_device_flash_write(struct blisp_device* device,
|
blisp_return_t blisp_device_flash_write(struct blisp_device* device,
|
||||||
uint32_t start_address,
|
uint32_t start_address,
|
||||||
uint8_t* payload,
|
uint8_t* payload,
|
||||||
uint32_t payload_size) {
|
uint32_t payload_size) {
|
||||||
// TODO: Add max payload size (8184?)
|
// TODO: Add max payload size (8184?)
|
||||||
// TODO: Don't use malloc + add check
|
// TODO: Don't use malloc + add check
|
||||||
|
|
||||||
uint8_t* buffer = malloc(4 + payload_size);
|
uint8_t* buffer = malloc(4 + payload_size);
|
||||||
*((uint32_t*)(buffer)) = start_address;
|
*((uint32_t*)(buffer)) = start_address;
|
||||||
memcpy(buffer + 4, payload, payload_size);
|
memcpy(buffer + 4, payload, payload_size);
|
||||||
int ret = blisp_send_command(device, 0x31, buffer, payload_size + 4, true);
|
blisp_return_t ret =
|
||||||
|
blisp_send_command(device, 0x31, buffer, payload_size + 4, true);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
goto exit1;
|
goto exit1;
|
||||||
ret = blisp_receive_response(device, false);
|
ret = blisp_receive_response(device, false);
|
||||||
@@ -375,7 +389,7 @@ exit1:
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t blisp_device_program_check(struct blisp_device* device) {
|
blisp_return_t blisp_device_program_check(struct blisp_device* device) {
|
||||||
int ret = blisp_send_command(device, 0x3A, NULL, 0, true);
|
int ret = blisp_send_command(device, 0x3A, NULL, 0, true);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
return ret;
|
return ret;
|
||||||
@@ -383,11 +397,11 @@ int32_t blisp_device_program_check(struct blisp_device* device) {
|
|||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
return 0;
|
return BLISP_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t blisp_device_reset(struct blisp_device* device) {
|
blisp_return_t blisp_device_reset(struct blisp_device* device) {
|
||||||
int ret = blisp_send_command(device, 0x21, NULL, 0, true);
|
blisp_return_t ret = blisp_send_command(device, 0x21, NULL, 0, true);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
return ret;
|
return ret;
|
||||||
ret = blisp_receive_response(device, false);
|
ret = blisp_receive_response(device, false);
|
||||||
|
|||||||
+46
-21
@@ -6,12 +6,16 @@
|
|||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
static int64_t blisp_easy_transport_read(struct blisp_easy_transport* transport,
|
static blisp_return_t blisp_easy_transport_read(
|
||||||
void* buffer,
|
struct blisp_easy_transport* transport,
|
||||||
uint32_t size) {
|
void* buffer,
|
||||||
|
uint32_t size) {
|
||||||
if (transport->type == 0) {
|
if (transport->type == 0) {
|
||||||
// TODO: Implement reading more than available
|
// TODO: Implement reading more than available
|
||||||
memcpy(buffer, (uint8_t*)transport->data.memory.data_location + transport->data.memory.current_position, size);
|
memcpy(buffer,
|
||||||
|
(uint8_t*)transport->data.memory.data_location +
|
||||||
|
transport->data.memory.current_position,
|
||||||
|
size);
|
||||||
transport->data.memory.current_position += size;
|
transport->data.memory.current_position += size;
|
||||||
return size;
|
return size;
|
||||||
} else {
|
} else {
|
||||||
@@ -19,11 +23,14 @@ static int64_t blisp_easy_transport_read(struct blisp_easy_transport* transport,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int64_t blisp_easy_transport_size(struct blisp_easy_transport* transport) {
|
static blisp_return_t blisp_easy_transport_size(
|
||||||
|
struct blisp_easy_transport* transport) {
|
||||||
if (transport->type == 0) {
|
if (transport->type == 0) {
|
||||||
return transport->data.memory.data_size;
|
return transport->data.memory.data_size;
|
||||||
} else {
|
} else {
|
||||||
// TODO: Implement
|
// TODO: Implement
|
||||||
|
printf("%s() Warning: calling non-implemented function\n", __func__);
|
||||||
|
return BLISP_ERR_NOT_IMPLEMENTED;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -57,17 +64,26 @@ int32_t blisp_easy_load_segment_data(
|
|||||||
struct blisp_easy_transport* segment_transport,
|
struct blisp_easy_transport* segment_transport,
|
||||||
blisp_easy_progress_callback progress_callback) {
|
blisp_easy_progress_callback progress_callback) {
|
||||||
int32_t ret;
|
int32_t ret;
|
||||||
|
#ifdef __APPLE__
|
||||||
|
const uint16_t buffer_max_size = 252 * 16;
|
||||||
|
#else
|
||||||
|
const uint16_t buffer_max_size = 4092;
|
||||||
|
#endif
|
||||||
|
|
||||||
uint32_t sent_data = 0;
|
uint32_t sent_data = 0;
|
||||||
uint32_t buffer_size = 0;
|
uint32_t buffer_size = 0;
|
||||||
|
#ifdef _WIN32
|
||||||
uint8_t buffer[4092];
|
uint8_t buffer[4092];
|
||||||
|
#else
|
||||||
|
uint8_t buffer[buffer_max_size];
|
||||||
|
#endif
|
||||||
|
|
||||||
blisp_easy_report_progress(progress_callback, 0, segment_size);
|
blisp_easy_report_progress(progress_callback, 0, segment_size);
|
||||||
|
|
||||||
while (sent_data < segment_size) {
|
while (sent_data < segment_size) {
|
||||||
buffer_size = segment_size - sent_data;
|
buffer_size = segment_size - sent_data;
|
||||||
if (buffer_size > 4092) {
|
if (buffer_size > buffer_max_size) {
|
||||||
buffer_size = 4092;
|
buffer_size = buffer_max_size;
|
||||||
}
|
}
|
||||||
blisp_easy_transport_read(segment_transport, buffer,
|
blisp_easy_transport_read(segment_transport, buffer,
|
||||||
buffer_size); // TODO: Error Handling
|
buffer_size); // TODO: Error Handling
|
||||||
@@ -80,7 +96,7 @@ int32_t blisp_easy_load_segment_data(
|
|||||||
sent_data += buffer_size;
|
sent_data += buffer_size;
|
||||||
blisp_easy_report_progress(progress_callback, sent_data, segment_size);
|
blisp_easy_report_progress(progress_callback, sent_data, segment_size);
|
||||||
}
|
}
|
||||||
return 0;
|
return BLISP_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t blisp_easy_load_ram_image(
|
int32_t blisp_easy_load_ram_image(
|
||||||
@@ -131,10 +147,10 @@ int32_t blisp_easy_load_ram_image(
|
|||||||
return BLISP_OK;
|
return BLISP_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t blisp_easy_load_ram_app(struct blisp_device* device,
|
int32_t blisp_easy_load_ram_app(
|
||||||
struct blisp_easy_transport* app_transport,
|
struct blisp_device* device,
|
||||||
blisp_easy_progress_callback progress_callback)
|
struct blisp_easy_transport* app_transport,
|
||||||
{
|
blisp_easy_progress_callback progress_callback) {
|
||||||
int32_t ret;
|
int32_t ret;
|
||||||
// TODO: Rework
|
// TODO: Rework
|
||||||
// region boot header fill
|
// region boot header fill
|
||||||
@@ -281,7 +297,6 @@ int32_t blisp_easy_load_ram_app(struct blisp_device* device,
|
|||||||
boot_header.crc32 = 0xDEADBEEF;
|
boot_header.crc32 = 0xDEADBEEF;
|
||||||
// endregion
|
// endregion
|
||||||
|
|
||||||
|
|
||||||
ret = blisp_device_load_boot_header(device, (uint8_t*)&boot_header);
|
ret = blisp_device_load_boot_header(device, (uint8_t*)&boot_header);
|
||||||
if (ret != BLISP_OK) {
|
if (ret != BLISP_OK) {
|
||||||
blisp_dlog("Failed to load boot header, ret: %d.", ret);
|
blisp_dlog("Failed to load boot header, ret: %d.", ret);
|
||||||
@@ -292,9 +307,9 @@ int32_t blisp_easy_load_ram_app(struct blisp_device* device,
|
|||||||
.dest_addr = device->chip->tcm_address,
|
.dest_addr = device->chip->tcm_address,
|
||||||
.length = blisp_easy_transport_size(app_transport),
|
.length = blisp_easy_transport_size(app_transport),
|
||||||
.reserved = 0,
|
.reserved = 0,
|
||||||
.crc32 = 0
|
.crc32 = 0};
|
||||||
};
|
segment_header.crc32 = crc32_calculate(
|
||||||
segment_header.crc32 = crc32_calculate(&segment_header, 3 * sizeof(uint32_t)); // TODO: Make function
|
&segment_header, 3 * sizeof(uint32_t)); // TODO: Make function
|
||||||
|
|
||||||
ret = blisp_device_load_segment_header(device, &segment_header);
|
ret = blisp_device_load_segment_header(device, &segment_header);
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
@@ -302,14 +317,14 @@ int32_t blisp_easy_load_ram_app(struct blisp_device* device,
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = blisp_easy_load_segment_data(device, blisp_easy_transport_size(app_transport),
|
ret = blisp_easy_load_segment_data(device,
|
||||||
|
blisp_easy_transport_size(app_transport),
|
||||||
app_transport, progress_callback);
|
app_transport, progress_callback);
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
// TODO: Error printing
|
// TODO: Error printing
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return BLISP_OK;
|
return BLISP_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -319,15 +334,25 @@ int32_t blisp_easy_flash_write(struct blisp_device* device,
|
|||||||
uint32_t data_size,
|
uint32_t data_size,
|
||||||
blisp_easy_progress_callback progress_callback) {
|
blisp_easy_progress_callback progress_callback) {
|
||||||
int32_t ret;
|
int32_t ret;
|
||||||
|
#if defined(__APPLE__) || defined(__FreeBSD__)
|
||||||
|
const uint16_t buffer_max_size = 372 * 1;
|
||||||
|
#else
|
||||||
|
const uint16_t buffer_max_size = 2052;
|
||||||
|
#endif
|
||||||
|
|
||||||
uint32_t sent_data = 0;
|
uint32_t sent_data = 0;
|
||||||
uint32_t buffer_size = 0;
|
uint32_t buffer_size = 0;
|
||||||
uint8_t buffer[8184];
|
#ifdef _WIN32
|
||||||
|
uint8_t buffer[2052];
|
||||||
|
#else
|
||||||
|
uint8_t buffer[buffer_max_size];
|
||||||
|
#endif
|
||||||
blisp_easy_report_progress(progress_callback, 0, data_size);
|
blisp_easy_report_progress(progress_callback, 0, data_size);
|
||||||
|
|
||||||
while (sent_data < data_size) {
|
while (sent_data < data_size) {
|
||||||
buffer_size = data_size - sent_data;
|
buffer_size = data_size - sent_data;
|
||||||
if (buffer_size > 2052) {
|
if (buffer_size > buffer_max_size) {
|
||||||
buffer_size = 2052;
|
buffer_size = buffer_max_size;
|
||||||
}
|
}
|
||||||
blisp_easy_transport_read(data_transport, buffer,
|
blisp_easy_transport_read(data_transport, buffer,
|
||||||
buffer_size); // TODO: Error Handling
|
buffer_size); // TODO: Error Handling
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
// SPDX-License-Identifier: MIT
|
// SPDX-License-Identifier: MIT
|
||||||
#include <malloc.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "../../data/bl60x_eflash_loader.h"
|
#include "../../data/bl60x_eflash_loader.h"
|
||||||
#include "blisp.h"
|
#include "blisp.h"
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
// SPDX-License-Identifier: MIT
|
// SPDX-License-Identifier: MIT
|
||||||
#include <malloc.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "../../data/bl70x_eflash_loader.h"
|
#include "../../data/bl70x_eflash_loader.h"
|
||||||
#include "blisp.h"
|
#include "blisp.h"
|
||||||
|
|||||||
@@ -3,11 +3,11 @@
|
|||||||
#define BLISP_CMD_H
|
#define BLISP_CMD_H
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
#include "error_codes.h"
|
||||||
struct cmd {
|
struct cmd {
|
||||||
const char* name;
|
const char* name;
|
||||||
int8_t (*args_init)();
|
blisp_return_t (*args_init)();
|
||||||
uint8_t (*args_parse_exec)(int argc, char** argv);
|
blisp_return_t (*args_parse_exec)(int argc, char** argv);
|
||||||
void (*args_print_syntax)();
|
void (*args_print_syntax)();
|
||||||
void (*args_free)();
|
void (*args_free)();
|
||||||
};
|
};
|
||||||
|
|||||||
+35
-28
@@ -1,7 +1,7 @@
|
|||||||
|
#include <argtable3.h>
|
||||||
#include <blisp_easy.h>
|
#include <blisp_easy.h>
|
||||||
#include "../cmd.h"
|
#include "../cmd.h"
|
||||||
#include "../common.h"
|
#include "../common.h"
|
||||||
#include <argtable3.h>
|
|
||||||
|
|
||||||
#define REG_EXTENDED 1
|
#define REG_EXTENDED 1
|
||||||
#define REG_ICASE (REG_EXTENDED << 1)
|
#define REG_ICASE (REG_EXTENDED << 1)
|
||||||
@@ -9,21 +9,21 @@
|
|||||||
static struct arg_rex* cmd;
|
static struct arg_rex* cmd;
|
||||||
static struct arg_file* single_download;
|
static struct arg_file* single_download;
|
||||||
static struct arg_int* single_download_location;
|
static struct arg_int* single_download_location;
|
||||||
static struct arg_str *port_name, *chip_type; // TODO: Make this common
|
static struct arg_str *port_name, *chip_type; // TODO: Make this common
|
||||||
static struct arg_lit* reset;
|
static struct arg_lit* reset;
|
||||||
static struct arg_end* end;
|
static struct arg_end* end;
|
||||||
static void* cmd_iot_argtable[7];
|
static void* cmd_iot_argtable[7];
|
||||||
|
|
||||||
void blisp_single_download()
|
blisp_return_t blisp_single_download() {
|
||||||
{
|
|
||||||
struct blisp_device device;
|
struct blisp_device device;
|
||||||
int32_t ret;
|
blisp_return_t ret;
|
||||||
|
|
||||||
if (blisp_common_init_device(&device, port_name, chip_type) != 0) {
|
ret = blisp_common_init_device(&device, port_name, chip_type);
|
||||||
return;
|
if (ret != BLISP_OK) {
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
ret = blisp_common_prepare_flash(&device);
|
||||||
if (blisp_common_prepare_flash(&device) != 0) {
|
if (ret != BLISP_OK) {
|
||||||
// TODO: Error handling
|
// TODO: Error handling
|
||||||
goto exit1;
|
goto exit1;
|
||||||
}
|
}
|
||||||
@@ -32,6 +32,7 @@ void blisp_single_download()
|
|||||||
if (data_file == NULL) {
|
if (data_file == NULL) {
|
||||||
fprintf(stderr, "Failed to open data file \"%s\".\n",
|
fprintf(stderr, "Failed to open data file \"%s\".\n",
|
||||||
single_download->filename[0]);
|
single_download->filename[0]);
|
||||||
|
ret = BLISP_ERR_CANT_OPEN_FILE;
|
||||||
goto exit1;
|
goto exit1;
|
||||||
}
|
}
|
||||||
fseek(data_file, 0, SEEK_END);
|
fseek(data_file, 0, SEEK_END);
|
||||||
@@ -39,9 +40,9 @@ void blisp_single_download()
|
|||||||
rewind(data_file);
|
rewind(data_file);
|
||||||
|
|
||||||
printf("Erasing the area, this might take a while...\n");
|
printf("Erasing the area, this might take a while...\n");
|
||||||
ret =
|
ret = blisp_device_flash_erase(
|
||||||
blisp_device_flash_erase(&device, *single_download_location->ival,
|
&device, *single_download_location->ival,
|
||||||
*single_download_location->ival + data_file_size + 1);
|
*single_download_location->ival + data_file_size + 1);
|
||||||
if (ret != BLISP_OK) {
|
if (ret != BLISP_OK) {
|
||||||
fprintf(stderr, "Failed to erase.\n");
|
fprintf(stderr, "Failed to erase.\n");
|
||||||
goto exit2;
|
goto exit2;
|
||||||
@@ -51,8 +52,8 @@ void blisp_single_download()
|
|||||||
struct blisp_easy_transport data_transport =
|
struct blisp_easy_transport data_transport =
|
||||||
blisp_easy_transport_new_from_file(data_file);
|
blisp_easy_transport_new_from_file(data_file);
|
||||||
|
|
||||||
ret = blisp_easy_flash_write(&device, &data_transport, *single_download_location->ival,
|
ret = blisp_easy_flash_write(&device, &data_transport,
|
||||||
data_file_size,
|
*single_download_location->ival, data_file_size,
|
||||||
blisp_common_progress_callback);
|
blisp_common_progress_callback);
|
||||||
if (ret < BLISP_OK) {
|
if (ret < BLISP_OK) {
|
||||||
fprintf(stderr, "Failed to write data to flash.\n");
|
fprintf(stderr, "Failed to write data to flash.\n");
|
||||||
@@ -67,21 +68,28 @@ void blisp_single_download()
|
|||||||
}
|
}
|
||||||
printf("Program OK!\n");
|
printf("Program OK!\n");
|
||||||
|
|
||||||
if (reset->count > 0) { // TODO: could be common
|
if (reset->count > 0) { // TODO: could be common
|
||||||
blisp_device_reset(&device);
|
|
||||||
printf("Resetting the chip.\n");
|
printf("Resetting the chip.\n");
|
||||||
|
ret = blisp_device_reset(&device);
|
||||||
|
if (ret != BLISP_OK) {
|
||||||
|
fprintf(stderr, "Failed to reset chip.\n");
|
||||||
|
goto exit2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (ret == BLISP_OK) {
|
||||||
|
printf("Download complete!\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("Download complete!\n");
|
|
||||||
|
|
||||||
exit2:
|
exit2:
|
||||||
if (data_file != NULL)
|
if (data_file != NULL)
|
||||||
fclose(data_file);
|
fclose(data_file);
|
||||||
exit1:
|
exit1:
|
||||||
blisp_device_close(&device);
|
blisp_device_close(&device);
|
||||||
|
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int8_t cmd_iot_args_init() {
|
blisp_return_t cmd_iot_args_init() {
|
||||||
cmd_iot_argtable[0] = cmd =
|
cmd_iot_argtable[0] = cmd =
|
||||||
arg_rex1(NULL, NULL, "iot", NULL, REG_ICASE, NULL);
|
arg_rex1(NULL, NULL, "iot", NULL, REG_ICASE, NULL);
|
||||||
cmd_iot_argtable[1] = chip_type =
|
cmd_iot_argtable[1] = chip_type =
|
||||||
@@ -99,9 +107,9 @@ int8_t cmd_iot_args_init() {
|
|||||||
|
|
||||||
if (arg_nullcheck(cmd_iot_argtable) != 0) {
|
if (arg_nullcheck(cmd_iot_argtable) != 0) {
|
||||||
fprintf(stderr, "insufficient memory\n");
|
fprintf(stderr, "insufficient memory\n");
|
||||||
return -1;
|
return BLISP_ERR_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
return 0;
|
return BLISP_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
void cmd_iot_args_print_glossary() {
|
void cmd_iot_args_print_glossary() {
|
||||||
@@ -111,20 +119,19 @@ void cmd_iot_args_print_glossary() {
|
|||||||
arg_print_glossary(stdout, cmd_iot_argtable, " %-25s %s\n");
|
arg_print_glossary(stdout, cmd_iot_argtable, " %-25s %s\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t cmd_iot_parse_exec(int argc, char** argv) {
|
blisp_return_t cmd_iot_parse_exec(int argc, char** argv) {
|
||||||
int errors = arg_parse(argc, argv, cmd_iot_argtable);
|
int errors = arg_parse(argc, argv, cmd_iot_argtable);
|
||||||
if (errors == 0) {
|
if (errors == 0) {
|
||||||
if (single_download->count == 1 && single_download_location->count == 1) {
|
if (single_download->count == 1 && single_download_location->count == 1) {
|
||||||
blisp_single_download();
|
return blisp_single_download();
|
||||||
return 1;
|
|
||||||
} else {
|
} else {
|
||||||
return 0;
|
return BLISP_ERR_INVALID_COMMAND;
|
||||||
}
|
}
|
||||||
} else if (cmd->count == 1) {
|
} else if (cmd->count == 1) {
|
||||||
cmd_iot_args_print_glossary();
|
cmd_iot_args_print_glossary();
|
||||||
return 1;
|
return BLISP_OK;
|
||||||
}
|
}
|
||||||
return 0;
|
return BLISP_ERR_INVALID_COMMAND;
|
||||||
}
|
}
|
||||||
|
|
||||||
void cmd_iot_args_print_syntax() {
|
void cmd_iot_args_print_syntax() {
|
||||||
@@ -137,4 +144,4 @@ void cmd_iot_free() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
struct cmd cmd_iot = {"iot", cmd_iot_args_init, cmd_iot_parse_exec,
|
struct cmd cmd_iot = {"iot", cmd_iot_args_init, cmd_iot_parse_exec,
|
||||||
cmd_iot_args_print_syntax, cmd_iot_free};
|
cmd_iot_args_print_syntax, cmd_iot_free};
|
||||||
|
|||||||
+16
-15
@@ -1,14 +1,14 @@
|
|||||||
// SPDX-License-Identifier: MIT
|
// SPDX-License-Identifier: MIT
|
||||||
|
#include <argtable3.h>
|
||||||
#include <blisp.h>
|
#include <blisp.h>
|
||||||
|
#include <blisp_easy.h>
|
||||||
|
#include <blisp_struct.h>
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "../cmd.h"
|
#include "../cmd.h"
|
||||||
#include "../common.h"
|
#include "../common.h"
|
||||||
#include "../util.h"
|
#include "../util.h"
|
||||||
#include <argtable3.h>
|
|
||||||
#include <blisp_easy.h>
|
|
||||||
#include <blisp_struct.h>
|
|
||||||
|
|
||||||
#define REG_EXTENDED 1
|
#define REG_EXTENDED 1
|
||||||
#define REG_ICASE (REG_EXTENDED << 1)
|
#define REG_ICASE (REG_EXTENDED << 1)
|
||||||
@@ -164,12 +164,13 @@ void fill_up_boot_header(struct bfl_boot_header* boot_header) {
|
|||||||
boot_header->crc32 = 0xDEADBEEF;
|
boot_header->crc32 = 0xDEADBEEF;
|
||||||
}
|
}
|
||||||
|
|
||||||
void blisp_flash_firmware() {
|
blisp_return_t blisp_flash_firmware() {
|
||||||
struct blisp_device device;
|
struct blisp_device device;
|
||||||
int32_t ret;
|
blisp_return_t ret;
|
||||||
|
ret = blisp_common_init_device(&device, port_name, chip_type);
|
||||||
|
|
||||||
if (blisp_common_init_device(&device, port_name, chip_type) != 0) {
|
if (ret != 0) {
|
||||||
return;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (blisp_common_prepare_flash(&device) != 0) {
|
if (blisp_common_prepare_flash(&device) != 0) {
|
||||||
@@ -248,7 +249,7 @@ exit1:
|
|||||||
blisp_device_close(&device);
|
blisp_device_close(&device);
|
||||||
}
|
}
|
||||||
|
|
||||||
int8_t cmd_write_args_init() {
|
blisp_return_t cmd_write_args_init() {
|
||||||
cmd_write_argtable[0] = cmd =
|
cmd_write_argtable[0] = cmd =
|
||||||
arg_rex1(NULL, NULL, "write", NULL, REG_ICASE, NULL);
|
arg_rex1(NULL, NULL, "write", NULL, REG_ICASE, NULL);
|
||||||
cmd_write_argtable[1] = chip_type =
|
cmd_write_argtable[1] = chip_type =
|
||||||
@@ -264,9 +265,9 @@ int8_t cmd_write_args_init() {
|
|||||||
|
|
||||||
if (arg_nullcheck(cmd_write_argtable) != 0) {
|
if (arg_nullcheck(cmd_write_argtable) != 0) {
|
||||||
fprintf(stderr, "insufficient memory\n");
|
fprintf(stderr, "insufficient memory\n");
|
||||||
return -1;
|
return BLISP_ERR_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
return 0;
|
return BLISP_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
void cmd_write_args_print_glossary() {
|
void cmd_write_args_print_glossary() {
|
||||||
@@ -276,16 +277,16 @@ void cmd_write_args_print_glossary() {
|
|||||||
arg_print_glossary(stdout, cmd_write_argtable, " %-25s %s\n");
|
arg_print_glossary(stdout, cmd_write_argtable, " %-25s %s\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t cmd_write_parse_exec(int argc, char** argv) {
|
blisp_return_t cmd_write_parse_exec(int argc, char** argv) {
|
||||||
int errors = arg_parse(argc, argv, cmd_write_argtable);
|
int errors = arg_parse(argc, argv, cmd_write_argtable);
|
||||||
if (errors == 0) {
|
if (errors == 0) {
|
||||||
blisp_flash_firmware(); // TODO: Error code?
|
return blisp_flash_firmware(); // TODO: Error code?
|
||||||
return 1;
|
|
||||||
} else if (cmd->count == 1) {
|
} else if (cmd->count == 1) {
|
||||||
cmd_write_args_print_glossary();
|
cmd_write_args_print_glossary();
|
||||||
return 1;
|
return BLISP_OK;
|
||||||
}
|
}
|
||||||
return 0;
|
return BLISP_ERR_INVALID_COMMAND;
|
||||||
}
|
}
|
||||||
|
|
||||||
void cmd_write_args_print_syntax() {
|
void cmd_write_args_print_syntax() {
|
||||||
|
|||||||
+31
-25
@@ -3,23 +3,26 @@
|
|||||||
#include <argtable3.h>
|
#include <argtable3.h>
|
||||||
#include <blisp.h>
|
#include <blisp.h>
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
#include <malloc.h>
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "blisp_easy.h"
|
#include "blisp_easy.h"
|
||||||
|
#include "error_codes.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
|
||||||
void blisp_common_progress_callback(uint32_t current_value, uint32_t max_value) {
|
void blisp_common_progress_callback(uint32_t current_value,
|
||||||
printf("%" PRIu32 "b / %ldb (%.2f%%)\n", current_value, max_value,
|
uint32_t max_value) {
|
||||||
|
printf("%" PRIu32 "b / %u (%.2f%%)\n", current_value, max_value,
|
||||||
(((float)current_value / (float)max_value) * 100.0f));
|
(((float)current_value / (float)max_value) * 100.0f));
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t blisp_common_init_device(struct blisp_device* device, struct arg_str* port_name, struct arg_str* chip_type)
|
blisp_return_t blisp_common_init_device(struct blisp_device* device,
|
||||||
{
|
struct arg_str* port_name,
|
||||||
|
struct arg_str* chip_type) {
|
||||||
if (chip_type->count == 0) {
|
if (chip_type->count == 0) {
|
||||||
fprintf(stderr, "Chip type is invalid.\n");
|
fprintf(stderr, "Chip type is invalid.\n");
|
||||||
return -1;
|
return BLISP_ERR_INVALID_CHIP_TYPE;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct blisp_chip* chip = NULL;
|
struct blisp_chip* chip = NULL;
|
||||||
@@ -30,44 +33,46 @@ int32_t blisp_common_init_device(struct blisp_device* device, struct arg_str* po
|
|||||||
chip = &blisp_chip_bl60x;
|
chip = &blisp_chip_bl60x;
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr, "Chip type is invalid.\n");
|
fprintf(stderr, "Chip type is invalid.\n");
|
||||||
return -1;
|
return BLISP_ERR_INVALID_CHIP_TYPE;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t ret;
|
blisp_return_t ret;
|
||||||
ret = blisp_device_init(device, chip);
|
ret = blisp_device_init(device, chip);
|
||||||
if (ret != BLISP_OK) {
|
if (ret != BLISP_OK) {
|
||||||
fprintf(stderr, "Failed to init device.\n");
|
fprintf(stderr, "Failed to init device.\n");
|
||||||
return -1;
|
return ret;
|
||||||
}
|
}
|
||||||
ret = blisp_device_open(device,
|
ret = blisp_device_open(device,
|
||||||
port_name->count == 1 ? port_name->sval[0] : NULL);
|
port_name->count == 1 ? port_name->sval[0] : NULL);
|
||||||
if (ret != BLISP_OK) {
|
if (ret != BLISP_OK) {
|
||||||
fprintf(stderr, ret == BLISP_ERR_DEVICE_NOT_FOUND ? "Device not found\n" : "Failed to open device.\n");
|
fprintf(stderr, ret == BLISP_ERR_DEVICE_NOT_FOUND
|
||||||
return -1;
|
? "Device not found\n"
|
||||||
|
: "Failed to open device.\n");
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return BLISP_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Prepares chip to access flash
|
* Prepares chip to access flash
|
||||||
* this means performing handshake, and loading eflash_loader if needed.
|
* this means performing handshake, and loading eflash_loader if needed.
|
||||||
*/
|
*/
|
||||||
int32_t blisp_common_prepare_flash(struct blisp_device* device) {
|
blisp_return_t blisp_common_prepare_flash(struct blisp_device* device) {
|
||||||
int32_t ret = 0;
|
blisp_return_t ret = 0;
|
||||||
|
|
||||||
printf("Sending a handshake...\n");
|
printf("Sending a handshake...\n");
|
||||||
ret = blisp_device_handshake(device, false);
|
ret = blisp_device_handshake(device, false);
|
||||||
if (ret != BLISP_OK) {
|
if (ret != BLISP_OK) {
|
||||||
fprintf(stderr, "Failed to handshake with device.\n");
|
fprintf(stderr, "Failed to handshake with device.\n");
|
||||||
return -1;
|
return ret;
|
||||||
}
|
}
|
||||||
printf("Handshake successful!\nGetting chip info...\n");
|
printf("Handshake successful!\nGetting chip info...\n");
|
||||||
struct blisp_boot_info boot_info;
|
struct blisp_boot_info boot_info;
|
||||||
ret = blisp_device_get_boot_info(device, &boot_info);
|
ret = blisp_device_get_boot_info(device, &boot_info);
|
||||||
if (ret != BLISP_OK) {
|
if (ret != BLISP_OK) {
|
||||||
fprintf(stderr, "Failed to get boot info.\n");
|
fprintf(stderr, "Failed to get boot info.\n");
|
||||||
return -1;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
printf(
|
printf(
|
||||||
@@ -80,7 +85,7 @@ int32_t blisp_common_prepare_flash(struct blisp_device* device) {
|
|||||||
boot_info.chip_id[6], boot_info.chip_id[7]);
|
boot_info.chip_id[6], boot_info.chip_id[7]);
|
||||||
|
|
||||||
if (device->chip->load_eflash_loader == NULL) {
|
if (device->chip->load_eflash_loader == NULL) {
|
||||||
return 0;
|
return BLISP_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (boot_info.boot_rom_version[0] == 255 &&
|
if (boot_info.boot_rom_version[0] == 255 &&
|
||||||
@@ -88,21 +93,24 @@ int32_t blisp_common_prepare_flash(struct blisp_device* device) {
|
|||||||
boot_info.boot_rom_version[2] == 255 &&
|
boot_info.boot_rom_version[2] == 255 &&
|
||||||
boot_info.boot_rom_version[3] == 255) {
|
boot_info.boot_rom_version[3] == 255) {
|
||||||
printf("Device already in eflash_loader.\n");
|
printf("Device already in eflash_loader.\n");
|
||||||
return 0;
|
return BLISP_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t* eflash_loader_buffer = NULL;
|
uint8_t* eflash_loader_buffer = NULL;
|
||||||
// TODO: Error check
|
// TODO: Error check
|
||||||
int64_t eflash_loader_buffer_length = device->chip->load_eflash_loader(0, &eflash_loader_buffer);
|
int64_t eflash_loader_buffer_length =
|
||||||
|
device->chip->load_eflash_loader(0, &eflash_loader_buffer);
|
||||||
|
|
||||||
struct blisp_easy_transport eflash_loader_transport =
|
struct blisp_easy_transport eflash_loader_transport =
|
||||||
blisp_easy_transport_new_from_memory(eflash_loader_buffer, eflash_loader_buffer_length);
|
blisp_easy_transport_new_from_memory(eflash_loader_buffer,
|
||||||
|
eflash_loader_buffer_length);
|
||||||
|
|
||||||
ret = blisp_easy_load_ram_app(device, &eflash_loader_transport, blisp_common_progress_callback);
|
ret = blisp_easy_load_ram_app(device, &eflash_loader_transport,
|
||||||
|
blisp_common_progress_callback);
|
||||||
|
|
||||||
if (ret != BLISP_OK) {
|
if (ret != BLISP_OK) {
|
||||||
fprintf(stderr, "Failed to load eflash_loader, ret: %d\n", ret);
|
fprintf(stderr, "Failed to load eflash_loader, ret: %d\n", ret);
|
||||||
ret = -1;
|
|
||||||
goto exit1;
|
goto exit1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -112,14 +120,12 @@ int32_t blisp_common_prepare_flash(struct blisp_device* device) {
|
|||||||
ret = blisp_device_check_image(device);
|
ret = blisp_device_check_image(device);
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
fprintf(stderr, "Failed to check image.\n");
|
fprintf(stderr, "Failed to check image.\n");
|
||||||
ret = -1;
|
|
||||||
goto exit1;
|
goto exit1;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = blisp_device_run_image(device);
|
ret = blisp_device_run_image(device);
|
||||||
if (ret != BLISP_OK) {
|
if (ret != BLISP_OK) {
|
||||||
fprintf(stderr, "Failed to run image.\n");
|
fprintf(stderr, "Failed to run image.\n");
|
||||||
ret = -1;
|
|
||||||
goto exit1;
|
goto exit1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -127,12 +133,12 @@ int32_t blisp_common_prepare_flash(struct blisp_device* device) {
|
|||||||
ret = blisp_device_handshake(device, true);
|
ret = blisp_device_handshake(device, true);
|
||||||
if (ret != BLISP_OK) {
|
if (ret != BLISP_OK) {
|
||||||
fprintf(stderr, "Failed to handshake with device.\n");
|
fprintf(stderr, "Failed to handshake with device.\n");
|
||||||
ret = -1;
|
|
||||||
goto exit1;
|
goto exit1;
|
||||||
}
|
}
|
||||||
printf("Handshake with eflash_loader successful.\n");
|
printf("Handshake with eflash_loader successful.\n");
|
||||||
exit1:
|
exit1:
|
||||||
if (eflash_loader_buffer != NULL)
|
if (eflash_loader_buffer != NULL)
|
||||||
free(eflash_loader_buffer);
|
free(eflash_loader_buffer);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
+25
-19
@@ -14,7 +14,7 @@ static struct arg_lit* version;
|
|||||||
static struct arg_end* end;
|
static struct arg_end* end;
|
||||||
static void* argtable[3];
|
static void* argtable[3];
|
||||||
|
|
||||||
int8_t args_init() {
|
blisp_return_t args_init() {
|
||||||
argtable[0] = help = arg_lit0(NULL, "help", "print this help and exit");
|
argtable[0] = help = arg_lit0(NULL, "help", "print this help and exit");
|
||||||
argtable[1] = version =
|
argtable[1] = version =
|
||||||
arg_lit0(NULL, "version", "print version information and exit");
|
arg_lit0(NULL, "version", "print version information and exit");
|
||||||
@@ -22,10 +22,10 @@ int8_t args_init() {
|
|||||||
|
|
||||||
if (arg_nullcheck(argtable) != 0) {
|
if (arg_nullcheck(argtable) != 0) {
|
||||||
fprintf(stderr, "insufficient memory\n");
|
fprintf(stderr, "insufficient memory\n");
|
||||||
return -1;
|
return BLISP_ERR_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return BLISP_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
void print_help() {
|
void print_help() {
|
||||||
@@ -43,14 +43,14 @@ int8_t args_parse_exec(int argc, char** argv) {
|
|||||||
if (error == 0) {
|
if (error == 0) {
|
||||||
if (help->count) {
|
if (help->count) {
|
||||||
print_help();
|
print_help();
|
||||||
return 1;
|
return BLISP_OK;
|
||||||
} else if (version->count) {
|
} else if (version->count) {
|
||||||
printf("blisp v0.0.2\n");
|
printf("blisp v0.0.3\n");
|
||||||
printf("Copyright (C) 2023 Marek Kraus and PINE64 Community\n");
|
printf("Copyright (C) 2023 Marek Kraus and PINE64 Community\n");
|
||||||
return 1;
|
return BLISP_OK;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
return BLISP_ERR_INVALID_COMMAND;
|
||||||
}
|
}
|
||||||
|
|
||||||
void args_free() {
|
void args_free() {
|
||||||
@@ -58,27 +58,29 @@ void args_free() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char** argv) {
|
int main(int argc, char** argv) {
|
||||||
int exit_code = 0;
|
blisp_return_t ret = args_init();
|
||||||
|
if (ret != 0) {
|
||||||
if (args_init() != 0) {
|
|
||||||
exit_code = -1;
|
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (uint8_t i = 0; i < cmds_count; i++) {
|
for (uint8_t i = 0; i < cmds_count; i++) {
|
||||||
if (cmds[i]->args_init() != 0) {
|
ret = cmds[i]->args_init();
|
||||||
exit_code = -1;
|
if (ret != BLISP_OK) {
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Try and parse as a help request
|
||||||
|
{
|
||||||
|
ret = args_parse_exec(argc, argv);
|
||||||
|
if (ret == BLISP_OK) {
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args_parse_exec(argc, argv)) {
|
|
||||||
goto exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint8_t command_found = false;
|
uint8_t command_found = false;
|
||||||
for (uint8_t i = 0; i < cmds_count; i++) {
|
for (uint8_t i = 0; i < cmds_count; i++) {
|
||||||
if (cmds[i]->args_parse_exec(argc, argv)) {
|
ret = cmds[i]->args_parse_exec(argc, argv);
|
||||||
|
if (ret != BLISP_ERR_INVALID_COMMAND) {
|
||||||
command_found = true;
|
command_found = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -93,5 +95,9 @@ exit:
|
|||||||
cmds[i]->args_free();
|
cmds[i]->args_free();
|
||||||
}
|
}
|
||||||
args_free();
|
args_free();
|
||||||
return exit_code;
|
// Make error codes more intuitive, but converting to +ve mirror
|
||||||
|
if (ret < 0) {
|
||||||
|
ret = -ret;
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,8 @@
|
|||||||
// These are not thread safe, but it doesn't place the responsibility
|
// These are not thread safe, but it doesn't place the responsibility
|
||||||
// to free an allocated buffer on the caller.nn
|
// to free an allocated buffer on the caller.nn
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
static void util_get_executable_path(char* buffer_out, uint32_t max_size) {
|
static void util_get_executable_path(char* buffer_out, uint32_t max_size) {
|
||||||
assert(max_size >= PATH_MAX); // n.b. 1024 on MacOS. 4K on most Linux.
|
assert(max_size >= PATH_MAX); // n.b. 1024 on MacOS. 4K on most Linux.
|
||||||
|
|
||||||
@@ -33,6 +35,11 @@ ssize_t util_get_binary_folder(char* buffer, uint32_t buffer_size) {
|
|||||||
#elif defined(__APPLE__)
|
#elif defined(__APPLE__)
|
||||||
util_get_executable_path(buffer, buffer_size);
|
util_get_executable_path(buffer, buffer_size);
|
||||||
char* pos = strrchr(buffer, '/');
|
char* pos = strrchr(buffer, '/');
|
||||||
|
#elif __FreeBSD__
|
||||||
|
if (readlink("/proc/curproc/file", buffer, buffer_size) <= 0) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
char* pos = strrchr(buffer, '/');
|
||||||
#else
|
#else
|
||||||
if (GetModuleFileName(NULL, buffer, buffer_size) <= 0) {
|
if (GetModuleFileName(NULL, buffer, buffer_size) <= 0) {
|
||||||
return -1;
|
return -1;
|
||||||
|
|||||||
@@ -4,9 +4,7 @@
|
|||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
#ifdef __linux__
|
#if defined(_MSC_VER)
|
||||||
#include <unistd.h>
|
|
||||||
#elif defined(_MSC_VER)
|
|
||||||
#include <BaseTsd.h>
|
#include <BaseTsd.h>
|
||||||
typedef SSIZE_T ssize_t;
|
typedef SSIZE_T ssize_t;
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
@@ -14,10 +12,9 @@ typedef SSIZE_T ssize_t;
|
|||||||
#elif defined(__APPLE__)
|
#elif defined(__APPLE__)
|
||||||
#include <sys/syslimits.h>
|
#include <sys/syslimits.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#endif
|
#include <sys/types.h>
|
||||||
|
#else
|
||||||
#ifdef __linux__
|
#include <unistd.h>
|
||||||
#include <linux/limits.h>
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
ssize_t util_get_binary_folder(char* buffer, uint32_t buffer_size);
|
ssize_t util_get_binary_folder(char* buffer, uint32_t buffer_size);
|
||||||
|
|||||||
Reference in New Issue
Block a user