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

Add package tiny-vcdiff #17797

Merged
merged 4 commits into from
Aug 26, 2022
Merged

Conversation

jue89
Copy link
Contributor

@jue89 jue89 commented Mar 11, 2022

Contribution description

This is a WIP PR that brings tiny-vcdiff into RIOT.
I mentioned this library during my talk on the last RIOT Summit

Currently this PR supports mtd as backend. But a vfs will be added, too. I guess those are the obvious interfaces for such a package.

Testing procedure

I will add a test later, that will make use of all implemented backends.

Issues/PRs references

@jue89 jue89 added Type: new feature The issue requests / The PR implemements a new feature for RIOT Area: pkg Area: External package ports labels Mar 11, 2022
@jue89 jue89 requested a review from fjmolinas March 11, 2022 12:13
@github-actions github-actions bot added Area: build system Area: Build system Area: doc Area: Documentation Area: Kconfig Area: Kconfig integration labels Mar 11, 2022
pkg/tinyvcdiff/doc.txt Outdated Show resolved Hide resolved
@aabadie
Copy link
Contributor

aabadie commented Mar 13, 2022

I'm realizing that there's no test application for this new package. So it won't be built by the CI. I would be nice to add a simple one (you can use make generate-test)

@jue89
Copy link
Contributor Author

jue89 commented Mar 13, 2022

I'm realizing that there's no test application for this new package. So it won't be built by the CI. I would be nice to add a simple one (you can use make generate-test)

Yep, I'm currently working on that. The reason why this is a draft PR.

@jue89
Copy link
Contributor Author

jue89 commented Mar 25, 2022

Writing the test revealed the bugs described in #17865 and #17866. Waiting for them to be on master.

@benpicco
Copy link
Contributor

You can probably squash when you rebase

@jue89 jue89 force-pushed the feature/pkg-tiny-vcdiff branch from 3ca9440 to b7997a9 Compare March 26, 2022 18:05
@github-actions github-actions bot added the Area: tests Area: tests and testing framework label Mar 26, 2022
@jue89 jue89 force-pushed the feature/pkg-tiny-vcdiff branch from b7997a9 to 9ba4d2f Compare March 26, 2022 18:36
@jue89 jue89 marked this pull request as ready for review March 26, 2022 18:37
@jue89 jue89 added the CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR label Mar 26, 2022
@jue89
Copy link
Contributor Author

jue89 commented Mar 26, 2022

I think everything should be in place, now. I'm ready to be roasted reviewed 🙈

@jue89 jue89 force-pushed the feature/pkg-tiny-vcdiff branch from 9ba4d2f to 28e9e12 Compare March 26, 2022 18:44
pkg/tinyvcdiff/contrib/tinyvcdiff_mtd/mtd.c Show resolved Hide resolved
pkg/tinyvcdiff/contrib/tinyvcdiff_mtd/mtd.c Outdated Show resolved Hide resolved
pkg/tinyvcdiff/contrib/tinyvcdiff_vfs/vfs.c Outdated Show resolved Hide resolved
pkg/tinyvcdiff/contrib/tinyvcdiff_vfs/vfs.c Outdated Show resolved Hide resolved
pkg/tinyvcdiff/contrib/tinyvcdiff_vfs/vfs.c Outdated Show resolved Hide resolved
tests/pkg_tinyvcdiff/main.c Outdated Show resolved Hide resolved
tests/pkg_tinyvcdiff/main.c Outdated Show resolved Hide resolved
tests/pkg_tinyvcdiff/main.c Outdated Show resolved Hide resolved
tests/pkg_tinyvcdiff/main.c Outdated Show resolved Hide resolved
tests/pkg_tinyvcdiff/main.c Outdated Show resolved Hide resolved
Copy link
Contributor

@benpicco benpicco left a comment

Choose a reason for hiding this comment

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

Nice, works like a charm - some more nits:

pkg/tinyvcdiff/contrib/tinyvcdiff_mtd/mtd.c Outdated Show resolved Hide resolved
pkg/tinyvcdiff/contrib/tinyvcdiff_mtd/mtd.c Outdated Show resolved Hide resolved
pkg/tinyvcdiff/contrib/tinyvcdiff_vfs/vfs.c Outdated Show resolved Hide resolved
tests/pkg_tinyvcdiff/main.c Outdated Show resolved Hide resolved
tests/pkg_tinyvcdiff/main.c Outdated Show resolved Hide resolved
tests/pkg_tinyvcdiff/main.c Show resolved Hide resolved
tests/pkg_tinyvcdiff/fakemtd.h Outdated Show resolved Hide resolved
Copy link
Contributor

@fjmolinas fjmolinas left a comment

Choose a reason for hiding this comment

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

Seems CI is mostly happy, but this will need some blacklisting

tests/pkg_tinyvcdiff/fakemtd.h Outdated Show resolved Hide resolved
@jue89
Copy link
Contributor Author

jue89 commented Mar 28, 2022

Thank you for your reviews, @benpicco @fjmolinas!

Is it okay if I squash all fixups before addressing your suggestions?

@jue89
Copy link
Contributor Author

jue89 commented Mar 30, 2022

Rebased on latest master.

* vcdiff_vfs_t target = VCDIFF_VFS_INIT(fd_target);
* vcdiff_set_target_driver(&vcdiff, &vcdiff_vfs_driver, &target);
*
* rc = vcdiff_apply_delta(&vcdiff, data, data_len);
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a requirement on how this needs to be fragmented?

Copy link
Contributor Author

@jue89 jue89 Mar 30, 2022

Choose a reason for hiding this comment

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

Nope, It should work byte-wise. Like shown here.

If it doesn't, it's a bug ;-)

@jue89
Copy link
Contributor Author

jue89 commented Mar 30, 2022

Has anyone an idea how to handle this CI error?
cc1: error: unrecognized command line option '-Wno-implicit-fallthrough' [-Werror]

@benpicco
Copy link
Contributor

Can you make the fall-throughs explicit with /* fall-through */?

@jue89
Copy link
Contributor Author

jue89 commented Mar 30, 2022

Well, I could. But that produces really noisy code :-/

/* mtd_read_page will take care of calculation the right page
* it's safe to call mtd_read_page_raw: the erase driver already
* prepared the sector for writing */
int rc = mtd_write_page_raw(mtd->dev, src, 0, offset, len);
Copy link
Contributor

Choose a reason for hiding this comment

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

Are you sure this is right? The input offset is offset in bytes, while the offset parameter to mtd_write_page_raw is the offset in the page being written to, shouldn't it be something like:

Suggested change
int rc = mtd_write_page_raw(mtd->dev, src, 0, offset, len);
uint32_t page = offset / mtd->dev->page_size;
uint32_t page_offset = (offset % mtd->dev->page_size);
int rc = mtd_write_page_raw(mtd->dev, src, page, page_offset, len);

(untested)

Copy link
Contributor

Choose a reason for hiding this comment

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

Same question goes for the read function actually.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It should work to start at page 0 and let the MTD implemenation figure out the right page.

Copy link
Contributor

@fjmolinas fjmolinas Mar 30, 2022

Choose a reason for hiding this comment

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

But that is only if there is write_page, not the case for mtd_flashpage for example.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah sorry, my bad, I misunderstood the API I think.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well, but another problem could occur: un-aligned writes (i.e. addr % FLASHPAGE_WRITE_BLOCK_ALIGNMENT and size % FLASHPAGE_WRITE_BLOCK_SIZE are possible troublemaker ...). Or am I wrong?

Copy link
Contributor

Choose a reason for hiding this comment

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

yea but you don't get those through MTD - #17683 tries to fix that

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added write alignment for the MTD backend: b705803

@jue89
Copy link
Contributor Author

jue89 commented Mar 31, 2022

I think it would be nice to have working MTD ;-) Thus, I'm waiting for #17683.

@jue89 jue89 added the State: waiting for other PR State: The PR requires another PR to be merged first label Mar 31, 2022
@jue89
Copy link
Contributor Author

jue89 commented Apr 5, 2022

I added write alignment for this package. Once #17683 is merged, I'll add a check if the configured write alignment and MTD write alignment are compatible.

@jue89 jue89 removed the State: waiting for other PR State: The PR requires another PR to be merged first label Apr 5, 2022
@jue89
Copy link
Contributor Author

jue89 commented Apr 5, 2022

Can you make the fall-throughs explicit with /* fall-through */?

I sneaked that in with some pre-processor magic. The package can now be compiled without -Wno-implicit-fallthrough.

@jue89
Copy link
Contributor Author

jue89 commented Apr 5, 2022

Finally a happy Murdock :)

@jue89 jue89 force-pushed the feature/pkg-tiny-vcdiff branch from 1a612fb to 0f1a1dc Compare May 17, 2022 11:42
@jue89 jue89 requested a review from MrKevinWeiss as a code owner May 17, 2022 11:42
@jue89
Copy link
Contributor Author

jue89 commented May 17, 2022

Rebased on latest master. Still looking fine.

@fjmolinas You faced problems with alignment on MTD flashpage, right? Could you test this PR again? I've introduced aligned writes for MTD backends.

Copy link
Contributor

@benpicco benpicco left a comment

Choose a reason for hiding this comment

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

With a rebase you can now get rid of CONFIG_TINYVCDIFF_MTD_WRITE_SIZE

size_t alignment_offset;
size_t copy_len;

alignment_offset = mtd->offset % CONFIG_TINYVCDIFF_MTD_WRITE_SIZE;
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
alignment_offset = mtd->offset % CONFIG_TINYVCDIFF_MTD_WRITE_SIZE;
alignment_offset = mtd->offset % mtd->write_size;

should now be possible.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

vcdiff_mtd_t requires write_size to be known at compile time to adjust buffer sizes. But at least an assert() would be nice to have.

Copy link
Contributor

Choose a reason for hiding this comment

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

Could we use mtd->work_area instead?

Copy link
Contributor Author

@jue89 jue89 Aug 30, 2022

Choose a reason for hiding this comment

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

This would add the dependency mtd_write_page. Currently, I'm not using any of the write page features. Adding this module would add unnecessary code just to have the (mtd_write_page-internal) buffer at hand. It feels a little bit hacky to me.

I'd say having assert()s in place that make sure the buffer is aligned and large enough would be a good thing to have in place.

The default of 4 bytes seems to be a size that fits all mtd devices available in RIOT (IIRC) and isn't wasteful in my opinion.

Copy link
Contributor

Choose a reason for hiding this comment

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

For mtd_flashpage it can be larger than 4, same for SD cards (but those are usually used with a filesystem)

@benpicco
Copy link
Contributor

Well, I'm happy to merge this as is and the do a follow-up PR.

@benpicco benpicco added CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR and removed CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR labels Aug 26, 2022
@benpicco benpicco merged commit cb27a26 into RIOT-OS:master Aug 26, 2022
@MrKevinWeiss
Copy link
Contributor

It seems like native tests are failing now hitting an assert

@jue89 jue89 deleted the feature/pkg-tiny-vcdiff branch August 30, 2022 10:25
@jue89
Copy link
Contributor Author

jue89 commented Aug 30, 2022

Oh thank you for your review!

@maribu maribu added this to the Release 2022.10 milestone Oct 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: build system Area: Build system Area: doc Area: Documentation Area: Kconfig Area: Kconfig integration Area: pkg Area: External package ports Area: tests Area: tests and testing framework CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Type: new feature The issue requests / The PR implemements a new feature for RIOT
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants