Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple RAM/ROM savings #1000

Merged
merged 8 commits into from
Feb 13, 2024
3 changes: 0 additions & 3 deletions projects.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -459,17 +459,14 @@ projects:
- *module_if
- *module_hic_lpc11u35
- records/board/musca_a.yaml
- records/tools/gcc_arm_lto.yaml
lpc11u35_musca_b_eflash_if:
- *module_if
- *module_hic_lpc11u35
- records/board/musca_b_eflash.yaml
- records/tools/gcc_arm_lto.yaml
lpc11u35_musca_b_if:
- *module_if
- *module_hic_lpc11u35
- records/board/musca_b.yaml
- records/tools/gcc_arm_lto.yaml
lpc11u35_nz32_sc151_if:
- *module_if
- *module_hic_lpc11u35
Expand Down
82 changes: 41 additions & 41 deletions source/daplink/drag-n-drop/flash_decoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,57 +121,57 @@ error_t flash_decoder_get_flash(flash_decoder_type_t type, uint32_t addr, bool a
flash_start_local = 0;
flash_intf_local = 0;

if (daplink_is_bootloader()) {
if (FLASH_DECODER_TYPE_INTERFACE == type) {
if (addr_valid && (DAPLINK_ROM_IF_START != addr)) {
// Address is wrong so display error message
status = ERROR_FD_INTF_UPDT_ADDR_WRONG;
} else {
// Setup for update
flash_start_local = DAPLINK_ROM_IF_START;
flash_intf_local = flash_intf_iap_protected;
}
} else if (FLASH_DECODER_TYPE_TARGET == type) {
if (addr_valid && (DAPLINK_ROM_IF_START != addr)) {
// Address is wrong so display error message
status = ERROR_FD_INTF_UPDT_ADDR_WRONG;
} else {
// "Target" update in this case would be a 3rd party interface application
flash_start_local = DAPLINK_ROM_IF_START;
flash_intf_local = flash_intf_iap_protected;
}
#if defined(DAPLINK_BL)
if (FLASH_DECODER_TYPE_INTERFACE == type) {
if (addr_valid && (DAPLINK_ROM_IF_START != addr)) {
// Address is wrong so display error message
status = ERROR_FD_INTF_UPDT_ADDR_WRONG;
} else {
status = ERROR_FD_UNSUPPORTED_UPDATE;
// Setup for update
flash_start_local = DAPLINK_ROM_IF_START;
flash_intf_local = flash_intf_iap_protected;
}
} else if (daplink_is_interface()) {
if (FLASH_DECODER_TYPE_BOOTLOADER == type) {
if (addr_valid && (DAPLINK_ROM_BL_START != addr)) {
// Address is wrong so display error message
status = ERROR_FD_BL_UPDT_ADDR_WRONG;
} else {
// Setup for update
flash_start_local = DAPLINK_ROM_BL_START;
flash_intf_local = flash_intf_iap_protected;
}
} else if (FLASH_DECODER_TYPE_TARGET == type) {
if (g_board_info.target_cfg) {
region_info_t * region = g_board_info.target_cfg->flash_regions;
for (; region->start != 0 || region->end != 0; ++region) {
if (kRegionIsDefault == region->flags) {
flash_start_local = region->start;
break;
}
} else if (FLASH_DECODER_TYPE_TARGET == type) {
if (addr_valid && (DAPLINK_ROM_IF_START != addr)) {
// Address is wrong so display error message
status = ERROR_FD_INTF_UPDT_ADDR_WRONG;
} else {
// "Target" update in this case would be a 3rd party interface application
flash_start_local = DAPLINK_ROM_IF_START;
flash_intf_local = flash_intf_iap_protected;
}
} else {
status = ERROR_FD_UNSUPPORTED_UPDATE;
}
#elif defined(DAPLINK_IF)
if (FLASH_DECODER_TYPE_BOOTLOADER == type) {
if (addr_valid && (DAPLINK_ROM_BL_START != addr)) {
// Address is wrong so display error message
status = ERROR_FD_BL_UPDT_ADDR_WRONG;
} else {
// Setup for update
flash_start_local = DAPLINK_ROM_BL_START;
flash_intf_local = flash_intf_iap_protected;
}
} else if (FLASH_DECODER_TYPE_TARGET == type) {
if (g_board_info.target_cfg) {
region_info_t * region = g_board_info.target_cfg->flash_regions;
for (; region->start != 0 || region->end != 0; ++region) {
if (kRegionIsDefault == region->flags) {
flash_start_local = region->start;
break;
}
flash_intf_local = flash_intf_target;
} else {
status = ERROR_FD_UNSUPPORTED_UPDATE;
}
flash_intf_local = flash_intf_target;
} else {
status = ERROR_FD_UNSUPPORTED_UPDATE;
}
} else {
status = ERROR_FD_UNSUPPORTED_UPDATE;
}
#else
#error "Build must be either bootloader or interface"
#endif

// Don't allow bootloader updates unless automation is allowed
if (!config_get_automation_allowed() && (FLASH_DECODER_TYPE_BOOTLOADER == type)) {
Expand Down
6 changes: 5 additions & 1 deletion source/daplink/drag-n-drop/flash_manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,14 @@ typedef enum {
STATE_ERROR
} state_t;

#ifndef FLASH_MANAGER_BUFFER_SIZE
#define FLASH_MANAGER_BUFFER_SIZE 1024
#endif

// Target programming expects buffer
// passed in to be 4 byte aligned
__attribute__((aligned(4)))
static uint8_t buf[1024];
static uint8_t buf[FLASH_MANAGER_BUFFER_SIZE];
static bool buf_empty;
static bool current_sector_valid;
static bool page_erase_enabled = false;
Expand Down
4 changes: 3 additions & 1 deletion source/daplink/drag-n-drop/iap_flash_intf.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
#include "crc.h"
#include "info.h"

#if ((DAPLINK_ROM_UPDATE_SIZE != 0) || defined(DAPLINK_BOOTLOADER_UPDATE))

// Application start must be aligned to page write
COMPILER_ASSERT(DAPLINK_ROM_APP_START % DAPLINK_MIN_WRITE_SIZE == 0);
// Application size must be a multiple of write size
Expand Down Expand Up @@ -507,5 +509,5 @@ static error_t critical_erase_and_program(uint32_t addr, const uint8_t *data, ui
static uint8_t target_flash_busy(void){
return (state == STATE_OPEN);
}

#endif
#endif
2 changes: 1 addition & 1 deletion source/daplink/drag-n-drop/vfs_user.c
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ void vfs_user_build_filesystem()
uint32_t file_size;
vfs_file_t file_handle;
// Setup the filesystem based on target parameters
vfs_init(get_daplink_drive_name(), VFS_DISK_SIZE);
vfs_init(get_daplink_drive_name());
// MBED.HTM
file_size = get_file_size(read_file_mbed_htm);
vfs_create_file(get_daplink_url_name(), read_file_mbed_htm, 0, file_size);
Expand Down
89 changes: 46 additions & 43 deletions source/daplink/drag-n-drop/virtual_fs.c
Original file line number Diff line number Diff line change
Expand Up @@ -122,27 +122,54 @@ static bool filename_character_valid(char character);
COMPILER_ASSERT(0x0200 == VFS_SECTOR_SIZE);
// If root directory size changes update max_root_dir_entries
COMPILER_ASSERT(0x0020 == sizeof(root_dir_t) / sizeof(FatDirectoryEntry_t));
static const mbr_t mbr_tmpl = {

#define MBR_BYTES_PER_SECTOR 0x0200
#define MBR_SECTORS_PER_CLUSTER 0x08
#define TOTAL_SECTORS ((VFS_DISK_SIZE + KB(64)) / MBR_BYTES_PER_SECTOR)
#if (TOTAL_SECTORS < (FAT_CLUSTERS_MIN * MBR_SECTORS_PER_CLUSTER))
// #warning "MBR Total Sector resulting in smaller number of FAT clusters than expected"
#define MBR_TOTAL_SECTORS (FAT_CLUSTERS_MIN * MBR_SECTORS_PER_CLUSTER)
#elif (TOTAL_SECTORS > (FAT_CLUSTERS_MAX * MBR_SECTORS_PER_CLUSTER))
// #warning "MBR Total Sector resulting in larger number of FAT clusters than expected"
#define MBR_TOTAL_SECTORS (FAT_CLUSTERS_MAX * MBR_SECTORS_PER_CLUSTER)
#else
#define MBR_TOTAL_SECTORS TOTAL_SECTORS
#endif

#if (MBR_TOTAL_SECTORS >= 0x10000)
#define MBR_TOTAL_LOGICAL_SECTORS 0
#define MBR_BIG_SECTORS_ON_DRIVE MBR_TOTAL_SECTORS
#else
#define MBR_TOTAL_LOGICAL_SECTORS MBR_TOTAL_SECTORS
#define MBR_BIG_SECTORS_ON_DRIVE 0
#endif

// FAT table will likely be larger than needed, but this is allowed by the
// fat specification
#define MBR_NUMBER_OF_CLUSTERS (MBR_TOTAL_SECTORS / MBR_SECTORS_PER_CLUSTER)
#define MBR_LOGICAL_SECTORS_PER_FAT ((MBR_NUMBER_OF_CLUSTERS * 2 + VFS_SECTOR_SIZE - 1) / VFS_SECTOR_SIZE)

const mbr_t mbr = {
/*uint8_t[11]*/.boot_sector = {
0xEB, 0x3C, 0x90,
'M', 'S', 'D', '0', 'S', '4', '.', '1' // OEM Name in text (8 chars max)
},
/*uint16_t*/.bytes_per_sector = 0x0200, // 512 bytes per sector
/*uint8_t */.sectors_per_cluster = 0x08, // 4k cluser
/*uint16_t*/.reserved_logical_sectors = 0x0001, // mbr is 1 sector
/*uint8_t */.num_fats = 0x02, // 2 FATs
/*uint16_t*/.max_root_dir_entries = 0x0020, // 32 dir entries (max)
/*uint16_t*/.total_logical_sectors = 0x1f50, // sector size * # of sectors = drive size
/*uint8_t */.media_descriptor = 0xf8, // fixed disc = F8, removable = F0
/*uint16_t*/.logical_sectors_per_fat = 0x0001, // FAT is 1k - ToDO:need to edit this
/*uint16_t*/.physical_sectors_per_track = 0x0001, // flat
/*uint16_t*/.heads = 0x0001, // flat
/*uint32_t*/.hidden_sectors = 0x00000000, // before mbt, 0
/*uint32_t*/.big_sectors_on_drive = 0x00000000, // 4k sector. not using large clusters
/*uint16_t*/.bytes_per_sector = MBR_BYTES_PER_SECTOR, // 512 bytes per sector
/*uint8_t */.sectors_per_cluster = MBR_SECTORS_PER_CLUSTER, // 4k cluser
/*uint16_t*/.reserved_logical_sectors = 0x0001, // mbr is 1 sector
/*uint8_t */.num_fats = 0x02, // 2 FATs
/*uint16_t*/.max_root_dir_entries = 0x0020, // 32 dir entries (max)
/*uint16_t*/.total_logical_sectors = MBR_TOTAL_LOGICAL_SECTORS, // sector size * # of sectors = drive size
/*uint8_t */.media_descriptor = 0xf8, // fixed disc = F8, removable = F0
/*uint16_t*/.logical_sectors_per_fat = MBR_LOGICAL_SECTORS_PER_FAT, // FAT is 1k - ToDO:need to edit this
/*uint16_t*/.physical_sectors_per_track = 0x0001, // flat
/*uint16_t*/.heads = 0x0001, // flat
/*uint32_t*/.hidden_sectors = 0x00000000, // before mbt, 0
/*uint32_t*/.big_sectors_on_drive = MBR_BIG_SECTORS_ON_DRIVE, // 4k sector. not using large clusters
/*uint8_t */.physical_drive_number = 0x00,
/*uint8_t */.not_used = 0x00, // Current head. Linux tries to set this to 0x1
/*uint8_t */.boot_record_signature = 0x29, // signature is present
/*uint32_t*/.volume_id = 0x27021974, // serial number
/*uint8_t */.not_used = 0x00, // Current head. Linux tries to set this to 0x1
/*uint8_t */.boot_record_signature = 0x29, // signature is present
/*uint32_t*/.volume_id = 0x27021974, // serial number
// needs to match the root dir label
/*char[11]*/.volume_label = {'D', 'A', 'P', 'L', 'I', 'N', 'K', '-', 'D', 'N', 'D'},
// unused by msft - just a label (FAT, FAT12, FAT16)
Expand Down Expand Up @@ -289,7 +316,6 @@ static const FatDirectoryEntry_t dir_entry_tmpl = {
/*uint32_t*/ .filesize = 0x00000000
};

mbr_t mbr;
file_allocation_table_t fat;
virtual_media_t virtual_media[16];
root_dir_t dir_current;
Expand Down Expand Up @@ -320,13 +346,11 @@ static void write_fat(file_allocation_table_t *fat, uint32_t idx, uint16_t val)
fat->f[high_idx] = (val >> 8) & 0xFF;
}

void vfs_init(const vfs_filename_t drive_name, uint32_t disk_size)
void vfs_init(const vfs_filename_t drive_name)
{
uint32_t i;
uint32_t num_clusters;
uint32_t total_sectors;

// Clear everything
memset(&mbr, 0, sizeof(mbr));
memset(&fat, 0, sizeof(fat));
fat_idx = 0;
memset(&virtual_media, 0, sizeof(virtual_media));
Expand All @@ -336,28 +360,7 @@ void vfs_init(const vfs_filename_t drive_name, uint32_t disk_size)
file_change_cb = file_change_cb_stub;
virtual_media_idx = 0;
data_start = 0;
// Initialize MBR
memcpy(&mbr, &mbr_tmpl, sizeof(mbr_t));
total_sectors = ((disk_size + KB(64)) / mbr.bytes_per_sector);
// Make sure this is the right size for a FAT16 volume
if (total_sectors < FAT_CLUSTERS_MIN * mbr.sectors_per_cluster) {
util_assert(0);
total_sectors = FAT_CLUSTERS_MIN * mbr.sectors_per_cluster;
} else if (total_sectors > FAT_CLUSTERS_MAX * mbr.sectors_per_cluster) {
util_assert(0);
total_sectors = FAT_CLUSTERS_MAX * mbr.sectors_per_cluster;
}
if (total_sectors >= 0x10000) {
mbr.total_logical_sectors = 0;
mbr.big_sectors_on_drive = total_sectors;
} else {
mbr.total_logical_sectors = total_sectors;
mbr.big_sectors_on_drive = 0;
}
// FAT table will likely be larger than needed, but this is allowed by the
// fat specification
num_clusters = total_sectors / mbr.sectors_per_cluster;
mbr.logical_sectors_per_fat = (num_clusters * 2 + VFS_SECTOR_SIZE - 1) / VFS_SECTOR_SIZE;

// Initailize virtual media
memcpy(&virtual_media, &virtual_media_tmpl, sizeof(virtual_media_tmpl));
virtual_media[MEDIA_IDX_FAT1].length = VFS_SECTOR_SIZE * mbr.logical_sectors_per_fat;
Expand Down
6 changes: 3 additions & 3 deletions source/daplink/drag-n-drop/virtual_fs.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#define VIRTUAL_FS_H

#include <stdint.h>
#include <stdbool.h>
#include <stdbool.h>

#ifdef __cplusplus
extern "C" {
Expand Down Expand Up @@ -68,8 +68,8 @@ typedef uint32_t (*vfs_read_cb_t)(uint32_t sector_offset, uint8_t *data, uint32_
typedef void (*vfs_file_change_cb_t)(const vfs_filename_t filename, vfs_file_change_t change,
vfs_file_t file, vfs_file_t new_file_data);

// Initialize the filesystem with the given size and name
void vfs_init(const vfs_filename_t drive_name, uint32_t disk_size);
// Initialize the filesystem with the given name
void vfs_init(const vfs_filename_t drive_name);

// Get the total size of the virtual filesystem
uint32_t vfs_get_total_size(void);
Expand Down
10 changes: 6 additions & 4 deletions source/daplink/settings/settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* DAPLink Interface Firmware
* Copyright (c) 2009-2020, ARM Limited, All Rights Reserved
* Copyright 2019, Cypress Semiconductor Corporation
* Copyright 2019, Cypress Semiconductor Corporation
* or a subsidiary of Cypress Semiconductor Corporation.
* SPDX-License-Identifier: Apache-2.0
*
Expand Down Expand Up @@ -74,17 +74,19 @@ static cfg_ram_t config_ram __attribute__((section("cfgram"), zero_init));
static cfg_ram_t config_ram __attribute__((section("cfgram")));
#endif

// Ram copy of RAM config
static cfg_ram_t config_ram_copy;
uint8_t initial_hold_in_bl;

void config_init()
{
cfg_ram_t config_ram_copy;
uint32_t new_size;
// Initialize RAM copy
memset(&config_ram_copy, 0, sizeof(config_ram_copy));
// Read settings from RAM if the key is valid
new_size = sizeof(config_ram);

initial_hold_in_bl = config_ram.hold_in_bl;

if (CFG_KEY == config_ram.key) {
uint32_t size = MIN(config_ram.size, sizeof(config_ram));
new_size = MAX(config_ram.size, sizeof(config_ram));
Expand Down Expand Up @@ -159,7 +161,7 @@ bool config_ram_get_hold_in_bl()

bool config_ram_get_initial_hold_in_bl()
{
return config_ram_copy.hold_in_bl;
return initial_hold_in_bl;
}

bool config_ram_get_assert(char *buf, uint16_t buf_size, uint16_t *line, assert_source_t *source)
Expand Down
20 changes: 6 additions & 14 deletions source/hic_hal/nxp/lpc11u35/daplink_addr.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@
#define DAPLINK_ROM_BL_SIZE 0x00000000

#define DAPLINK_ROM_IF_START 0x00000000
#define DAPLINK_ROM_IF_SIZE 0x0000F000
#define DAPLINK_ROM_IF_SIZE 0x0000FC00

#define DAPLINK_ROM_CONFIG_USER_START 0x0000F000
#define DAPLINK_ROM_CONFIG_USER_SIZE 0x00001000
#define DAPLINK_ROM_CONFIG_USER_START 0x0000FC00
#define DAPLINK_ROM_CONFIG_USER_SIZE 0x00000400

/* RAM sizes */

Expand All @@ -66,23 +66,15 @@

/* Current build */

#if defined(DAPLINK_BL)

#define DAPLINK_ROM_APP_START DAPLINK_ROM_BL_START
#define DAPLINK_ROM_APP_SIZE DAPLINK_ROM_BL_SIZE
#define DAPLINK_ROM_UPDATE_START DAPLINK_ROM_IF_START
#define DAPLINK_ROM_UPDATE_SIZE DAPLINK_ROM_IF_SIZE

#elif defined(DAPLINK_IF)
#if defined(DAPLINK_IF)

#define DAPLINK_ROM_APP_START DAPLINK_ROM_IF_START
#define DAPLINK_ROM_APP_SIZE DAPLINK_ROM_IF_SIZE
#define DAPLINK_ROM_UPDATE_START DAPLINK_ROM_BL_START
#define DAPLINK_ROM_UPDATE_SIZE DAPLINK_ROM_BL_SIZE
#define DAPLINK_ROM_UPDATE_SIZE 0

#else

#error "Build must be either bootloader or interface"
#error "Build must be interface"

#endif

Expand Down
2 changes: 1 addition & 1 deletion source/target/target_family.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ __WEAK const target_family_descriptor_t g_maxim_max3266x_family = {0};
//! descriptors has a weak reference defined above, the entry in this list for a family whose
//! descriptor is not included in the link will resolve to NULL and init_family() can skip it.
__WEAK
const target_family_descriptor_t *g_families[] = {
const target_family_descriptor_t * const g_families[] = {
&g_hw_reset_family,
&g_sw_vectreset_family,
&g_sw_sysresetreq_family,
Expand Down
Loading
Loading