Skip to content

Dproano/logging - #2

Open
jibbychohan wants to merge 44 commits into
mainfrom
dproano/logging
Open

jibbychohan wants to merge 44 commits into
mainfrom
dproano/logging

Conversation

@jibbychohan

Copy link
Copy Markdown

No description provided.

Comment thread firmware/lib/logging/logging.cpp Resolved
Comment thread firmware/src/ec_main.cpp Resolved
@jacobh460
jacobh460 self-requested a review September 25, 2026 01:09
Comment thread firmware/lib/logging/flash.cpp Resolved

flash_error_t write_to_cache(uint32_t col_addr, uint8_t *data, size_t len);

flash_error_t program(uint32_t addr);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Naming this parameter "addr" is misleading because I'm pretty sure it's really a row address. Need to confirm during testing because the datasheet isn't very specific.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agreed, fixed

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same with the other functions; all the function that deal with a specific page deal in row addr

Comment thread firmware/lib/logging/flash.cpp Resolved
Comment thread firmware/lib/logging/flash.cpp Resolved
Comment thread firmware/lib/logging/flash.cpp Resolved
Comment thread firmware/lib/logging/flash.cpp Resolved

@jacobh460 jacobh460 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's looking pretty good just the biggest thing is the clock prescaler looks wrong now (I agree that you probably had it correct originally). And some things in the logging.cpp. I'll add more comments later if I think of something else.

Comment thread firmware/lib/logging/bad_page_table.cpp Resolved
Comment thread firmware/lib/logging/bad_page_table.cpp Resolved
Comment thread firmware/lib/logging/bad_page_table.cpp Resolved
Comment thread firmware/lib/logging/flash.cpp Resolved
Comment thread firmware/lib/logging/bad_page_table.cpp Resolved
Comment thread firmware/lib/logging/flash.h Resolved
Comment thread firmware/lib/logging/logging.cpp Resolved
Comment thread firmware/lib/logging/logging.cpp Resolved
Comment thread firmware/lib/logging/logging.cpp Resolved
Comment thread firmware/lib/logging/logging.cpp Resolved
@jacobh460

Copy link
Copy Markdown
Contributor

Can you also document in one of the files or in a markdown how you are structuring the bad page table in memory and how the logging logic works (ie it looks like you are making sure a structure doesn't cross page boundary)

@jacobh460 jacobh460 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's looking pretty good, just some documentation and a few small things and I think it's good to test and then merge. Also we should make sure DFU won't overwrite the BPT in flash. And if you could make sure to comment the functions in bad_page_table.h/.cpp to make it clear what they are doing to other people.

constexpr uint32_t BPT_MAX_ENTRIES =
(FLASH_SECTOR_SIZE - STM32_FLASH_WORD_SIZE - NUM_BYTES_TRACKING_BLOCKS) / STM32_FLASH_WORD_SIZE;

const uint32_t *bpt_magic = &_bpt_start;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These give the impression that the data pointed to is constant; what I meant is can you make it clear that these point to fixed addresses.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The syntax for this is uint32_t* const bpt_magic = ... which makes it clear that the address pointed to doesn't change, but the data at that address can be modified/

return !(bpt_table[get_bpt_bad_byte(block_num)] & get_bpt_bad_bit(block_num));
}

bool get_runtime_bad_page(uint32_t block_num, uint32_t *out_page) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function looks like it's checking if a block was marked bad at runtime and returns the last good page that was written to? Can you just comment that this is what it does and what the return value means thx

return *out_page != NAND_NUM_PAGES;
}

bool add_entry(uint32_t page_address) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same with this - can you make a note that it stores which specific page went bad.

return *reinterpret_cast<uint32_t *>(get_entry_addr(index));
}

uint32_t get_bpt_bad_byte(uint32_t block_num) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider renaming to get_bpt_bad_index or get_bpt_bad_byte_index

return block_num / 8;
}

uint8_t get_bpt_bad_bit(uint32_t block_num) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider renaming to get_bpt_bad_bit_mask

Comment thread firmware/lib/logging/logging.cpp Resolved
Comment thread firmware/lib/logging/logging.cpp Resolved
} >FLASH

/* Reserved for the NAND flash Bad Page Table */
.bpt_table (NOLOAD) :

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you confirm DFU won't overwrite this section

Comment thread firmware/src/ec_main.cpp
Comment on lines +29 to +41
static bool in_flight = false;

static void dump_log_cmd() {
if (!in_flight && Logging::dump()) {
CommsSerial.println("Log dump finished");
}
}

static void erase_log_cmd() {
if (!in_flight) {
Logging::erase();
}
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you move these (the dump_log_cmd and erase_log_cmd) to logging.cpp; and see my other comment about the log_arm logic, it's similar to what you are going for here. You can call CommandRouter::add() from Logging::begin() to keep things organized. We usually try to call CommandRouter::add() from a lib's dedicated begin() function to keep the ec_main.cpp organized. The only exception to this is when we have a lib that is shared across multiple different devices (ie also used by the prog mcu), in which case we may put some logic in main.

Comment thread firmware/platformio.ini
Comment on lines +59 to +60
-D USBCON
-D USBD_USE_CDC

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these two are redundant since they are already specified on lines 34-35

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants