Skip to content

Commit c49b5d1

Browse files
committed
Fix segfault in release builds, and add output to all commands
1 parent 08d4d0d commit c49b5d1

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

main.cpp

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6086,7 +6086,7 @@ bool link_command::execute(device_map &devices) {
60866086

60876087
#if HAS_LIBUSB
60886088
struct _bdevfs_setup {
6089-
picoboot::connection *con;
6089+
picoboot::connection *connection;
60906090
std::shared_ptr<picoboot_memory_access> access;
60916091
uint32_t base_addr;
60926092
uint32_t size;
@@ -6095,14 +6095,13 @@ struct _bdevfs_setup {
60956095
};
60966096
_bdevfs_setup bdevfs_setup;
60976097

6098-
void setup_bdevfs(picoboot::connection con) {
6099-
auto raw_access_ptr = std::make_shared<picoboot_memory_access>(con);
6100-
auto raw_access = *raw_access_ptr;
6101-
bdevfs_setup.con = &con;
6102-
bdevfs_setup.access = raw_access_ptr;
6098+
#define setup_bdevfs(con) bdevfs_setup.access = std::make_shared<picoboot_memory_access>(con); bdevfs_setup.connection = &con; setup_bdevfs_internal()
6099+
6100+
void setup_bdevfs_internal() {
6101+
auto raw_access = *bdevfs_setup.access;
61036102

61046103
if (settings.bdev.partition >= 0) {
6105-
auto partitions = get_partitions(con);
6104+
auto partitions = get_partitions(*bdevfs_setup.connection);
61066105
if (!partitions) {
61076106
fail(ERROR_NOT_POSSIBLE, "There is no partition table on the device");
61086107
}
@@ -6256,7 +6255,7 @@ DRESULT disk_ioctl (void *drv, BYTE cmd, void* buff) {
62566255
if (start % FLASH_SECTOR_ERASE_SIZE) start += FLASH_SECTOR_ERASE_SIZE - (start % FLASH_SECTOR_ERASE_SIZE);
62576256
end -= end % FLASH_SECTOR_ERASE_SIZE;
62586257
for (uint32_t addr = start; addr < end; addr += FLASH_SECTOR_ERASE_SIZE) {
6259-
bdevfs_setup.con->flash_erase(addr, FLASH_SECTOR_ERASE_SIZE);
6258+
bdevfs_setup.connection->flash_erase(addr, FLASH_SECTOR_ERASE_SIZE);
62606259
}
62616260
return RES_OK;
62626261
} else {
@@ -6383,7 +6382,7 @@ int lfs_prog(const struct lfs_config *c, lfs_block_t block, lfs_off_t off, const
63836382

63846383
int lfs_erase(const struct lfs_config *c, lfs_block_t block) {
63856384
if (bdevfs_setup.writeable) {
6386-
bdevfs_setup.con->flash_erase(bdevfs_setup.base_addr + (block * c->block_size), c->block_size);
6385+
bdevfs_setup.connection->flash_erase(bdevfs_setup.base_addr + (block * c->block_size), c->block_size);
63876386
return LFS_ERR_OK;
63886387
} else {
63896388
fail(ERROR_NOT_POSSIBLE, "This block device is not writeable");
@@ -6498,6 +6497,8 @@ bool bdev_ls_command::execute(device_map &devices) {
64986497
dir.pop_back();
64996498
}
65006499

6500+
fos << settings.filenames[0] << "/\n";
6501+
65016502
switch (settings.bdev.fs) {
65026503
case fs_littlefs: {
65036504
lfs_op_fn lfs_op = [&](lfs_t *lfs) {
@@ -6555,6 +6556,9 @@ bool bdev_mkdir_command::execute(device_map &devices) {
65556556
default:
65566557
fail(ERROR_ARGS, "Unknown filesystem specified");
65576558
}
6559+
6560+
fos << "Created directory " << settings.filenames[0] << " on device\n";
6561+
65586562
return false;
65596563
}
65606564

@@ -6725,6 +6729,9 @@ bool bdev_rm_command::execute(device_map &devices) {
67256729
default:
67266730
fail(ERROR_ARGS, "Unknown filesystem specified");
67276731
}
6732+
6733+
fos << "Removed " << settings.filenames[0] << " from device\n";
6734+
67286735
return false;
67296736
}
67306737

0 commit comments

Comments
 (0)