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

Pbtools update #24

Merged
merged 14 commits into from Aug 30, 2023
Merged

Pbtools update #24

merged 14 commits into from Aug 30, 2023

Conversation

jonasblixt
Copy link
Owner

No description provided.

@codecov
Copy link

codecov bot commented Aug 28, 2023

Codecov Report

Merging #24 (b92f1ad) into master (18abc4d) will increase coverage by 0.09%.
Report is 2 commits behind head on master.
The diff coverage is 88.88%.

@@            Coverage Diff             @@
##           master      #24      +/-   ##
==========================================
+ Coverage   68.06%   68.15%   +0.09%     
==========================================
  Files          54       54              
  Lines        2787     2795       +8     
==========================================
+ Hits         1897     1905       +8     
  Misses        890      890              
Files Changed Coverage Δ
src/lib/der_helpers.c 0.00% <0.00%> (ø)
src/boot/ab_state.c 69.46% <100.00%> (+1.53%) ⬆️

@jonasblixt jonasblixt force-pushed the pbtools-update branch 4 times, most recently from 3e4cfd1 to 33b1595 Compare August 28, 2023 12:43
Copy link
Contributor

@thebolt thebolt left a comment

Choose a reason for hiding this comment

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

Functionality wise seems ok, but a few cleanups can be done before merging.

@@ -245,9 +243,11 @@ bool pbstate_is_system_active(pbstate_system_t system)
return config.enable == PB_STATE_A_ENABLED;
case PBSTATE_SYSTEM_B:
return config.enable == PB_STATE_B_ENABLED;
case PBSTATE_SYSTEM_NONE:
Copy link
Contributor

Choose a reason for hiding this comment

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

This is adding new functionality as part of another unrelated commit (the cmake migraiton), consider splitting in two.

Copy link
Owner Author

Choose a reason for hiding this comment

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

fixed

@@ -134,10 +134,15 @@ int main(int argc, char * const argv[])
}
}

#if !defined(PRIMARY_PART) && !defined(BACKUP_PART)
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this should be !defined || !defined (that is, only use the default path below if both are defined). Possibly expressed as !(defined && defined).

Copy link
Owner Author

Choose a reason for hiding this comment

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

fixed


int pbstate_read_board_reg(unsigned int index, uint32_t *value)
{
if (index > (NO_OF_BOARD_REGS - 1))
Copy link
Contributor

Choose a reason for hiding this comment

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

To allow for (easier) later extension with more board_regs, I would at least consider numbering them with index == 0 as the last register, and then count backwards.

Copy link
Owner Author

Choose a reason for hiding this comment

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

fixed

@@ -116,6 +136,18 @@ int main(int argc, char * const argv[])
case 'i':
flag_show = true;
break;
case 'w':
flag_write_board_reg = true;
board_reg_index = strtol(optarg, NULL, 0);
Copy link
Contributor

Choose a reason for hiding this comment

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

No error handling on bad parsing?

Copy link
Owner Author

Choose a reason for hiding this comment

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

fixed


if (read_config(fd, &config_backup) != 0) {
LOG("Could not read backup config data\n");
if (fd != -1) {
Copy link
Contributor

Choose a reason for hiding this comment

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

As a general style I prefer (and most code seems to be) in a style where the success case is as little indented as possible, that is you try as much as possible to have

if (error) {
  .. return or break
}

<success case>

If nothing else just to keep consistency, consider changing.

Copy link
Owner Author

Choose a reason for hiding this comment

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

Agreed, but in this case the function should not return on error but try to load/read the backup. I'll keep it as is.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, that is my misunderstanding of the logic in the method.

memcpy(&config, &config_backup, sizeof(config));
} else if (!primary_ok) {
LOG("Primary configuration corrupt\n");
LOG("Backup configuration corrupt\n");
LOG("Both primary and backup state corrupt\n");
err = -1;
Copy link
Contributor

Choose a reason for hiding this comment

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

Earlier in the method it returns an -errno, however here it is -1 (which maps ot EPERM, which is probably not what should be returned). Within a single method, either just have 0/-1, or 0/-errno, but don't mix

Copy link
Owner Author

Choose a reason for hiding this comment

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

fixed

} __attribute__((packed));

// For 'struct pb_boot_state'
#include "../tools/pbstate/src/pbstate.h"
Copy link
Contributor

Choose a reason for hiding this comment

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

Seems a bit wrong when "core" functionality includes parts from tools.. other way around would feel less incorrect

Copy link
Owner Author

Choose a reason for hiding this comment

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

fixed

@@ -34,8 +34,7 @@ jobs:
- name: Build pbstate
run: |
pushd tools/pbstate
autoreconf -fi
./configure
cmake .
Copy link
Contributor

Choose a reason for hiding this comment

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

CMake generally don't like at all to build in same directory (which is probably why CI fails, I haven't checked).

Fix -Wextra/-pedantic warnings
This adds cmake option for specifying a default for primary and backup
partition through the parameters:

 - PB_STATE_PRIMARY_PART
 - PB_STATE_BACKUP_PART

This is only relevant for the CLI and does not change any behaviour with
the library portion.
This adds the additional "board registers". The idéa is to have a few
board specific registers to control custom board specific logic.

These registers can be accessed in the board bootloader code and through
the pbstate library and CLI.

This commit also moves the struct to a public header shared with the
bootloader code.
Use errno whenever possible.
Apparently, this is now required.
The same crc routine is used in the main code, let's use that instead.
Copy link
Contributor

@thebolt thebolt left a comment

Choose a reason for hiding this comment

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

Looks good to me now

@jonasblixt jonasblixt merged commit 0fbb011 into master Aug 30, 2023
5 checks passed
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.

None yet

2 participants