pengutronix / genimage

tool to generate multiple filesystem and flash images from a tree
GNU General Public License v2.0
308 stars 110 forks source link

Multiple rauc images in a config file fails after generating first #85

Closed thirtythreeforty closed 4 years ago

thirtythreeforty commented 4 years ago

If I have a config file that specifies multiple rauc images (say, update.raucb and update-developer.raucb), then generating all but the first fails.

This is because rauc_generate improperly uses insert_data to write data to a file:

https://github.com/pengutronix/genimage/blob/a58a53b7fd864dbf5835b25e232c76bc0752deef/image-rauc.c#L41-L44

This manifest file is presumed not to exist, but if previous RAUC runs have been done, it does exist and the file is not replaced/truncated, but simply pasted into, leaving garbage at the end from the previous RAUC run. (In other words, insert_data is not the appropriate function to use here.)

This creates bizarre errors when RAUC runs again and encounters the garbage data, like:

Failed to update manifest: Key file contains line ?      dff3f29ff09360b59513? which is not a key-value pair, group, or comment

As a workaround, I'm deleting the file before continuing:

diff --git a/image-rauc.c b/image-rauc.c
index c4195a3..8ee5550 100644
--- a/image-rauc.c
+++ b/image-rauc.c
@@ -19,6 +19,7 @@
 #include <string.h>
 #include <stdlib.h>
 #include <errno.h>
+#include <unistd.h>

 #include "genimage.h"

@@ -39,6 +40,7 @@ static int rauc_generate(struct image *image)
    image_debug(image, "manifest = '%s'\n", manifest);

    xasprintf(&manifest_file, "%s/manifest.raucm", mountpath(image));
+   ret = unlink(manifest_file);
    ret = insert_data(image, manifest, manifest_file, strlen(manifest), 0);
    if (ret)
        return ret;

Feel free to steal this patch for a quick fix, or if you want to make more sweeping changes, you won't hurt my feelings.

thirtythreeforty commented 4 years ago

Actually, more sweeping changes are needed, perhaps a temp directory per rauc run. All the files from the various RAUC bundles I'm generating are piling up in the subsequent bundles. (rootfs.squashfs from bundle 1 is showing up next to rootfs.ext4 from bundle 2 in bundle 2).

thirtythreeforty commented 4 years ago

Thanks very much!