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

Daniel/duo/full hardened malloc removal #241

Merged
merged 64 commits into from
Apr 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
3af51cc
testing changes
Unreal-Dan Apr 11, 2024
868506c
some test changes
Unreal-Dan Apr 11, 2024
721dd74
don't need this
Unreal-Dan Apr 11, 2024
e497c5c
more stuff
Unreal-Dan Apr 12, 2024
24d8742
more crap
Unreal-Dan Apr 12, 2024
e46ebc1
more work
Unreal-Dan Apr 16, 2024
ade0f6e
makefile adjustments
Unreal-Dan Apr 19, 2024
5db153f
flash storage kinda works
Unreal-Dan Apr 19, 2024
9cd94c3
storage changes
Unreal-Dan Apr 20, 2024
d1786db
Merge branch 'daniel/duo/storage_slots' into daniel/duo/unserialize_h…
Unreal-Dan Apr 20, 2024
00e6486
lots of changes
Unreal-Dan Apr 20, 2024
3fb9138
fixes
Unreal-Dan Apr 20, 2024
c34316c
fixes
Unreal-Dan Apr 20, 2024
2b75deb
fixes
Unreal-Dan Apr 20, 2024
3ca27e9
fixes
Unreal-Dan Apr 20, 2024
8ba99a9
fixes
Unreal-Dan Apr 20, 2024
015b816
fixes
Unreal-Dan Apr 20, 2024
bca5ed8
fixes
Unreal-Dan Apr 20, 2024
909c739
fixes
Unreal-Dan Apr 20, 2024
54351ef
fixes
Unreal-Dan Apr 20, 2024
1b24754
fixes
Unreal-Dan Apr 20, 2024
9930749
fixes
Unreal-Dan Apr 20, 2024
728bb79
fixes
Unreal-Dan Apr 20, 2024
f5726ea
fixes
Unreal-Dan Apr 20, 2024
dd579c7
8 modes for the lols
Unreal-Dan Apr 20, 2024
1c313e0
fixed auto cycler in randomizer
Unreal-Dan Apr 20, 2024
d2ad36a
minor fix
Unreal-Dan Apr 20, 2024
3d9ec28
fix to storage on desktop and auto cycle disable
Unreal-Dan Apr 20, 2024
52ce052
fix for linux storage code
Unreal-Dan Apr 20, 2024
a7a13d8
fixed up tests and autocycle
Unreal-Dan Apr 20, 2024
7238cea
fixed tests
Unreal-Dan Apr 20, 2024
6acb6d9
don't need this
Unreal-Dan Apr 20, 2024
fbe4eda
don't need this
Unreal-Dan Apr 20, 2024
eec9c3f
adjustments
Unreal-Dan Apr 21, 2024
85bda45
fixes
Unreal-Dan Apr 21, 2024
8d4512b
Merge branch 'duo' into daniel/duo/unserialize_harden
Unreal-Dan Apr 26, 2024
c2de85d
work for now
Unreal-Dan Apr 26, 2024
b69bfca
added serialize hardening too
Unreal-Dan Apr 26, 2024
2a17896
hardened all serialization code
Unreal-Dan Apr 26, 2024
72e9772
hardened all serialize code
Unreal-Dan Apr 26, 2024
5eff25a
Merge branch 'daniel/core/serialize_harden' into daniel/duo/unseriali…
Unreal-Dan Apr 26, 2024
8ec6bfc
more hardening
Unreal-Dan Apr 26, 2024
c3ea56d
fix wasm
Unreal-Dan Apr 26, 2024
cdb708c
Merge branch 'daniel/core/serialize_harden' into daniel/duo/serialize…
Unreal-Dan Apr 26, 2024
c4a5b80
Daniel/core/serialize harden (#226)
Unreal-Dan Apr 26, 2024
205a852
Merge branch 'daniel/duo/serialize_harden' into daniel/duo/unserializ…
Unreal-Dan Apr 26, 2024
45a58aa
restored modesharing and serialize unsafety
Unreal-Dan Apr 26, 2024
2e4684e
Merge branch 'daniel/duo/unserialize_harden' into daniel/duo/unserial…
Unreal-Dan Apr 26, 2024
5e5b26a
fixes
Unreal-Dan Apr 26, 2024
a55441c
minor fix
Unreal-Dan Apr 27, 2024
98912a0
minor fix
Unreal-Dan Apr 27, 2024
73f53a9
Merge branch 'daniel/duo/unserialize_harden' into daniel/duo/unserial…
Unreal-Dan Apr 27, 2024
8615209
fixed storage size
Unreal-Dan Apr 27, 2024
6e57d56
Separate save header and mode loading (#240)
Unreal-Dan Apr 27, 2024
365933f
Merge branch 'master' into daniel/duo/unserialize_full_harden
Unreal-Dan Apr 27, 2024
05be429
minor fix
Unreal-Dan Apr 27, 2024
6b45d28
Colorset refactor
Unreal-Dan Apr 29, 2024
944daa9
some fixes to colorset refactor
Unreal-Dan Apr 29, 2024
ed19a11
button refactor
Unreal-Dan Apr 29, 2024
b7eced3
mode sharing individual led
Unreal-Dan Apr 29, 2024
141ed5f
fixed some casts
Unreal-Dan Apr 29, 2024
a190d7a
improved comment
Unreal-Dan Apr 29, 2024
f053b72
recorded tests
Unreal-Dan Apr 29, 2024
995c48f
minor fix
Unreal-Dan Apr 29, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 35 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,31 @@ CPU_SPEED = 10000000L
# the port for serial upload
SERIAL_PORT = COM11

# whether eeprom is erased on flash (must write this fuse first to take effect)
SAVE_EEPROM = 1
FUSE0 = 0b00000000
FUSE2 = 0x02
FUSE5 = 0b1100010$(SAVE_EEPROM)
FUSE6 = 0x04

# WDTCFG { PERIOD=OFF, WINDOW=OFF }
WDTCFG = 0b00000000
# BODCFG { SLEEP=DIS, ACTIVE=DIS, SAMPFREQ=1KHZ, LVL=BODLEVEL0 }
BODCFG = 0x00
# OSCCFG { FREQSEL=20mhz, OSCLOCK=CLEAR }
OSCCFG = 0x02
# RESERVED
#FUSE3 = 0x00
# TCD0CFG { CMPA=CLEAR, CMPB=CLEAR, CMPC=CLEAR, CMPD=CLEAR, CMPAEN=CLEAR, CPMCEN=CLEAR, CMPDEN=CLEAR }
TCD0CFG = 0x00
# SYSCFG0
SYSCFG0 = 0b1100010$(SAVE_EEPROM)
# SYSCFG1 { SUT=64ms }
SYSCFG1 = 0x07
# fuse7 = APPEND
FUSE7 = 0x00
APPEND = 0x00
# fuse8 = BOOTEND
FUSE8 = 0x7e
# This controls the amount of storage for modes at the end of the flash memory,
# it is the boundary for the segment that can be rewritten by the program, 0x7e
# means 0x7e00/0x8000 bytes are program and 0x200 bytes are reserved for flash
# storage of modes, this does not include the eeprom.
BOOTEND = 0x7e

CFLAGS = -g \
-Os \
Expand Down Expand Up @@ -107,7 +123,7 @@ all: $(TARGET).hex
$(OBJDUMP) --disassemble --source --line-numbers --demangle --section=.text $(TARGET).elf > $(TARGET).lst
$(NM) --numeric-sort --line-numbers --demangle --print-size --format=s $(TARGET).elf > $(TARGET).map
chmod +x avrsize.sh
./avrsize.sh $(TARGET).elf
./avrsize.sh $(TARGET).elf $(BOOTEND)00

$(TARGET).hex: $(TARGET).elf
$(OBJCOPY) -O binary -R .eeprom $(TARGET).elf $(TARGET).bin
Expand All @@ -124,11 +140,21 @@ $(TARGET).elf: $(OBJS)
$(CC) $(CFLAGS) -c $< -o $@

upload: $(TARGET).hex
$(AVRDUDE) $(AVRDUDE_FLAGS) -Ufuse0:w:$(FUSE0):m -Ufuse2:w:$(FUSE2):m -Ufuse5:w:$(FUSE5):m -Ufuse6:w:$(FUSE6):m -Ufuse7:w:$(FUSE7):m -Ufuse8:w:$(FUSE8):m -Uflash:w:$(TARGET).hex:i
$(AVRDUDE) $(AVRDUDE_FLAGS) \
-Ufuse0:w:$(WDTCFG):m \
-Ufuse1:w:$(BODCFG):m \
-Ufuse2:w:$(OSCCFG):m \
-Ufuse4:w:$(TCD0CFG):m \
-Ufuse5:w:$(SYSCFG0):m \
-Ufuse6:w:$(SYSCFG1):m \
-Ufuse7:w:$(APPEND):m \
-Ufuse8:w:$(BOOTEND):m \
-Uflash:w:$(TARGET).hex:i

# upload via SerialUPDI
serial: $(TARGET).hex
$(PYTHON) -u $(PYPROG) -t uart -u $(SERIAL_PORT) -b 921600 -d $(AVRDUDE_CHIP) --fuses 0:$(FUSE0) 2:$(FUSE2) 5:$(FUSE5) 6:$(FUSE6) 7:$(FUSE7) 8:$(FUSE8) -f $< -a write -v
$(PYTHON) -u $(PYPROG) -t uart -u $(SERIAL_PORT) -b 921600 -d $(AVRDUDE_CHIP) \
--fuses 0:$(WDTCFG) 1:$(BODCFG) 2:$(OSCCFG) 4:$(TCD0CFG) 5:$(SYSCFG0) 6:$(SYSCFG1) 7:$(APPEND) 8:$(BOOTEND) -f $< -a write -v

ifneq ($(OS),Windows_NT) # Linux
build: all
Expand Down
8 changes: 1 addition & 7 deletions VortexEngine/VortexEngine.cppproj
Original file line number Diff line number Diff line change
Expand Up @@ -266,9 +266,6 @@
<Compile Include="src\Patterns\Multi\LighthousePattern.cpp">
<SubType>compile</SubType>
</Compile>
<Compile Include="src\Patterns\Multi\MateriaPattern.cpp">
<SubType>compile</SubType>
</Compile>
<Compile Include="src\Patterns\Multi\MeteorPattern.cpp">
<SubType>compile</SubType>
</Compile>
Expand Down Expand Up @@ -455,9 +452,6 @@
<Compile Include="src\Patterns\Multi\LighthousePattern.h">
<SubType>compile</SubType>
</Compile>
<Compile Include="src\Patterns\Multi\MateriaPattern.h">
<SubType>compile</SubType>
</Compile>
<Compile Include="src\Patterns\Multi\MeteorPattern.h">
<SubType>compile</SubType>
</Compile>
Expand Down Expand Up @@ -606,4 +600,4 @@
<Folder Include="src\Wireless\" />
</ItemGroup>
<Import Project="$(AVRSTUDIO_EXE_PATH)\\Vs\\Compiler.targets" />
</Project>
</Project>
18 changes: 10 additions & 8 deletions VortexEngine/VortexLib/VortexLib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,15 +166,16 @@ EMSCRIPTEN_BINDINGS(Vortex) {
.function("sanity", &ByteStream::sanity)
.function("checkCRC", &ByteStream::checkCRC)
.function("isCRCDirty", &ByteStream::isCRCDirty)
.function("serialize", select_overload<bool(uint8_t)>(&ByteStream::serialize))
.function("serialize16", select_overload<bool(uint16_t)>(&ByteStream::serialize))
.function("serialize32", select_overload<bool(uint32_t)>(&ByteStream::serialize))
.function("serialize8", &ByteStream::serialize8)
.function("serialize16", &ByteStream::serialize16)
.function("serialize32", &ByteStream::serialize32)
.function("resetUnserializer", &ByteStream::resetUnserializer)
.function("moveUnserializer", &ByteStream::moveUnserializer)
.function("unserializerAtEnd", &ByteStream::unserializerAtEnd)
.function("unserialize8", &ByteStream::unserialize8)
.function("unserialize16", &ByteStream::unserialize16)
.function("unserialize32", &ByteStream::unserialize32)
// TODO: provide better apis here
//.function("unserialize8", &ByteStream::unserialize8)
//.function("unserialize16", &ByteStream::unserialize16)
//.function("unserialize32", &ByteStream::unserialize32)
.function("peek8", &ByteStream::peek8)
.function("peek16", &ByteStream::peek16)
.function("peek32", &ByteStream::peek32)
Expand Down Expand Up @@ -658,8 +659,9 @@ bool Vortex::init(VortexCallbacks *callbacks)

// init the engine
VortexEngine::init();
// clear the modes
//Modes::clearModes();
// load the modes
// TODO: don't load modes here? separate api?
Modes::load();
// save and set undo buffer
doSave();

Expand Down
20 changes: 7 additions & 13 deletions VortexEngine/src/Buttons/Buttons.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,32 +15,26 @@
// This will simply point at Buttons::m_button.
Button *g_pButton = nullptr;

// static members
Button Buttons::m_buttons[NUM_BUTTONS];

bool Buttons::init()
{
// initialize the button on pin 1
if (!m_buttons[0].init(1)) {
g_pButton = new Button();
if (!g_pButton) {
return false;
}
g_pButton = &m_buttons[0];
return true;
// init the button on pin 1
return g_pButton->init(1);
}

void Buttons::cleanup()
{
delete g_pButton;
}

void Buttons::update()
{
// would iterate all buttons and check them here
// but there's only one button so
for (uint8_t i = 0; i < NUM_BUTTONS; ++i) {
m_buttons[i].update();
}
g_pButton->update();
#ifdef VORTEX_LIB
// read input from the vortex lib interface, for example Vortex::shortClick()
Vortex::handleInputQueue(m_buttons, NUM_BUTTONS);
Vortex::handleInputQueue(g_pButton, NUM_BUTTONS);
#endif
}
2 changes: 0 additions & 2 deletions VortexEngine/src/Buttons/Buttons.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ class Buttons
static uint8_t numButtons() { return NUM_BUTTONS; }

private:
// feel free to add more I guess
static Button m_buttons[NUM_BUTTONS];
};

// best way I think
Expand Down
30 changes: 22 additions & 8 deletions VortexEngine/src/Colors/ColorTypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,18 +198,32 @@ RGBColor RGBColor::adjustBrightness(uint8_t fadeBy)
return *this;
}

void RGBColor::serialize(ByteStream &buffer) const
bool RGBColor::serialize(ByteStream &buffer) const
{
buffer.serialize(red);
buffer.serialize(green);
buffer.serialize(blue);
if (!buffer.serialize8(red)) {
return false;
}
if (!buffer.serialize8(green)) {
return false;
}
if (!buffer.serialize8(blue)) {
return false;
}
return true;
}

void RGBColor::unserialize(ByteStream &buffer)
bool RGBColor::unserialize(ByteStream &buffer)
{
buffer.unserialize(&red);
buffer.unserialize(&green);
buffer.unserialize(&blue);
if (!buffer.unserialize8(&red)) {
return false;
}
if (!buffer.unserialize8(&green)) {
return false;
}
if (!buffer.unserialize8(&blue)) {
return false;
}
return true;
}

// ========================================================
Expand Down
4 changes: 2 additions & 2 deletions VortexEngine/src/Colors/ColorTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ class RGBColor
void clear();

RGBColor adjustBrightness(uint8_t fadeBy);
void serialize(ByteStream &buffer) const;
void unserialize(ByteStream &buffer);
bool serialize(ByteStream &buffer) const;
bool unserialize(ByteStream &buffer);

uint32_t raw() const { return ((uint32_t)red << 16) | ((uint32_t)green << 8) | (uint32_t)blue; }

Expand Down
Loading
Loading