Skip to content

Commit

Permalink
Merge pull request #48 from jluebbe/raw-nand
Browse files Browse the repository at this point in the history
raw NAND support
  • Loading branch information
Enrico Jorns committed May 24, 2016
2 parents 22c9b59 + a55c40f commit 15b74a2
Show file tree
Hide file tree
Showing 2 changed files with 117 additions and 8 deletions.
24 changes: 16 additions & 8 deletions src/install.c
Original file line number Diff line number Diff line change
Expand Up @@ -682,6 +682,12 @@ static gboolean launch_and_wait_default_handler(RaucInstallArgs *args, gchar* bu
}

r_context_end_step("copy_image", TRUE);

if (g_strcmp0(dest_slot->type, "nand") == 0) {
g_message("Skipping slot status update for nand slot %s ", dest_slot->device);
goto image_out;
}

g_debug("mounting slot %s", dest_slot->device);
res = r_mount_slot(dest_slot, &ierror);
if (!res) {
Expand Down Expand Up @@ -714,14 +720,16 @@ static gboolean launch_and_wait_default_handler(RaucInstallArgs *args, gchar* bu
g_clear_pointer(&destdevicefile, g_object_unref);
g_clear_pointer(&slotstatuspath, g_free);

g_debug("unmounting slot %s", dest_slot->device);
res = r_umount_slot(dest_slot, &ierror);
if (!res) {
g_propagate_prefixed_error(
error,
ierror,
"Unmounting failed: ");
goto out;
if (dest_slot->mount_internal) {
g_debug("unmounting slot %s", dest_slot->device);
res = r_umount_slot(dest_slot, &ierror);
if (!res) {
g_propagate_prefixed_error(
error,
ierror,
"Unmounting failed: ");
goto out;
}
}

install_args_update(args, g_strdup_printf("Updating slot %s done", dest_slot->name));
Expand Down
101 changes: 101 additions & 0 deletions src/update_handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,82 @@ static gboolean ext4_format_slot(RaucSlot *dest_slot, GError **error)
return res;
}

static gboolean nand_format_slot(const gchar *device, GError **error)
{
GSubprocess *sproc = NULL;
GError *ierror = NULL;
gboolean res = FALSE;
GPtrArray *args = g_ptr_array_new_full(5, g_free);

g_ptr_array_add(args, g_strdup("flash_erase"));
g_ptr_array_add(args, g_strdup("--quiet"));
g_ptr_array_add(args, g_strdup(device));
g_ptr_array_add(args, g_strdup("0"));
g_ptr_array_add(args, g_strdup("0"));
g_ptr_array_add(args, NULL);

sproc = g_subprocess_newv((const gchar * const *)args->pdata,
G_SUBPROCESS_FLAGS_NONE, &ierror);
if (sproc == NULL) {
g_propagate_prefixed_error(
error,
ierror,
"failed to start flash_erase: ");
goto out;
}

res = g_subprocess_wait_check(sproc, NULL, &ierror);
if (!res) {
g_propagate_prefixed_error(
error,
ierror,
"failed to run flash_erase: ");
goto out;
}

out:
g_ptr_array_unref(args);
return res;
}

static gboolean nand_write_slot(const gchar *image, const gchar *device, GError **error)
{
GSubprocess *sproc = NULL;
GError *ierror = NULL;
gboolean res = FALSE;
GPtrArray *args = g_ptr_array_new_full(5, g_free);

g_ptr_array_add(args, g_strdup("nandwrite"));
g_ptr_array_add(args, g_strdup("--pad"));
g_ptr_array_add(args, g_strdup("--quiet"));
g_ptr_array_add(args, g_strdup(device));
g_ptr_array_add(args, g_strdup(image));
g_ptr_array_add(args, NULL);

sproc = g_subprocess_newv((const gchar * const *)args->pdata,
G_SUBPROCESS_FLAGS_NONE, &ierror);
if (sproc == NULL) {
g_propagate_prefixed_error(
error,
ierror,
"failed to start nandwrite: ");
goto out;
}

res = g_subprocess_wait_check(sproc, NULL, &ierror);
if (!res) {
g_propagate_prefixed_error(
error,
ierror,
"failed to run nandwrite: ");
goto out;
}

out:
g_ptr_array_unref(args);
return res;
}

static gboolean untar_image(RaucImage *image, gchar *dest, GError **error)
{
GSubprocess *sproc = NULL;
Expand Down Expand Up @@ -332,6 +408,30 @@ static gboolean tar_to_ext4_handler(RaucImage *image, RaucSlot *dest_slot, GErro
return res;
}

static gboolean img_to_nand_handler(RaucImage *image, RaucSlot *dest_slot, GError **error) {
GError *ierror = NULL;
gboolean res = FALSE;

/* erase */
g_message("erasing slot device %s", dest_slot->device);
res = nand_format_slot(dest_slot->device, &ierror);
if (!res) {
g_propagate_error(error, ierror);
goto out;
}

/* write */
g_message("writing slot device %s", dest_slot->device);
res = nand_write_slot(image->filename, dest_slot->device, &ierror);
if (!res) {
g_propagate_error(error, ierror);
goto out;
}

out:
return res;
}

static gboolean img_to_raw_handler(RaucImage *image, RaucSlot *dest_slot, GError **error) {
GOutputStream *outstream = NULL;
GError *ierror = NULL;
Expand Down Expand Up @@ -371,6 +471,7 @@ RaucUpdatePair updatepairs[] = {
{"*.tar.*", "ext4", tar_to_ext4_handler},
{"*.tar.*", "ubifs", tar_to_ubifs_handler},
{"*.ubifs", "ubifs", ubifs_to_ubifs_handler},
{"*.img", "nand", img_to_nand_handler},
{"*.img", "*", img_to_raw_handler}, /* fallback */
{0}
};
Expand Down

0 comments on commit 15b74a2

Please sign in to comment.