Compare commits

...

5 Commits

Author SHA1 Message Date
porsolic
6424f9ddf8 Fix it to work under FreeBSD
Add sp_drain() where needed. Without it FreeBSD won't pass the handshake
phase.
Also decreate max buffer size.
Tested with Pinecil v2 and it can write and check new firmware.
2023-02-15 20:21:47 +01:00
porsolic
7fb2cc829c Fix UART baudrate
Set standard baudrate (460800) instead of non-standard (500000).
This enables opening of serial device under FreeBSD without error.
2023-02-15 20:21:47 +01:00
porsolic
a67ab9d218 Fix build on FreeBSD 2023-02-15 20:21:47 +01:00
porsolic
3fff531334 Fix compiler warnings 2023-02-15 20:21:47 +01:00
porsolic
53b57c3158 Update README.md
Add missing part about git submodules.
Without it build system won't find dependencies.
2023-02-15 20:21:47 +01:00
6 changed files with 26 additions and 13 deletions

View File

@ -17,6 +17,7 @@ Open source tool and library for flashing Bouffalo RISC-V MCUs.
- [x] Windows - [x] Windows
- [x] Linux - [x] Linux
- [x] Apple - [x] Apple
- [x] FreeBSD
# Building # Building
@ -27,6 +28,7 @@ If you have not cloned this repository locally; clone the git repository locally
```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 ## Build the library and command line utility

View File

@ -13,6 +13,12 @@
#define DEBUG #define DEBUG
static void drain(struct sp_port* port) {
#if defined(__APPLE__) || defined(__FreeBSD__)
sp_drain(port);
#endif
}
int32_t blisp_device_init(struct blisp_device* device, int32_t blisp_device_init(struct blisp_device* device,
struct blisp_chip* chip) { struct blisp_chip* chip) {
device->chip = chip; device->chip = chip;
@ -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
@ -130,9 +136,7 @@ int32_t blisp_send_command(struct blisp_device* device,
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_UNKNOWN;
} }
#ifdef __APPLE__ drain(serial_port);
sp_drain(serial_port);
#endif
return BLISP_OK; return BLISP_OK;
} }
@ -195,12 +199,12 @@ 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);
#ifdef __APPLE__ drain(serial_port);
sp_drain(serial_port);
#endif
} }
} }
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_UNKNOWN;

View File

@ -24,6 +24,8 @@ static int64_t blisp_easy_transport_size(struct blisp_easy_transport* transport)
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 -1;
} }
} }
@ -329,7 +331,7 @@ 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;
#ifdef __APPLE__ #if defined (__APPLE__) || defined (__FreeBSD__)
const uint16_t buffer_max_size = 372 * 1; const uint16_t buffer_max_size = 372 * 1;
#else #else
const uint16_t buffer_max_size = 2052; const uint16_t buffer_max_size = 2052;

View File

@ -11,7 +11,7 @@
#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, uint32_t max_value) {
printf("%" PRIu32 "b / %ldb (%.2f%%)\n", current_value, 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));
} }

View File

@ -35,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;

View File

@ -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>
@ -15,6 +13,8 @@ typedef SSIZE_T ssize_t;
#include <sys/syslimits.h> #include <sys/syslimits.h>
#include <assert.h> #include <assert.h>
#include <sys/types.h> #include <sys/types.h>
#else
#include <unistd.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);