8000 Multiple RAM/ROM savings (#1000) · ARMmbed/DAPLink@fec4f08 · GitHub
[go: up one dir, main page]

Skip to content

Commit fec4f08

Browse files
authored
Multiple RAM/ROM savings (#1000)
2 parents 61a4a8e + e6db541 commit fec4f08

File tree

11 files changed

+113
-113
lines changed

11 files changed

+113
-113
lines changed

projects.yaml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -459,17 +459,14 @@ projects:
459459
- *module_if
460460
- *module_hic_lpc11u35
461461
- records/board/musca_a.yaml
462-
- records/tools/gcc_arm_lto.yaml
463462
lpc11u35_musca_b_eflash_if:
464463
- *module_if
465464
- *module_hic_lpc11u35
466465
- records/board/musca_b_eflash.yaml
467-
- records/tools/gcc_arm_lto.yaml
468466
lpc11u35_musca_b_if:
469467
- *module_if
470468
- *module_hic_lpc11u35
471469
- records/board/musca_b.yaml
472-
- records/tools/gcc_arm_lto.yaml
473470
lpc11u35_nz32_sc151_if:
474471
- *module_if
475472
- *module_hic_lpc11u35

source/daplink/drag-n-drop/flash_decoder.c

Lines changed: 41 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -121,57 +121,57 @@ error_t flash_decoder_get_flash(flash_decoder_type_t type, uint32_t addr, bool a
121121
flash_start_local = 0;
122122
flash_intf_local = 0;
123123

124-
if (daplink_is_bootloader()) {
125-
if (FLASH_DECODER_TYPE_INTERFACE == type) {
126-
if (addr_valid && (DAPLINK_ROM_IF_START != addr)) {
127-
// Address is wrong so display error message
128-
status = ERROR_FD_INTF_UPDT_ADDR_WRONG;
129-
} else {
130-
// Setup for update
131-
flash_start_local = DAPLINK_ROM_IF_START;
132-
flash_intf_local = flash_intf_iap_protected;
133-
}
134-
} else if (FLASH_DECODER_TYPE_TARGET == type) {
135-
if (addr_valid && (DAPLINK_ROM_IF_START != addr)) {
136-
// Address is wrong so display error message
137-
status = ERROR_FD_INTF_UPDT_ADDR_WRONG;
138-
} else {
139-
// "Target" update in this case would be a 3rd party interface application
140-
flash_start_local = DAPLINK_ROM_IF_START;
141-
flash_intf_local = flash_intf_iap_protected;
142-
}
124+
#if defined(DAPLINK_BL)
125+
if (FLASH_DECODER_TYPE_INTERFACE == type) {
126+
if (addr_valid && (DAPLINK_ROM_IF_START != addr)) {
127+
// Address is wrong so display error message
128+
status = ERROR_FD_INTF_UPDT_ADDR_WRONG;
143129
} else {
144-
status = ERROR_FD_UNSUPPORTED_UPDATE;
130+
// Setup for update
131+
flash_start_local = DAPLINK_ROM_IF_START;
132+
flash_intf_local = flash_intf_iap_protected;
145133
}
146-
} else if (daplink_is_interface()) {
147-
if (FLASH_DECODER_TYPE_BOOTLOADER == type) {
148-
if (addr_valid && (DAPLINK_ROM_BL_START != addr)) {
149-
// Address is wrong so display error message
150-
status = ERROR_FD_BL_UPDT_ADDR_WRONG;
151-
} else {
152-
// Setup for update
153-
flash_start_local = DAPLINK_ROM_BL_START;
154-
flash_intf_local = flash_intf_iap_protected;
155-
}
156-
} else if (FLASH_DECODER_TYPE_TARGET == type) {
157-
if (g_board_info.target_cfg) {
158-
region_info_t * region = g_board_info.target_cfg->flash_regions;
159-
for (; region->start != 0 || region->end != 0; ++region) {
160-
if (kRegionIsDefault == region->flags) {
161-
flash_start_local = region->start;
162-
break;
163-
}
134+
} else if (FLASH_DECODER_TYPE_TARGET == type) {
135+
if (addr_valid && (DAPLINK_ROM_IF_START != addr)) {
136+
// Address is wrong so display error message
137+
status = ERROR_FD_INTF_UPDT_ADDR_WRONG;
138+
} else {
139+
// "Target" update in this case would be a 3rd party interface application
140+
flash_start_local = DAPLINK_ROM_IF_START;
141+
flash_intf_local = flash_intf_iap_protected;
142+
}
143+
} else {
144+
status = ERROR_FD_UNSUPPORTED_UPDATE;
145+
}
146+
#elif defined(DAPLINK_IF)
147+
if (FLASH_DECODER_TYPE_BOOTLOADER == type) {
148+
if (addr_valid && (DAPLINK_ROM_BL_START != addr)) {
149+
// Address is wrong so display error message
150+
status = ERROR_FD_BL_UPDT_ADDR_WRONG;
151+
} else {
152+
// Setup for update
153+
flash_start_local = DAPLINK_ROM_BL_START;
154+
flash_intf_local = flash_intf_iap_protected;
155+
}
156+
} else if (FLASH_DECODER_TYPE_TARGET == type) {
157+
if (g_board_info.target_cfg) {
158+
region_info_t * region = g_board_info.target_cfg->flash_regions;
159+
for (; region->start != 0 || region->end != 0; ++region) {
160+
if (kRegionIsDefault == region->flags) {
161+
flash_start_local = region->start;
162+
break;
164163
}
165-
flash_intf_local = flash_intf_target;
166-
} else {
167-
status = ERROR_FD_UNSUPPORTED_UPDATE;
168164
}
165+
flash_intf_local = flash_intf_target;
169166
} else {
170167
status = ERROR_FD_UNSUPPORTED_UPDATE;
171168
}
172169
} else {
173170
status = ERROR_FD_UNSUPPORTED_UPDATE;
174171
}
172+
#else
173+
#error "Build must be either bootloader or interface"
174+
#endif
175175

176176
// Don't allow bootloader updates unless automation is allowed
177177
if (!config_get_automation_allowed() && (FLASH_DECODER_TYPE_BOOTLOADER == type)) {

source/daplink/drag-n-drop/flash_manager.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,14 @@ typedef enum {
4444
STATE_ERROR
4545
} state_t;
4646

47+
#ifndef FLASH_MANAGER_BUFFER_SIZE
48+
#define FLASH_MANAGER_BUFFER_SIZE 1024
49+
#endif
50+
4751
// Target programming expects buffer
4852
// passed in to be 4 byte aligned
4953
__attribute__((aligned(4)))
50-
static uint8_t buf[1024];
54+
static uint8_t buf[FLASH_MANAGER_BUFFER_SIZE];
5155
static bool buf_empty;
5256
static bool current_sector_valid;
5357
static bool page_erase_enabled = false;

source/daplink/drag-n-drop/iap_flash_intf.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
#include "crc.h"
3333
#include "info.h"
3434

35+
#if ((DAPLINK_ROM_UPDATE_SIZE != 0) || defined(DAPLINK_BOOTLOADER_UPDATE))
36+
3537
// Application start must be aligned to page write
3638
COMPILER_ASSERT(DAPLINK_ROM_APP_START % DAPLINK_MIN_WRITE_SIZE == 0);
3739
// Application size must be a multiple of write size
@@ -507,5 +509,5 @@ static error_t critical_erase_and_program(uint32_t addr, const uint8_t *data, ui
507509
static uint8_t target_flash_busy(void){
508510
return (state == STATE_OPEN);
509511
}
510-
512+
#endif
511513
#endif

source/daplink/drag-n-drop/vfs_user.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ void vfs_user_build_filesystem()
132132
uint32_t file_size;
133133
vfs_file_t file_handle;
134134
// Setup the filesystem based on target parameters
135-
vfs_init(get_daplink_drive_name(), VFS_DISK_SIZE);
135+
vfs_init(get_daplink_drive_name());
136136
// MBED.HTM
137137
file_size = get_file_size(read_file_mbed_htm);
138138
vfs_create_file(get_daplink_url_name(), read_file_mbed_htm, 0, file_size);

source/daplink/drag-n-drop/virtual_fs.c

Lines changed: 46 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -122,27 +122,54 @@ static bool filename_character_valid(char character);
122122
COMPILER_ASSERT(0x0200 == VFS_SECTOR_SIZE);
123123
// If root directory size changes update max_root_dir_entries
124124
COMPILER_ASSERT(0x0020 == sizeof(root_dir_t) / sizeof(FatDirectoryEntry_t));
125-
static const mbr_t mbr_tmpl = {
125+
126+
#define MBR_BYTES_PER_SECTOR 0x0200
127+
#define MBR_SECTORS_PER_CLUSTER 0x08
128+
#define TOTAL_SECTORS ((VFS_DISK_SIZE + KB(64)) / MBR_BYTES_PER_SECTOR)
129+
#if (TOTAL_SECTORS < (FAT_CLUSTERS_MIN * MBR_SECTORS_PER_CLUSTER))
130+
// #warning "MBR Total Sector resulting in smaller number of FAT clusters than expected"
131+
#define MBR_TOTAL_SECTORS (FAT_CLUSTERS_MIN * MBR_SECTORS_PER_CLUSTER)
132+
#elif (TOTAL_SECTORS > (FAT_CLUSTERS_MAX * MBR_SECTORS_PER_CLUSTER))
133+
// #warning "MBR Total Sector resulting in larger number of FAT clusters than expected"
134+
#define MBR_TOTAL_SECTORS (FAT_CLUSTERS_MAX * MBR_SECTORS_PER_CLUSTER)
135+
#else
136+
#define MBR_TOTAL_SECTORS TOTAL_SECTORS
137+
#endif
138+
139+
#if (MBR_TOTAL_SECTORS >= 0x10000)
140+
#define MBR_TOTAL_LOGICAL_SECTORS 0
141+
#define MBR_BIG_SECTORS_ON_DRIVE MBR_TOTAL_SECTORS
142+
#else
143+
#define MBR_TOTAL_LOGICAL_SECTORS MBR_TOTAL_SECTORS
144+
#define MBR_BIG_SECTORS_ON_DRIVE 0
145+
#endif
146+
147+
// FAT table will likely be larger than needed, but this is allowed by the
148+
// fat specification
149+
#define MBR_NUMBER_OF_CLUSTERS (MBR_TOTAL_SECTORS / MBR_SECTORS_PER_CLUSTER)
150+
#define MBR_LOGICAL_SECTORS_PER_FAT ((MBR_NUMBER_OF_CLUSTERS * 2 + VFS_SECTOR_SIZE - 1) / VFS_SECTOR_SIZE)
151+
152+
const mbr_t mbr = {
126153
/*uint8_t[11]*/.boot_sector = {
127154
0xEB, 0x3C, 0x90,
128155
'M', 'S', 'D', '0', 'S', '4', '.', '1' // OEM Name in text (8 chars max)
129156
},
130-
/*uint16_t*/.bytes_per_sector = 0x0200, // 512 bytes per sector
131-
/*uint8_t */.sectors_per_cluster = 0x08, // 4k cluser
132-
/*uint16_t*/.reserved_logical_sectors = 0x0001, // mbr is 1 sector
133-
/*uint8_t */.num_fats = 0x02, // 2 FATs
134-
/*uint16_t*/.max_root_dir_entries = 0x0020, // 32 dir entries (max)
135-
/*uint16_t*/.total_logical_sectors = 0x1f50, // sector size * # of sectors = drive size
136-
/*uint8_t */.media_descriptor = 0xf8, // fixed disc = F8, removable = F0
137-
/*uint16_t*/.logical_sectors_per_fat = 0x0001, // FAT is 1k - ToDO:need to edit this
138-
/*uint16_t*/.physical_sectors_per_track = 0x0001, // flat
139-
/*uint16_t*/.heads = 0x0001, // flat
140-
/*uint32_t*/.hidden_sectors = 0x00000000, // before mbt, 0
141-
/*uint32_t*/.big_sectors_on_drive = 0x00000000, // 4k sector. not using large clusters
157+
/*uint16_t*/.bytes_per_sector = MBR_BYTES_PER_SECTOR, // 512 bytes per sector
158+
/*uint8_t */.sectors_per_cluster = MBR_SECTORS_PER_CLUSTER, // 4k cluser
159+
/*uint16_t*/.reserved_logical_sectors = 0x0001, // mbr is 1 sector
160+
/*uint8_t */.num_fats = 0x02, // 2 FATs
161+
/*uint16_t*/.max_root_dir_entries = 0x0020, // 32 dir entries (max)
162+
/*uint16_t*/.total_logical_sectors = MBR_TOTAL_LOGICAL_SECTORS, // sector size * # of sectors = drive size
163+
/*uint8_t */.media_descriptor = 0xf8, // fixed disc = F8, removable = F0
164+
/*uint16_t*/.logical_sectors_per_fat = MBR_LOGICAL_SECTORS_PER_FAT, // FAT is 1k - ToDO:need to edit this
165+
/*uint16_t*/.physical_sectors_per_track = 0x0001, // flat
166+
/*uint16_t*/.heads = 0x0001, // flat
167+
/*uint32_t*/.hidden_sectors = 0x00000000, // before mbt, 0
168+
/*uint32_t*/.big_sectors_on_drive = MBR_BIG_SECTORS_ON_DRIVE, // 4k sector. not using large clusters
142169
/*uint8_t */.physical_drive_number = 0x00,
143-
/*uint8_t */.not_used = 0x00, // Current head. Linux tries to set this to 0x1
144-
/*uint8_t */.boot_record_signature = 0x29, // signature is present
145-
/*uint32_t*/.volume_id = 0x27021974, // serial number
170+
/*uint8_t */.not_used = 0x00, // Current head. Linux tries to set this to 0x1
171+
/*uint8_t */.boot_record_signature = 0x29, // signature is present
172+
/*uint32_t*/.volume_id = 0x27021974, // serial number
146173
// needs to match the root dir label
147174
/*char[11]*/.volume_label = {'D', 'A', 'P', 'L', 'I', 'N', 'K', '-', 'D', 'N', 'D'},
148175
// unused by msft - just a label (FAT, FAT12, FAT16)
@@ -289,7 +316,6 @@ static const FatDirectoryEntry_t dir_entry_tmpl = {
289316
/*uint32_t*/ .filesize = 0x00000000
290317
};
291318

292-
mbr_t mbr;
293319
file_allocation_table_t fat;
294320
virtual_media_t virtual_media[16];
295321
root_dir_t dir_current;
@@ -320,13 +346,11 @@ static void write_fat(file_allocation_table_t *fat, uint32_t idx, uint16_t val)
320346
fat->f[high_idx] = (val >> 8) & 0xFF;
321347
}
322348

323-
void vfs_init(const vfs_filename_t drive_name, uint32_t disk_size)
349+
void vfs_init(const vfs_filename_t drive_name)
324350
{
325351
uint32_t i;
326-
uint32_t num_clusters;
327-
uint32_t total_sectors;
352+
328353
// Clear everything
329-
memset(&mbr, 0, sizeof(mbr));
330354
memset(&fat, 0, sizeof(fat));
331355
fat_idx = 0;
332356
memset(&virtual_media, 0, sizeof(virtual_media));
@@ -336,28 +360,7 @@ void vfs_init(const vfs_filename_t drive_name, uint32_t disk_size)
336360
file_change_cb = file_change_cb_stub;
337361
virtual_media_idx = 0;
338362
data_start = 0;
339-
// Initialize MBR
340-
memcpy(&mbr, &mbr_tmpl, sizeof(mbr_t));
341-
total_sectors = ((disk_size + KB(64)) / mbr.bytes_per_sector);
342-
// Make sure this is the right size for a FAT16 volume
343-
if (total_sectors < FAT_CLUSTERS_MIN * mbr.sectors_per_cluster) {
344-
util_assert(0);
345-
total_sectors = FAT_CLUSTERS_MIN * mbr.sectors_per_cluster;
346-
} else if (total_sectors > FAT_CLUSTERS_MAX * mbr.sectors_per_cluster) {
347-
util_assert(0);
348-
total_sectors = FAT_CLUSTERS_MAX * mbr.sectors_per_cluster;
349-
}
350-
if (total_sectors >= 0x10000) {
351-
mbr.total_logical_sectors = 0;
352-
mbr.big_sectors_on_drive = total_sectors;
353-
} else {
354-
mbr.total_logical_sectors = total_sectors;
355-
mbr.big_sectors_on_drive = 0;
356-
}
357-
// FAT table will likely be larger than needed, but this is allowed by the
358-
// fat specification
359-
num_clusters = total_sectors / mbr.sectors_per_cluster;
360-
mbr.logical_sectors_per_fat = (num_clusters * 2 + VFS_SECTOR_SIZE - 1) / VFS_SECTOR_SIZE;
363+
361364
// Initailize virtual media
362365
memcpy(&virtual_media, &virtual_media_tmpl, sizeof(virtual_media_tmpl));
363366
virtual_media[MEDIA_IDX_FAT1].length = VFS_SECTOR_SIZE * mbr.logical_sectors_per_fat;

source/daplink/drag-n-drop/virtual_fs.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
#define VIRTUAL_FS_H
2424

2525
#include <stdint.h>
26-
#include <stdbool.h>
26+
#include <stdbool.h>
2727

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

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

7474
// Get the total size of the virtual filesystem
7575
uint32_t vfs_get_total_size(void);

source/daplink/settings/settings.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*
55
* DAPLink Interface Firmware
66
* Copyright (c) 2009-2020, ARM Limited, All Rights Reserved
7-
* Copyright 2019, Cypress Semiconductor Corporation
7+
* Copyright 2019, Cypress Semiconductor Corporation
88
* or a subsidiary of Cypress Semiconductor Corporation.
99
* SPDX-License-Identifier: Apache-2.0
1010
*
@@ -74,17 +74,19 @@ static cfg_ram_t config_ram __attribute__((section("cfgram"), zero_init));
7474
static cfg_ram_t config_ram __attribute__((section("cfgram")));
7575
#endif
7676

77-
// Ram copy of RAM config
78-
static cfg_ram_t config_ram_copy;
77+
uint8_t initial_hold_in_bl;
7978

8079
void config_init()
8180
{
81+
cfg_ram_t config_ram_copy;
8282
uint32_t new_size;
8383
// Initialize RAM copy
8484
memset(&config_ram_copy, 0, sizeof(config_ram_copy));
8585
// Read settings from RAM if the key is valid
8686
new_size = sizeof(config_ram);
8787

88+
initial_hold_in_bl = config_ram.hold_in_bl;
89+
8890
if (CFG_KEY == config_ram.key) {
8991
uint32_t size = MIN(config_ram.size, sizeof(config_ram));
9092
new_size = MAX(config_ram.size, sizeof(config_ram));
@@ -159,7 +161,7 @@ bool config_ram_get_hold_in_bl()
159161

160162
bool config_ram_get_initial_hold_in_bl()
161163
{
162-
return config_ram_copy.hold_in_bl;
164+
return initial_hold_in_bl;
163165
}
164166

165167
bool config_ram_get_assert(char *buf, uint16_t buf_size, uint16_t *line, assert_source_t *source)

source/hic_hal/nxp/lpc11u35/daplink_addr.h

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@
3939
#define DAPLINK_ROM_BL_SIZE 0x00000000
4040

4141
#define DAPLINK_ROM_IF_START 0x00000000
42-
#define DAPLINK_ROM_IF_SIZE 0x0000F000
42+
#define DAPLINK_ROM_IF_SIZE 0x0000FC00
4343

44-
#define DAPLINK_ROM_CONFIG_USER_START 0x0000F000
45-
#define DAPLINK_ROM_CONFIG_USER_SIZE 0x00001000
44+
#define DAPLINK_ROM_CONFIG_USER_START 0x0000FC00
45+
#define DAPLINK_ROM_CONFIG_USER_SIZE 0x00000400
4646

4747
/* RAM sizes */
4848

@@ -66,23 +66,15 @@
6666

6767
/* Current build */
6868

69-
#if defined(DAPLINK_BL)
70-
71-
#define DAPLINK_ROM_APP_START DAPLINK_ROM_BL_START
72-
#define DAPLINK_ROM_APP_SIZE DAPLINK_ROM_BL_SIZE
73-
#define DAPLINK_ROM_UPDATE_START DAPLINK_ROM_IF_START
74-
#define DAPLINK_ROM_UPDATE_SIZE DAPLINK_ROM_IF_SIZE
75-
76-
#elif defined(DAPLINK_IF)
69+
#if defined(DAPLINK_IF)
7770

7871
#define DAPLINK_ROM_APP_START DAPLINK_ROM_IF_START
7972
#define DAPLINK_ROM_APP_SIZE DAPLINK_ROM_IF_SIZE
80-
#define DAPLINK_ROM_UPDATE_START DAPLINK_ROM_BL_START
81-
#define DAPLINK_ROM_UPDATE_SIZE DAPLINK_ROM_BL_SIZE
73+
#define DAPLINK_ROM_UPDATE_SIZE 0
8274

8375
#else
8476

85-
#error "Build must be either bootloader or interface"
77+
#error "Build must be interface"
8678

8779
#endif
8880

source/target/target_family.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ __WEAK const target_family_descriptor_t g_maxim_max3266x_family = {0};
7373
//! descriptors has a weak reference defined above, the entry in this list for a family whose
7474
//! descriptor is not included in the link will resolve to NULL and init_family() can skip it.
7575
__WEAK
76-
const target_family_descriptor_t *g_families[] = {
76+
const target_family_descriptor_t * const g_families[] = {
7777
&g_hw_reset_family,
7878
&g_sw_vectreset_family,
7979
&g_sw_sysresetreq_family,

0 commit comments

Comments
 (0)
0