Skip to content

Commit e8ecac5

Browse files
dgarskedanielinux
authored andcommitted
Peer review cleanups
1 parent 8f407ce commit e8ecac5

3 files changed

Lines changed: 29 additions & 5 deletions

File tree

src/port/lpc54s018/fix_checksum.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,18 @@ def find_vector_offset(data):
3232
return 0
3333

3434

35+
def is_flash_image(data, off):
36+
"""Decide flash vs RAM by inspecting the reset handler (vector[1]).
37+
Flash-linked images have the reset handler in SPIFI XIP space
38+
(0x10000000+); RAM-linked images point into SRAM (0x20000000+).
39+
RAM builds have the vector table at file offset 0 too, so offset
40+
alone can't be used to distinguish them. """
41+
if off + 8 > len(data):
42+
return False
43+
reset = struct.unpack_from('<I', data, off + 4)[0]
44+
return 0x10000000 <= reset < 0x20000000
45+
46+
3547
def patch_vector_checksum(f, off):
3648
"""Patch vector[7] (offset+0x1C) so vectors[0..7] sum to 0."""
3749
f.seek(off)
@@ -98,7 +110,8 @@ def main():
98110
print("Error: file too small")
99111
sys.exit(1)
100112

101-
if off == 0:
113+
flash_image = (off == 0) and is_flash_image(data, off)
114+
if flash_image:
102115
# Flash boot build: write enhanced boot block first
103116
if size < 0x160 + 100:
104117
print("Error: image too small for enhanced boot block")
@@ -116,7 +129,7 @@ def main():
116129
print("ERROR: checksum verification failed (sum=0x%08X)" % total)
117130
sys.exit(1)
118131

119-
if off == 0:
132+
if flash_image:
120133
print("Vector checksum patched: offset=0x%X entry[7]=0x%08X "
121134
"(+ enhanced boot block @ 0x24/0x160)" % (off, cksum))
122135
else:

src/port/lpc54s018/main.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,13 +91,17 @@ void SysTick_Handler(void)
9191
}
9292

9393
/* Atomic read of 64-bit tick_ms on 32-bit Cortex-M4.
94-
* Briefly disables interrupts to prevent torn reads. */
94+
* Briefly disables interrupts to prevent torn reads while preserving
95+
* the caller's prior interrupt mask state (save/restore PRIMASK rather
96+
* than blindly re-enabling). */
9597
static uint64_t get_tick_ms(void)
9698
{
9799
uint64_t val;
100+
uint32_t primask;
101+
__asm volatile ("mrs %0, primask" : "=r" (primask) :: "memory");
98102
__asm volatile ("cpsid i" ::: "memory");
99103
val = tick_ms;
100-
__asm volatile ("cpsie i" ::: "memory");
104+
__asm volatile ("msr primask, %0" :: "r" (primask) : "memory");
101105
return val;
102106
}
103107

src/port/lpc_enet/lpc_enet.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -526,9 +526,16 @@ int lpc_enet_init(struct wolfIP_ll_dev *ll, const uint8_t *mac)
526526
mac_start();
527527

528528
/* Retry PHY detection after MAC is fully started.
529-
* MDIO can be unreliable before the MAC is running on some boards. */
529+
* MDIO can be unreliable before the MAC is running on some boards.
530+
* On success, re-run phy_init() (resets PHY, restarts autoneg) and
531+
* refresh MAC speed/duplex so the MAC isn't left at the default
532+
* 100/full guess from config_mac(). */
530533
if (phy_addr < 0) {
531534
phy_addr = phy_detect_retry();
535+
if (phy_addr >= 0) {
536+
phy_init();
537+
config_speed_duplex();
538+
}
532539
}
533540

534541
if (phy_addr < 0) {

0 commit comments

Comments
 (0)