Is there any utility where I can exactly specify to which sector area the images are going to be burned ?
I need to burn an SD card according to a specific sector map,
e.g. bootloader should reside in 512K area from sector 57 to sector 1072 inclusively
kernel should reside in 4M area from sector 1073 to sector 9264 inclusively
and so on
SECTOR_SIZE=<sector size in bytes>
FLASH_DEV=/dev/sd??
sudo dd if=boot.bin of=$FLASH_DEV bs=$SECTOR_SIZE count=$((1072-57)) seek=57
sudo dd if=kernel of=$FLASH_DEV bs=$SECTOR_SIZE count=$((9264-1073)) seek=1073
Just man 1 dd, and you must determine name of your flash drive in /dev/sd* before.
You can use the dd utility and specify the sector offset with the 'seek' option
Related
A file of size 12,500 bytes is to be stored on a hard disk drive where the sector size is 512 bytes, and a cluster consists of 8 sectors. How much slack space is there once the file has been saved?
A few things to know:
Slack space is the leftover sectors and bytes from a cluster allocation.
Hard drives understand sectors and are nearly universally 512 bytes as far as logical block addressing goes.
OS (operating systems) understand clusters, which are groups of sectors. This amount of sectors can vary between OS and file system.
The OS DOES NOT understand sectors. The hard drive DOES NOT understand clusters. But they are both terms needed for calculating slack space.
Example 1
Given:
Sector Size: 512 bytes (basically the ONLY sector size these days)
cluster size: 8 sectors
file size: 2560 bytes
In this scenario, when disk space is allocated to store the file, the smallest amount that the OS can read/write MUST be 8 sectors or 4096 bytes.
To find slack space:
first find your cluster size in bytes. Cluster == 8 sectors.
∴ allotment is 4096.
then find if the file size is larger or smaller than that allotment size.
2560 bytes < 4096.
∴ only one cluster is needed to save this file
subtract the file size from the cluster size and you have slack space.
4096 - 2560 == 1536 bytes (or 3 sectors) of slack space.
Example 2
Given:
Sector Size: 512 bytes
cluster size: 16 sectors
file size: 61440 bytes
In this scenario, when disk space is allocated to store the file, the smallest amount that the OS can read/write MUST be 16 sectors or 8192 bytes.
Let's work through the same process:
first find your cluster size in bytes. Cluster == 16 sectors.
∴ allotment is 8192.
then find if the file size is larger or smaller than that allotment size.
61440 bytes > 8192.
∴ several clusters are needed to save this file.
since this file is larger, divide it by the cluster size in bytes.
61440 / 8192 == 7.5 clusters required to save this file.
This isn't a nice round number, so we will have to round up. Recall that the OS cannot write LESS than a whole cluster and if we allot less whole clusters than necessary, we won't save the file.
∴ we require 8 clusters.
find the size in bytes of your allotment size.
8 clusters * 8192 == 65536.
subtract the file size from the cluster allotment and you have slack space.
65536 - 61440 == 4096 bytes (or 4 sectors) of slack space.
Try it.
Refer to here, IOCTL_STORAGE_QUERY_PROPERTY with StorageAdapterProperty can be used to get the max transfer size of per SCSI Read(10) command.
In this code, 16 sectors are read from start of lba. I tried to modify the number and in my Win7 environment, the max number is 256 sector through SATA and 128 sector through bridge (SATA-USB) to a SSD, which match the result using IOCTL_STORAGE_QUERY_PROPERTY with StorageAdapterProperty.
As far as I know, when installing OS (win7, win10, macOS), a device can receive a SCSI Read(10) command up to 2048 sector. I wonder which layer limits the transfer size (operating system/device driver...) and is there any way to bypass the layer to send a SCSI Read(10) command longer than the limitation at a time?
I'm planning to use Spansion (now Cypress) S25FL032P flash memory. ( datasheet : http://www.cypress.com/file/196861/download )
On the datasheet, it says,
Memory architecture
– Uniform 64 KB sectors
– Top or bottom parameter block (Two 64-KB sectors (top or
bottom) broken down into sixteen 4-KB sub-sectors each)
– 256-byte page size
...
Erase
– Bulk erase function
– Sector erase (SE) command (D8h) for 64 KB sectors
– Sub-sector erase (P4E) command (20h) for 4 KB sectors
– Sub-sector erase (P8E) command (40h) for 8 KB sectors
So, it can perform erase operation on 1. chip, 2. 64k sector, 3. 8k sector, 4k sector level.
My question is, In both cases equivalently consume single P/E cycle on the perspective of 64kb sector?
Single command for 64kb sector erase.
16 commands for 64kb sector erase using 4k sector erase command (P4E)
Otherwise, second method consumes 16x P/E cycle?
I'm asking this because I want to issue erase command on as small as possible size while maximizing cell endurance as long as possible.
Can anyone explains how CD/DVD Boot Sector works to me? I've extracted some boot sectors from ISO images and found out that some of them are 6 sectors long and some are 8. I tried to look it up but no results. What is the minimum(maximum) length of a CD/DVD boot sector? Does it have to end with 0x55 0xAA?
Bootable ISO 9660 images are very different from other media such as floppies and hard drives. In the latter case, the BIOS loads a single, 512-byte sector, verifies the final 55 AA bytes, and then jumps to what it loaded.
El Torito, the extension that defines bootable ISO 9660 images for PCs, supports various methods of booting. Four of the methods emulate floppy (1.2M, 1.44M, 2.88M) and hard disk boot sectors; the BIOS will map the first floppy or hard disk to the CD-ROM so that you can take bootable floppies or small, bootable hard disks and convert them to ISO images. The last method is called native booting. Native boot sectors can be anywhere from 1-65535 sectors in length, or up to 32 MiB. Native boot sectors do not have to end in 55 AA.
ISO 9660 native sectors are almost always 2048 bytes, so native boot sectors will usually be 4 sectors long (512 * 4 == 2048).
You can find more info including a link to the El Torito standard here:
http://wiki.osdev.org/ISO_9660
http://wiki.osdev.org/El-Torito
https://en.wikipedia.org/wiki/El_Torito_(CD-ROM_standard)
Also, this document shows the binary structure of El Torito:
http://fossies.org/linux/xorriso/doc/boot_sectors.txt
i wanted to make a code that will run before the mbr, so i moved the mbr to the second sector, my code to sector zero. in sector 1 I loaded the second sector(which contains the mbr) than i call to address 7c00 to begin the mbr code.
so hard disk looks like this:
sector 0: my program that does IO ans loads sector 1
sector 1: code that loads sector 2
sector 2 mbr code
when i boot i receive this message:
"could not open drive multi 0 disk 0 rdisk 0 partition 1"
its importent to say that i want windows xp to run after my code
What you describe is exactly how the MBR code works:
The MBR of a hard disk is located at the first sector of the hard disk. BIOS will load that sector.
The MBR sector will move itself to some other address and load the first sector of the bootable hard disk partition to address 7C00 (hex). Then it will jump to 7C00 (hex).
However:
The MBR also contains information about the hard disk partitions in the last 80 bytes. If you want to replace the MBR by your own boot sector you'll have to copy the data located in the last 80 bytes. Otherwise hard disk access won't work any longer because the OS will look for hard disk information in thes last 80 bytes of the first sector of the hard disk.
If you want to replace the boot sector of the bootable partition you have a similar problem. Depending on the file system used there is file system information stored in some bytes of the boot sector. For FAT or NTFS the first three bytes must be a "JMP" instruction and the following about 65 bytes contain file system information.