summaryrefslogtreecommitdiffstats
path: root/common/partitions/dos.c
Commit message (Collapse)AuthorAgeFilesLines
* partitions: have parsers record bootable bitsAhmad Fatoum2024-03-051-0/+10
| | | | | | | | | barebox as EFI loader can use the information about which partitions are bootable to guide its decision. Record this information. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20240304190038.3486881-22-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* partitions: dos: change first partition number from 1 to 0Sascha Hauer2024-03-011-3/+3
| | | | | | | | | | | | Traditionally barebox starts partition numbers at 0. This was changed in 8f48e6366c to start at 1. This was done to make the parted numbering consistent to the Linux tool. This breaks boot scripts though which assume 0 to be the first partition, so change it back. Fixes: 8f48e6366c ("partitions: dos: implement partition manipulation support") Tested-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20240229071825.1624411-2-s.hauer@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Merge branch 'for-next/partitions'Sascha Hauer2024-02-211-39/+289
|\
| * partitions: dos: implement partition manipulation supportSascha Hauer2024-02-201-13/+243
| | | | | | | | | | | | | | | | This fills in the msdos specific function hooks to add/remove partitions. Link: https://lore.barebox.org/20240219083140.2713047-11-s.hauer@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * partitions: move parser.h to include/partitions.hSascha Hauer2024-02-201-2/+1
| | | | | | | | | | | | | | | | This will be needed by upcoming partition manipulation code, so move it to include/ Link: https://lore.barebox.org/20240219083140.2713047-9-s.hauer@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * partition: allocate struct partition in parserSascha Hauer2024-02-201-24/+32
| | | | | | | | | | | | | | | | | | Allocate struct partition in the parser rather than in the core partition code. Doing so allows the parser to embed struct partition in an implementation specific struct type. Link: https://lore.barebox.org/20240219083140.2713047-4-s.hauer@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * partition: allocate struct partition_desc in parserSascha Hauer2024-02-201-2/+12
| | | | | | | | | | | | | | | | | | Allocate struct partition_desc in parser rather than in the core. Doing so allows the efi/dos partition code to embed the struct partition_desc is a efi/dos specific struct type. Link: https://lore.barebox.org/20240219083140.2713047-3-s.hauer@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * partitions: dos: save indention levelSascha Hauer2024-02-201-25/+27
| | | | | | | | | | | | | | Save an indention level by continuing early in the loop. Link: https://lore.barebox.org/20240219083140.2713047-2-s.hauer@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | partitions: dos: support root=PARTUUID= generation with zero NT signatureAhmad Fatoum2024-02-161-8/+3
|/ | | | | | | | | | | | | | | | | | | | | | | | | | | For MBR-partitioned disks, the NT signature is used to derive the PARTUUID used to identify the root partition. For this to work reliably, the NT signature is expected to be unique across all attached MBR-partitioned storage. Some partition tools may populate the NT signature with an all-zero value by default, which will likely run afoul of the uniqueness expectations. When this happens, barebox' bootm.appendroot feature will report a non-descriptive error message: ERROR: Failed to append kernel cmdline parameter 'root=' and continue to boot the kernel without a root= option. As the kernel doesn't mind an all-zero NT signature, let's just support computing the correct partuuid in this case. The user is still presented with an info message: Adding "root=PARTUUID=00000000-02" to Kernel commandline and it's up to them to do something about it. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20240213100836.2853989-1-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* common: partitions: record whether disk is GPT or MBR partitionedAhmad Fatoum2023-06-121-0/+2
| | | | | | | | | | | | | | | Currently, the only way to differentiate between a GPT disk and a MBR one is to check whether the cdev's device has a guid (=> GPT) or a nt_signature (=> MBR) device parameter. We already have a flag parameter though, so let's record this info there for easy retrieval. We intentionally don't use the struct cdev::filetype member, because we don't want to change behavior of file_detect_type(). Reviewed-by: Marco Felsch <m.felsch@pengutronix.de> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20230607120714.3083182-14-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* cdev: use more descriptive struct cdev::diskuuid/partuuidAhmad Fatoum2023-06-081-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | The UUID field has different meanings: For a master cdev: - GPT Header DiskGUID if GPT-formatted - MBR Header NT Disk Signature if MBR-formatted For a partition cdev: - GPT UniquePartitionGUID - MBR Header NT Disk Signature followed by "-${partititon_number}" Later code will add yet another UUID (Partition Type GUID), so let's make existing code more readable by using either diskuuid or partuuid as appropriate. No functional change. Reviewed-by: Marco Felsch <m.felsch@pengutronix.de> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20230607120714.3083182-10-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* cdev: add diskuuid supportMichael Olbrich2022-02-081-0/+3
| | | | | | | | | | | | This allows identifying disks by UUID. For disks with GPT the disk GUID is used. For DOS partition tables the NT signature ist used, similar to how the partuuid is generated. Signed-off-by: Michael Olbrich <m.olbrich@pengutronix.de> Link: https://lore.barebox.org/20220124100458.2924679-3-m.olbrich@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de> Link: https://lore.barebox.org/20220207094953.949868-2-s.hauer@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* dos-partitions: Fix extended partitionsSascha Hauer2022-01-251-0/+2
| | | | | | | | | | | | | extended partitions are currently registered with their full size which means they overlap with the logical partitions therein. Since 7f9f45b9bf ("devfs: Do not create overlapping partitions") we no longer register overlapping partitions, so the logical partitions are no longer accessible. Fix this by reducing the size of the extended partition to two blocks (1kiB) which is the same as Linux does. Fixes: 7f9f45b9bf ("devfs: Do not create overlapping partitions") Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de> Reported-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
* x86: drop legacy (PC BIOS) boot in favor of EFIAhmad Fatoum2021-03-251-29/+0
| | | | | | | | | | | | | The 16-bit port has experienced bitrot and failed to compile with more recent linkers for at least a year. Fixing the linker error is insufficient to restore a barebox that can boot to shell. This continued breakage likely means that there are no users interested in updating. As new x86 projects should be using MACH_EFI_GENERIC anyway, retire support for 16-bit legacy boot (MACH_X86_GENERIC). Acked-by: Juergen Borleis <jbe@pengutronix.de> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* partitions: don't allocate dma capable memoryAhmad Fatoum2021-03-231-4/+3
| | | | | | | | | | | While block drivers may do DMA, they always use block caching chunks as bounce buffer. No dma is every done directly to the block_read data argument, so it doesn't need to be allocated with dma_alloc. The buffer also need not be zeroed, as block_read will either overwrite it completely or fail. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* partitions: dos: Treat all extended partition types equallyAndrey Smirnov2018-01-221-7/+18
| | | | | | | | | | | | | | | | | | | | Creating logical DOS partitions with fdisk (Fedora 27, fdisk from util-linux 2.30.2) results in extended partition of type 0x05 being created on the device. Partitioned like this, device is succesfully recognized by Linux, but, due to algorithm in dos_partition(), not Barebox. Looking closer at the actual contents of MBR shows that while marked as "Extended partition with CHS addressing" that partition still have all of the LBA adressed fields filled correctly. Given the above and the fact that similar code in Linux kernel (block/partitions/msdos.c) does not make a distinction between types 0x0f and 0x05, port Linux's is_extended_partition() and convert the code to treat types 0x05, 0x0f and 0x85 the same way. Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* param: make parameter functions more consistentSascha Hauer2017-04-111-1/+1
| | | | | | | | | | | | | | | | | | | | | | This patch creates a consitent set of device parameter functions. With this we have: dev_add_param_<type><access> "type" is one of: int32, uint32, int64, uint64, string, mac, ipv4, enum, bitmask The improvement here is that we now can exactly specify the width of the int type parameters and also correctly distinguish between signed and unsigned variables which means that a variable no longer ends up with INT_MAX when it's assigned -1. "access" can be empty for regular read/write parameter, "_ro" for readonly parameters which get their value from a variable pointer in the background or "_fixed" for parameters which are set to a fixed value (without a pointer in the background). Some more exotic types are not (yet) implemented, like dev_add_param_ip_ro. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* partitions: dos: add partuuid string for logical partitionsUwe Kleine-König2016-05-101-2/+7
| | | | | | | | | | | Commit bc31d85c6e23 ("cdev: Add partuuid string to struct cdev") added partuuid strings for dos partitions but only for the (up to) four primary partitions. Do the same for the logical partitions. Their numbers start at 5 independently of the number of available primary partitions. Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* cdev: Add partuuid string to struct cdevSascha Hauer2015-06-181-0/+4
| | | | | | | | This adds the partuuid string to struct cdev in order to have this available for constructing a suitable Linux root=PARTUUID= option for booting Linux. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* partitions: dos: parse extended partitionUwe Kleine-König2013-11-081-1/+75
| | | | | | | | DOS MBRs might contain an extended partition that holds several logical partitions. Add these to the partitions of the block device. Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* partitions: dos: don't open code get_unaligned_le32Uwe Kleine-König2013-11-081-1/+1
| | | | | Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* partitions: dos: improve guess of disk sizeUwe Kleine-König2013-11-081-5/+9
| | | | | | | | | | | | The code used to ineffectively take the end of the last partition as guess for the disk size. Better use the end of the partition that has its end rearmost. Also return an unsigned type instead of int as the result is always non-negative. Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* cdev: store dos partition type in struct cdevSascha Hauer2013-10-141-2/+5
| | | | Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* partitions: dos: fix memory leak in nt disk signatureSascha Hauer2013-06-191-0/+2
| | | | Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* partition: DOS: Add parameter for the NT disk SignatureSascha Hauer2013-06-021-0/+88
| | | | | | | | | | The NT disk Signature is a unique 32-bit value in the MBR allowing to identify a MSDOS partitioned disk. The signature can be used to specify the Linux rootfs. This patch adds support for the NT disk Signature in the form of a device parameter which can both be read and written. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* disk: introduce partition nameJean-Christophe PLAGNIOL-VILLARD2013-02-161-1/+1
| | | | | | | | so we can register partion with name as present in EFI GPT Cc: Rob Herring <rob.herring@calxeda.com> Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* partitons: add frameworkJean-Christophe PLAGNIOL-VILLARD2013-02-161-0/+88
so we can support multiple format use filetpye to detect the parser to use Cc: Rob Herring <rob.herring@calxeda.com> Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>