Skip to content

Commit 6f3c006

Browse files
committed
Refactor error reporting and remove font.S
Centralize and simplify error handling across the codebase: add CONFIG_CLIB_USE_UART0 to bootloader-tftp/Common.mk; refactor lib-clib/src/perror.cpp to use stdio (printf/puts) instead of console:: functions; remove lib-hal/console/font.S; and update lib-network sources to include network_private.h and replace console::Error calls with network::Error(__func__, ...) (lib-network/src/core/network_memory.h, lib-network/src/core/tcp.cpp). These changes remove console forward-declarations and route errors through a unified network error API while cleaning up the perror implementation.
1 parent 266aabe commit 6f3c006

7 files changed

Lines changed: 13 additions & 74 deletions

File tree

bootloader-tftp/Common.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ DEFINES+=DISABLE_PRINTF_FLOAT
55

66
DEFINES+=ENABLE_TFTP_SERVER
77
DEFINES+=CONFIG_REMOTECONFIG_MINIMUM
8+
DEFINES+=CONFIG_CLIB_USE_UART0
89

910
DEFINES+=UDP_MAX_PORTS_ALLOWED=3
1011
DEFINES+=ENET_RXBUF_NUM=2 ENET_TXBUF_NUM=2

lib-clib/src/perror.cpp

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,10 @@
2323
* THE SOFTWARE.
2424
*/
2525

26-
#include <stddef.h>
26+
#include <cstdio>
2727
#include <errno.h>
2828

29-
namespace console {
30-
void Error(const char*);
31-
int PutChar(int);
32-
int Puts(const char*);
33-
void Write(const char*, unsigned int);
34-
} // namespace console
35-
36-
/*
37-
errno -l | cut -f3- -d ' ' | sort -V -u | awk '$0="\""$0"\","'
38-
*/
39-
29+
//errno -l | cut -f3- -d ' ' | sort -V -u | awk '$0="\""$0"\","'
4030
const char* const kSysErrlist[] = {"OK",
4131
"Operation not permitted",
4232
"No such file or directory",
@@ -98,11 +88,9 @@ void perror(const char* s) { // NOLINT
9888
}
9989

10090
if (s && *s) {
101-
console::Error(s);
102-
console::Write(": ", 2);
91+
printf("%s: ", s);
10392
}
10493

105-
console::Error(ptr);
106-
console::PutChar('\n');
94+
puts(ptr);
10795
}
10896
}

lib-hal/.cproject

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@
2727
</folderInfo>
2828
<sourceEntries>
2929
<entry excluding="rtc|console|debug|src" flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name=""/>
30-
<entry excluding="uart0" flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="console"/>
31-
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="console/uart0"/>
3230
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="debug"/>
3331
<entry excluding="gd32" flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="src"/>
3432
<entry excluding="com0" flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="src/gd32"/>

lib-hal/.settings/language.settings.xml

Lines changed: 0 additions & 12 deletions
This file was deleted.

lib-hal/console/font.S

Lines changed: 0 additions & 29 deletions
This file was deleted.

lib-network/src/core/network_memory.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,7 @@
3030
#include <cstring>
3131
#include <cassert>
3232

33-
namespace console {
34-
void Error(const char*);
35-
}
33+
#include "network_private.h"
3634

3735
namespace network::memory {
3836
inline constexpr uint32_t kBlocks =
@@ -86,7 +84,7 @@ class Allocator {
8684

8785
uint8_t* Allocate() {
8886
if (IsFull()) {
89-
console::Error("Allocate:Full!\n");
87+
network::Error(__func__, "Allocate:Full!");
9088
return nullptr;
9189
}
9290

@@ -104,7 +102,7 @@ class Allocator {
104102
assert(size <= kBlockSize);
105103

106104
if (IsFull()) {
107-
console::Error("Allocate:Full!\n");
105+
network::Error(__func__, "Allocate:Full!");
108106
return UINT16_MAX;
109107
}
110108

lib-network/src/core/tcp.cpp

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,9 @@
5555
#pragma GCC optimize("O2")
5656
#pragma GCC optimize("no-tree-loop-distribute-patterns")
5757

58-
namespace console {
59-
void Error(const char*);
60-
}
61-
6258
#include <cstdint>
6359
#include <cstring>
6460
#include <algorithm>
65-
#include <cstdio>
6661
#include <cassert>
6762

6863
#include "core/netif.h"
@@ -1499,15 +1494,15 @@ static uint16_t s_local_port = kLocalPortRangeStart;
14991494
ConnHandle Connect(uint32_t remote_ip, uint16_t remote_port, CallbackConnect cb_connect, CallbackData cb_data, void* context) {
15001495
const auto& netif = netif::global::netif_default;
15011496
if (__builtin_expect((netif.ip.addr == 0), 0)) {
1502-
console::Error("Connect: No ip!");
1497+
network::Error(__func__, "Connect: No ip!");
15031498
return kInvalidConnHandle;
15041499
}
15051500

15061501
uint32_t out_index = 0;
15071502

15081503
auto* tcb = AllocTcb(remote_port, &out_index);
15091504
if (tcb == nullptr) {
1510-
console::Error("Connect: No TCB!");
1505+
network::Error(__func__, "Connect: No TCB!");
15111506
return kInvalidConnHandle;
15121507
}
15131508

@@ -1547,14 +1542,14 @@ ConnHandle Connect(uint32_t remote_ip, uint16_t remote_port, CallbackConnect cb_
15471542
int32_t Close(ConnHandle conn_handle) // graceful FIN
15481543
{
15491544
if (conn_handle >= TCP_MAX_TCBS_ALLOWED) {
1550-
console::Error("Close: Connection handle!\n");
1545+
network::Error(__func__, "Close: Connection handle!");
15511546
return -1;
15521547
}
15531548

15541549
auto* c = &s_tcbs[conn_handle];
15551550

15561551
if (!c->in_use || c->state == kStateClosed) {
1557-
console::Error("Close: TCB!\n");
1552+
network::Error(__func__, "Close: TCB!");
15581553
return -1;
15591554
}
15601555

@@ -1573,7 +1568,7 @@ int32_t Close(ConnHandle conn_handle) // graceful FIN
15731568

15741569
// We only support graceful close from states where FIN makes sense here.
15751570
if (c->state != kStateEstablished && c->state != kStateCloseWait) {
1576-
console::Error("Close: Not graceful!\n");
1571+
network::Error(__func__, "Close: Not graceful!");
15771572
return -1;
15781573
}
15791574

0 commit comments

Comments
 (0)