Bug 262896 - /usr/sbin/fstyp is not able to detect FAT filesystem on Raspberry Pi Pico
Summary: /usr/sbin/fstyp is not able to detect FAT filesystem on Raspberry Pi Pico
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: 13.0-RELEASE
Hardware: Any Any
: --- Affects Some People
Assignee: Ed Maste
URL: https://reviews.freebsd.org/D34699
Keywords:
: 269072 (view as bug list)
Depends on:
Blocks:
 
Reported: 2022-03-28 19:37 UTC by probono
Modified: 2024-03-17 17:10 UTC (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description probono 2022-03-28 19:37:36 UTC
/usr/sbin/fstyp is not able to detect FAT filesystem on Raspberry Pi Pico.

When attaching a Raspberry Pi Pico with the BOOTSEL button held down, there should be a USB storage device mounted so that the user can copy the firmware there.

/usr/local/sbin/automount is relying on /usr/sbin/fstyp to detect the partition type, since fstyp fails to recognize the FAT filesystem on the Raspberry Pi Pico, automount will not mount it.

A dd dump of the partition in question is available at
https://github.com/vermaden/automount/issues/41#issuecomment-1081055087
Comment 1 Ed Maste freebsd_committer freebsd_triage 2022-03-28 21:03:53 UTC
file says:

partition1.dd: DOS/MBR boot sector, code offset 0x3c+2, OEM-ID "MSWIN4.1", sectors/cluster 8, root entries 512, Media descriptor 0xf8, sectors/FAT 129, sectors/track 1, heads 1, hidden sectors 1, sectors 262143 (volumes > 32 MB), serial number 0x1ae50f, label: "RPI-RP2    ", FAT (16 bit)

fstyp fails on:
        /* Check for the FAT boot sector signature. */
        if (sector0[510] != 0x55 || sector0[511] != 0xaa) { 

00000000  eb 3c 90 4d 53 57 49 4e  34 2e 31 00 02 08 01 00  |.<.MSWIN4.1.....|
00000010  02 00 02 00 00 f8 81 00  01 00 01 00 01 00 00 00  |................|
00000020  ff ff 03 00 00 00 29 0f  e5 1a 00 52 50 49 2d 52  |......)....RPI-R|
00000030  50 32 20 20 20 20 46 41  54 31 36 20 20 20 eb fe  |P2    FAT16   ..|
00000040  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000050  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000060  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000070  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000080  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000090  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
000000a0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
000000b0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
000000c0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
000000d0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
000000e0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
000000f0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000100  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000110  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000120  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000130  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000140  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000150  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000160  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000170  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000180  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000190  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
000001a0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
000001b0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
000001c0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
000001d0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
000001e0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
000001f0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000200
Comment 2 Slawomir Wojciech Wojtczak 2022-03-29 08:11:21 UTC
Can you try this fix:

% fetch -o lsblk.FIX https://pastebin.com/raw/EqukzGwv
% sed -i '' -e s/$'\r'//g lsblk.FIX
% sh lsblk.FIX

The sed(1) line is to remove the 'Carriage Return' characters which will be visible in vim(1) as ^M at the end of each line.

Regards.
Comment 3 commit-hook freebsd_committer freebsd_triage 2022-03-29 21:34:18 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=868c1b8431f297ade8deba5baf903f73cf5e11c6

commit 868c1b8431f297ade8deba5baf903f73cf5e11c6
Author:     Ed Maste <emaste@FreeBSD.org>
AuthorDate: 2022-03-28 21:03:10 +0000
Commit:     Ed Maste <emaste@FreeBSD.org>
CommitDate: 2022-03-29 21:33:15 +0000

    fstyp: detect Raspberry Pi Pico boot filesystem as FAT

    fstyp looks for a 0x55 0xAA signature at offset 510, but this is not
    required by specifications and is not proivded by the Raspberry Pi Nano
    bootloader.

    We should really remove the signature check and implement a more
    comprehensive BPB validation instead, but it will require more
    investigation and testing.  For now just add a special case for the
    Raspberry Pi Nano bootloader, to avoid introducing regressions or new
    false positives.

    PR:             262896
    Reviewed by:    delphij
    MFC after:      3 days
    Sponsored by:   The FreeBSD Foundation
    Differential Revision:  https://reviews.freebsd.org/D34699

 usr.sbin/fstyp/msdosfs.c | 21 +++++++++++++++++++--
 1 file changed, 19 insertions(+), 2 deletions(-)
Comment 4 commit-hook freebsd_committer freebsd_triage 2022-03-31 20:11:42 UTC
A commit in branch stable/13 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=e06ce938ddc0222c6ed10a70108f71685923bd45

commit e06ce938ddc0222c6ed10a70108f71685923bd45
Author:     Ed Maste <emaste@FreeBSD.org>
AuthorDate: 2022-03-28 21:03:10 +0000
Commit:     Ed Maste <emaste@FreeBSD.org>
CommitDate: 2022-03-31 20:11:05 +0000

    fstyp: detect Raspberry Pi Pico boot filesystem as FAT

    fstyp looks for a 0x55 0xAA signature at offset 510, but this is not
    required by specifications and is not proivded by the Raspberry Pi Pico
    bootloader.

    We should really remove the signature check and implement a more
    comprehensive BPB validation instead, but it will require more
    investigation and testing.  For now just add a special case for the
    Raspberry Pi Pico bootloader, to avoid introducing regressions or new
    false positives.

    PR:             262896
    Reviewed by:    delphij
    MFC after:      3 days
    Sponsored by:   The FreeBSD Foundation
    Differential Revision:  https://reviews.freebsd.org/D34699

    (cherry picked from commit 868c1b8431f297ade8deba5baf903f73cf5e11c6)
    (cherry picked from commit 27c2f016b86744aa5d4c6031b4ef2fc16bbf6546)

 usr.sbin/fstyp/msdosfs.c | 21 +++++++++++++++++++--
 1 file changed, 19 insertions(+), 2 deletions(-)
Comment 5 commit-hook freebsd_committer freebsd_triage 2022-04-01 00:43:29 UTC
A commit in branch stable/12 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=1318b1ee9c4ee9ef6c1be600adc252a713b93961

commit 1318b1ee9c4ee9ef6c1be600adc252a713b93961
Author:     Ed Maste <emaste@FreeBSD.org>
AuthorDate: 2022-03-28 21:03:10 +0000
Commit:     Ed Maste <emaste@FreeBSD.org>
CommitDate: 2022-03-31 21:00:47 +0000

    fstyp: detect Raspberry Pi Pico boot filesystem as FAT

    fstyp looks for a 0x55 0xAA signature at offset 510, but this is not
    required by specifications and is not proivded by the Raspberry Pi Pico
    bootloader.

    We should really remove the signature check and implement a more
    comprehensive BPB validation instead, but it will require more
    investigation and testing.  For now just add a special case for the
    Raspberry Pi Pico bootloader, to avoid introducing regressions or new
    false positives.

    PR:             262896
    Reviewed by:    delphij
    MFC after:      3 days
    Sponsored by:   The FreeBSD Foundation
    Differential Revision:  https://reviews.freebsd.org/D34699

    (cherry picked from commit 868c1b8431f297ade8deba5baf903f73cf5e11c6)
    (cherry picked from commit 27c2f016b86744aa5d4c6031b4ef2fc16bbf6546)
    (cherry picked from commit e06ce938ddc0222c6ed10a70108f71685923bd45)

 usr.sbin/fstyp/msdosfs.c | 21 +++++++++++++++++++--
 1 file changed, 19 insertions(+), 2 deletions(-)
Comment 6 commit-hook freebsd_committer freebsd_triage 2022-04-05 18:55:15 UTC
A commit in branch releng/13.1 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=7b03cfcb24c201a25e92eca854c95dbbca2bc60f

commit 7b03cfcb24c201a25e92eca854c95dbbca2bc60f
Author:     Ed Maste <emaste@FreeBSD.org>
AuthorDate: 2022-03-28 21:03:10 +0000
Commit:     Ed Maste <emaste@FreeBSD.org>
CommitDate: 2022-04-05 18:54:04 +0000

    fstyp: detect Raspberry Pi Pico boot filesystem as FAT

    fstyp looks for a 0x55 0xAA signature at offset 510, but this is not
    required by specifications and is not provided by the Raspberry Pi Pico
    bootloader.

    We should really remove the signature check and implement a more
    comprehensive BPB validation instead, but it will require more
    investigation and testing.  For now just add a special case for the
    Raspberry Pi Pico bootloader, to avoid introducing regressions or new
    false positives.

    PR:             262896
    Reviewed by:    delphij
    MFC after:      3 days
    Sponsored by:   The FreeBSD Foundation
    Differential Revision:  https://reviews.freebsd.org/D34699

    (cherry picked from commit 868c1b8431f297ade8deba5baf903f73cf5e11c6)
    (cherry picked from commit 27c2f016b86744aa5d4c6031b4ef2fc16bbf6546)
    (cherry picked from commit e06ce938ddc0222c6ed10a70108f71685923bd45)

    Approved by:    re (gjb)

 usr.sbin/fstyp/msdosfs.c | 21 +++++++++++++++++++--
 1 file changed, 19 insertions(+), 2 deletions(-)
Comment 7 Robert Clausecker freebsd_committer freebsd_triage 2024-02-29 17:09:49 UTC
*** Bug 269072 has been marked as a duplicate of this bug. ***
Comment 8 Ed Maste freebsd_committer freebsd_triage 2024-03-17 17:10:45 UTC
*** Bug 269072 has been marked as a duplicate of this bug. ***