mirror of
https://git.proxmox.com/git/fwupd
synced 2025-06-03 13:41:12 +00:00

A UF2 device exposes a VFAT block device (sometimes called a Mass Storage Device) which has a virtual file called `INFO_UF2.TXT` where metadata can be read. It may also have a the current firmware exported as a file called `CURRENT.UF2` which is in a 512 byte-block UF2 format. Writing any file to the MSD will cause the firmware to be written. Sometimes the device will restart and the volume will be unmounted and then mounted again. In some cases the volume may not “come back” until the user manually puts the device back in programming mode. Match the block devices using the VID*PID, UUID or label, and then create a UF2 device which can be used to flash firmware. Note: We only read metadata from allow-listed IDs to avoid causing regressions on non-UF2 volumes. To get the UUID and label you can use commands like: udisksctl info -b /dev/sda1
60 lines
1.7 KiB
C
60 lines
1.7 KiB
C
/*
|
|
* Copyright (C) 2021 Richard Hughes <richard@hughsie.com>
|
|
*
|
|
* SPDX-License-Identifier: LGPL-2.1+
|
|
*/
|
|
|
|
#include "config.h"
|
|
|
|
#include <fwupdplugin.h>
|
|
|
|
#include "fu-uf2-firmware.h"
|
|
|
|
static void
|
|
fu_uf2_firmware_xml_func(void)
|
|
{
|
|
gboolean ret;
|
|
g_autofree gchar *filename = NULL;
|
|
g_autofree gchar *csum1 = NULL;
|
|
g_autofree gchar *csum2 = NULL;
|
|
g_autofree gchar *xml_out = NULL;
|
|
g_autofree gchar *xml_src = NULL;
|
|
g_autoptr(FuFirmware) firmware1 = fu_uf2_firmware_new();
|
|
g_autoptr(FuFirmware) firmware2 = fu_uf2_firmware_new();
|
|
g_autoptr(GError) error = NULL;
|
|
|
|
/* build and write */
|
|
filename = g_test_build_filename(G_TEST_DIST, "tests", "uf2.builder.xml", NULL);
|
|
ret = g_file_get_contents(filename, &xml_src, NULL, &error);
|
|
g_assert_no_error(error);
|
|
g_assert_true(ret);
|
|
ret = fu_firmware_build_from_xml(firmware1, xml_src, &error);
|
|
g_assert_no_error(error);
|
|
g_assert_true(ret);
|
|
csum1 = fu_firmware_get_checksum(firmware1, G_CHECKSUM_SHA1, &error);
|
|
g_assert_no_error(error);
|
|
g_assert_cmpstr(csum1, ==, "2aae6c35c94fcfb415dbe95f408b9ce91ee846ed");
|
|
|
|
/* ensure we can round-trip */
|
|
xml_out = fu_firmware_export_to_xml(firmware1, FU_FIRMWARE_EXPORT_FLAG_NONE, &error);
|
|
g_assert_no_error(error);
|
|
ret = fu_firmware_build_from_xml(firmware2, xml_out, &error);
|
|
g_assert_no_error(error);
|
|
g_assert_true(ret);
|
|
csum2 = fu_firmware_get_checksum(firmware2, G_CHECKSUM_SHA1, &error);
|
|
g_assert_cmpstr(csum1, ==, csum2);
|
|
}
|
|
|
|
int
|
|
main(int argc, char **argv)
|
|
{
|
|
g_test_init(&argc, &argv, NULL);
|
|
|
|
/* only critical and error are fatal */
|
|
g_log_set_fatal_mask(NULL, G_LOG_LEVEL_ERROR | G_LOG_LEVEL_CRITICAL);
|
|
|
|
/* tests go here */
|
|
g_test_add_func("/uf2/firmware{xml}", fu_uf2_firmware_xml_func);
|
|
return g_test_run();
|
|
}
|