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
mkfs.fat, issue with boot AM335x from SD-Card. (answer the total_sect differs between 4.2 and 4.1) #165
Comments
Quoting from https://bugs.launchpad.net/ubuntu/+source/dosfstools/+bug/615873:
mkfs.fat 4.2 started using C/H/S geometry for FAT according to the SD Card Part 2 File System Specification be compliant with that standard. So It looks like that TI boot ROMs are not compliant with SD card standards mkfs.fat 4.2 has a new option -g for specifying custom C/H/S geometry. You could try to play with it if it helps. At least it was required for some people as reported on launchpad bug tracker. mkfs.fat has also for a long time option -a which disables aligning. You could try it too. Both aligning and C/H/S geometry affects total number of sectors. |
I have build the old and new version to compare. Because I am not to sure about the head 255 problem.
So I have done two runs on the same 1GB SDCARD with100MB dos partition and 900mb ext4 My question is how come that the numbers of total sectors is different between the old and new version of mkfs.fat ? AVR Total sectors : 0x00032000, 204800 (old 100mb) 100MB partition (1GB Disk) sudo ./mkdosfs /dev/sdc1 -F 32 -I -v mkdosfs 3.0.12 (29 Oct 2011) sudo ./mkfs.fat /dev/sdc1 -F 32 -I -v mkfs.fat 4.2+git (2021-01-31) |
As I said in my previous post:
So if you have 61 sectors per track then on disk with 3357 tracks you will have 61*3357=204777 total number of sectors. And on disk with 3358 tracks you will have 61*3358=204838 sectors. Older version of mkfs.fat did not aligned number of sectors, |
Ok, thanks that explains it better. I am not an expert in file formats :-) |
So you need to play with |
Maybe I just keep on using the old one to make sdcards. Since I dont know anything about partitions it will take a lot of time to try-and-error this. |
Well, if you do not do these tests and checks parameters, how can I help with resolving this issue? |
I have downloaded OMAP3 bootrom dump from http:https://droid-dev.mobi/wiki/File:Omap_3430.bin.gz and looked at it. At address 0x4D3A seems to be code which checks if read block is valid FAT12/16/32 partition. And seems there is nothing suspicious or special. Just that there is requirement for 2 FAT tables and sector size must be 512 bytes. At address 0x1AFC seems to be some FAT "fixup" function and instructions at addresses 0x1B48, 0x1B4A and 0x1B4E are erasing the least significant bit of total number of FAT32 sectors. So there can be an issue if total number of FAT32 sectors is odd number. Can you try to format it with even number of sectors per track and even number of heads? |
I will try your idea in the weekend. For some more info of the partition you can look at https://www.ti.com/lit/ug/spruh73q/spruh73q.pdf |
https://www.ti.com/lit/ug/spruh73q/spruh73q.pdf
|
So it looks like that it requires / expects that number of heads is 255 (like it was already described in launchpad bug report) and number of sectors per track is 63. This can be achieved by mkfs.fat Then there is interesting information that if C/H/S is known, which can be decoded only from MBR table, it is checked. So could mean that C/H/S for <<4GB cards needs to be correctly set also in MBR. And the last thing is that partition size in MBR must match total number of sectors. So for me it looks like that number of heads must be 255 (in both FAT and calculated in MBR), sectors per track must be 63 (again in both FAT and MBR), MBR partition size must be aligned to the total number of FAT sectors, which then implies that needs to be aligned to C/H/S. Totally insane... I thought that C/H/S is not used for 20+ years... So erase all partitions and try to create a new partition via And then format partition as FAT12/16/32 via |
Tried your suggestion as follows. sudo fdisk -c=dos -u=cylinders -H 255 -S 63 /dev/sdco - create DOS Partition a - boot sudo mkfs.fat -g 255/63 /dev/sdc1 The end result was a bootable disk. Thanks a lot this fixes the problem. |
Ok, thanks for testing. So now we know that 255/63 geometry is really needed (as written in that TI doc) and also C/H/S alignment. |
Thanks a lot for the help. You were totally on top of it. Ultra fast response on this item ! |
I also run into this issue, but we use bigger sd-cards (8 and 16GB).
and using
but both are still resulting in an not bootable sd-card sudo mkfs.fat --help |
Hmwel, I dont know much about this program. So I cannot help you on that. When I first encountered the problem I went back to the 2011-Version of mkfs.fat It is not a fix, but it will help to find a solution. |
@hmwel See my above comment #165 (comment) It applies for size < 4Gbytes. I'm not sure how to interpret it for bigger cards... |
On an am3874-based board, adding the "-a" option fixed boot failures on a 32GB flash card. I am (naively and optimistically) choosing to believe that this is more SD-card-agnostic than explicitly specifying geometry. |
@gsmecher If you look into the documentation for Recently I sent patch to util-linux's fdisk tool to try reconstruct geometry (number-of-heads and sectors-per-track) from MBR table and fills correct C/H/S values in MBR table when creating/updating partitions. I could probably extend mkfs.fat to try read this geometry from MBR in the same way how util-linux's fdisk, which could help with these issues (so number-of-heads and sectors-per-track in MBR would match them in FAT). But this works only when MBR partition ends in first 8GB (when C/H/S in MBR values do not overflow) |
Hello |
I do not know about any changes in master branch after v4.2 tag which could change behavior or fix that issue. I guess that you could format disk differently and C/H/S in MBR or in FAT could have been filled differenty. |
OK, good to know that the new version is not supposed to help. When I was testing with the master branch, I was on another machine and I was formatting my partition through the MMC interface (/dev/mmcblk0p1). If I use a USB card reader (using /dev/sdb1) as in my other tests, I still have the issue. So, this confirms that the latest commits don't fix the issue as you suspected. So, actually version 4.2 works when you access the partition through the MMC interface instead of using a USB card reader |
I guess the MMC interface (/dev/mmcblk0p1) exposes more information than the standard block device through USB mass storage (/dev/sdb1), and that could make a difference for mkfs.vfat. Could this be correct? |
Not more information but different information. And it could be the reason. |
For booting an Texas-AM335x (Beagle-board) from the SD-card the cpu uses a own hard coded bootloader (by TI)
Basicly it looks for a boot partition and tries to find MLO (a boot loader) on the sdcard.
So create a bootable dos partition on the SDCARD with mkfs.fat and it works. This all worked fine with the mkfs.fat 4.1 (2017-01-24) which is included on Ubuntu 20.04
After upgrading to Ubuntu 21.04 the new version mkfs.fat 4.2 (2021-01-31) was included. Since then the AM335x will not boot anymore with the newly created cards.
After comparing the output of both programs on the Scards I found out that at offset 0x20 of the partition there is the total counts of sectors on the volume.
This has a different number on the 4.1 than the 4.2 version. So when I create a partition
sudo ./mkfs.fat -v -I -F 32 /dev/sdc1
The 4.1 will have 00 00 0C 00
The 4.2 will have EC FF 0B 00
The rest of the partition is exactly the same (beside serial number)
This test is done multiple time on the SAME SD-CARD.
The BFFEC is the correct number of sectors, but the C0000 is the one allowing the AM335x to boot. But how can the calculation differ on the same card ?
To make sure this was the problem I patched the program at line 1210
This would make the SDCARD boot.
So why is this calculation (or the result) different between to program's ?
The text was updated successfully, but these errors were encountered: