Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Open source tool and library for flashing Bouffalo RISC-V MCUs.
- [x] Windows
- [x] Linux
- [x] Apple
- [x] FreeBSD

# Building

Expand All @@ -27,6 +28,7 @@ If you have not cloned this repository locally; clone the git repository locally
```bash
git clone --recursive https://github.com/pine64/blisp.git
cd blisp
git submodule update --init --recursive
```

## Build the library and command line utility
Expand Down
20 changes: 12 additions & 8 deletions lib/blisp.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@

#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,
struct blisp_chip* chip) {
device->chip = chip;
Expand Down Expand Up @@ -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_flowcontrol(serial_port, SP_FLOWCONTROL_NONE);

uint32_t vid, pid;
int vid, pid;
sp_get_port_usb_vid_pid(serial_port, &vid, &pid);
device->is_usb = pid == 0xFFFF;
// if (device->is_usb) {
// device->current_baud_rate = 2000000;
// } else {
device->current_baud_rate = 500000;
device->current_baud_rate = 460800;
// }

#if 0
Expand Down Expand Up @@ -130,9 +136,7 @@ int32_t blisp_send_command(struct blisp_device* device,
blisp_dlog("Received error or not written all data: %d", ret);
return BLISP_ERR_UNKNOWN;
}
#ifdef __APPLE__
sp_drain(serial_port);
#endif
drain(serial_port);

return BLISP_OK;
}
Expand Down Expand Up @@ -195,12 +199,12 @@ int32_t blisp_device_handshake(struct blisp_device* device, bool in_ef_loader) {
if (!in_ef_loader) {
if (device->is_usb) {
sp_blocking_write(serial_port, "BOUFFALOLAB5555RESET\0\0", 22, 100);
#ifdef __APPLE__
sp_drain(serial_port);
#endif
drain(serial_port);
}
}
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) {
blisp_dlog("Handshake write failed, ret %d", ret);
return BLISP_ERR_UNKNOWN;
Expand Down
4 changes: 3 additions & 1 deletion lib/blisp_easy.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ static int64_t blisp_easy_transport_size(struct blisp_easy_transport* transport)
return transport->data.memory.data_size;
} else {
// TODO: Implement
printf("%s() Warning: calling non-implemented function\n", __func__);
return -1;
}
}

Expand Down Expand Up @@ -329,7 +331,7 @@ int32_t blisp_easy_flash_write(struct blisp_device* device,
uint32_t data_size,
blisp_easy_progress_callback progress_callback) {
int32_t ret;
#ifdef __APPLE__
#if defined (__APPLE__) || defined (__FreeBSD__)
const uint16_t buffer_max_size = 372 * 1;
#else
const uint16_t buffer_max_size = 2052;
Expand Down
2 changes: 1 addition & 1 deletion tools/blisp/src/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include "util.h"

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));
}

Expand Down
5 changes: 5 additions & 0 deletions tools/blisp/src/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ ssize_t util_get_binary_folder(char* buffer, uint32_t buffer_size) {
#elif defined(__APPLE__)
util_get_executable_path(buffer, buffer_size);
char* pos = strrchr(buffer, '/');
#elif __FreeBSD__
if (readlink("/proc/curproc/file", buffer, buffer_size) <= 0) {
return -1;
}
char* pos = strrchr(buffer, '/');
#else
if (GetModuleFileName(NULL, buffer, buffer_size) <= 0) {
return -1;
Expand Down
6 changes: 3 additions & 3 deletions tools/blisp/src/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@

#include <stdint.h>

#ifdef __linux__
#include <unistd.h>
#elif defined(_MSC_VER)
#if defined(_MSC_VER)
#include <BaseTsd.h>
typedef SSIZE_T ssize_t;
#include <windows.h>
Expand All @@ -15,6 +13,8 @@ typedef SSIZE_T ssize_t;
#include <sys/syslimits.h>
#include <assert.h>
#include <sys/types.h>
#else
#include <unistd.h>
#endif

ssize_t util_get_binary_folder(char* buffer, uint32_t buffer_size);
Expand Down