Commit Graph

286 Commits

Author SHA1 Message Date
Heinrich Schuchardt 44ab2d325b efi_loader: avoid initializer element is not constant
When building with -pedantic the current definition of EFI_GUID() causes
an error 'initializer element is not constant'.

Currently EFI_GUID() is used both as an anonymous constant and as an
intializer. A conversion to efi_guid_t is not allowable when using
EFI_GUID() as an initializer. But it is needed when using it as an
anonymous constant.

We should not use EFI_GUID() for anything but an initializer. So let's
introduce a variable where needed and remove the conversion.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Signed-off-by: Alexander Graf <agraf@suse.de>
2018-06-14 10:52:14 +02:00
Sam Protsenko 955575c8dc disk: efi: Correct backing up the MBR boot code
In commit e163a931af ("cmd: gpt: backup boot code before writing MBR")
there was added the procedure for storing old boot code when doing "gpt
write". But instead of storing just backup code, the whole MBR was
stored, and only specific fields were replaced further, keeping
everything else intact. That's obviously not what we want.

Fix the code to actually store only old boot code and zero out
everything else. This fixes next testing case:

    => mmc write $loadaddr 0x0 0x7b
    => gpt write mmc 1 $partitions

In case when $loadaddr address and further memory contains 0xff, the
board was bricked (ROM-code probably didn't like partition entries that
were clobbered with 0xff). With this patch applied, commands above don't
brick the board.

Signed-off-by: Sam Protsenko <semen.protsenko@linaro.org>
Cc: Alejandro Hernandez <ajhernandez@ti.com>
Tested-by: Andy Shevchenko <andy.shevchenko@gmail.com>
2018-06-05 10:33:57 -04:00
Tom Rini 83d290c56f SPDX: Convert all of our single license tags to Linux Kernel style
When U-Boot started using SPDX tags we were among the early adopters and
there weren't a lot of other examples to borrow from.  So we picked the
area of the file that usually had a full license text and replaced it
with an appropriate SPDX-License-Identifier: entry.  Since then, the
Linux Kernel has adopted SPDX tags and they place it as the very first
line in a file (except where shebangs are used, then it's second line)
and with slightly different comment styles than us.

In part due to community overlap, in part due to better tag visibility
and in part for other minor reasons, switch over to that style.

This commit changes all instances where we have a single declared
license in the tag as both the before and after are identical in tag
contents.  There's also a few places where I found we did not have a tag
and have introduced one.

Signed-off-by: Tom Rini <trini@konsulko.com>
2018-05-07 09:34:12 -04:00
Alex Kiernan ab9e12f651 spl: disk: usb: Add dependencies to sprintf/strto*
If SPL serial support is disabled nothing brings in sprintf, snprintf
or simple_strtoul:

  env/built-in.o: In function `regex_callback':
  env/attr.c:128: undefined reference to `sprintf'
  disk/built-in.o: In function `blk_get_device_by_str':
  disk/part.c:386: undefined reference to `simple_strtoul'
  disk/part.c:395: undefined reference to `simple_strtoul'
  disk/built-in.o: In function `blk_get_device_part_str':
  disk/part.c:522: undefined reference to `simple_strtoul'
  disk/built-in.o: In function `part_set_generic_name':
  disk/part.c:704: undefined reference to `sprintf'
  drivers/built-in.o: In function `init_peripheral_ep':
  drivers/usb/musb-new/musb_gadget.c:1826: undefined reference to `sprintf'
  drivers/built-in.o: In function `musb_core_init':
  drivers/usb/musb-new/musb_core.c:1451: undefined reference to `snprintf'

Add those dependencies here.

Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com>
2018-04-28 18:32:24 -04:00
Tom Rini d024236e5a Remove unnecessary instances of DECLARE_GLOBAL_DATA_PTR
We have a large number of places where while we historically referenced
gd in the code we no longer do, as well as cases where the code added
that line "just in case" during development and never dropped it.

Signed-off-by: Tom Rini <trini@konsulko.com>
2018-04-27 14:54:48 -04:00
Alexander Graf 4f67b93fb7 part: Disable CONFIG_SPL_ISO_PARTITION by default
We enabled CONFIG_ISO_PARTITION by default for distro boot, so that U-Boot
could load distro images that usually get shipped as iso images. These images
usually come with a board agnostic boot environment.

However, there is very little point in having ISO support enabled (for anyone
really) in SPL, as the whole idea of SPL is to load U-Boot proper which again
is board specific. So the fact that we enable ISO support in U-Boot proper does
not mean at all that we want ISO support in U-Boot SPL.

Hence, let's remove the Kconfig dependency. Along the way, let's also clean up
all those default configs that disabled SPL ISO support.

Signed-off-by: Alexander Graf <agraf@suse.de>
2018-04-16 18:45:35 -04:00
Kever Yang 56670d6fb8 disk: part: use common api to lookup part driver
Do not need to scan disk every time when we get part info
by name.

Signed-off-by: Kever Yang <kever.yang@rock-chips.com>
[trini: Fix build in !CONFIG_HAVE_BLOCK_DEVICE case]
Signed-off-by: Tom Rini <trini@konsulko.com>
2018-03-13 21:58:45 -04:00
Kever Yang d472926919 disk: part: scan the disk if the part_type is unknown
If a DUT do not have partition table, and we write one with 'gpt write'
cmd, we should able to list the partition with 'part list' cmd.
It's reasonable to scan the disk again if the initial part_type is
unknown in case we just write a new one into disk.

Signed-off-by: Kever Yang <kever.yang@rock-chips.com>
2018-03-13 21:46:05 -04:00
Adam Ford 1811a928c6 Move most CONFIG_HAVE_BLOCK_DEVICE to Kconfig
config_fallbacks.h has some logic that sets HAVE_BLOCK_DEVICE
based on a list of enabled options.  Moving HAVE_BLOCK_DEVICE to
Kconfig allows us to drastically shrink the logic in
config_fallbacks.h

Signed-off-by: Adam Ford <aford173@gmail.com>
[trini: Rename HAVE_BLOCK_DEVICE to CONFIG_BLOCK_DEVICE]
Signed-off-by: Tom Rini <trini@konsulko.com>
2018-02-08 19:09:03 -05:00
Adam Ford a451bc27c9 Convert LIB_UUID to Kconfig
config_fallback.h has some logic that checks a variety of options
and selects LIB_UUID if it hasn't already been selected.  This
will all LIB_UUID in Kconfig and select this option for the list
of options to allow us to remove the logic from fallbacks

Signed-off-by: Adam Ford <aford173@gmail.com>
2018-02-08 19:08:39 -05:00
Alexey Brodkin 8639e34d2c part: Allocate only one legacy_mbr buffer
Commit ff98cb9051 ("part: extract MBR signature from partitions")
blindly switched allocated by ALLOC_CACHE_ALIGN_BUFFER buffer type from
"unsigned char" to "legacy_mbr" which caused allocation of size =
(typeof(legacy_mbr) * dev_desc->blksize) instead of just space enough
for "legacy_mbr" structure.

Signed-off-by: Alexey Brodkin <abrodkin@synopsys.com>
Cc: Rob Clark <robdclark@gmail.com>
Cc: Peter Jones <pjones@redhat.com>
Cc: Alexander Graf <agraf@suse.de>
Cc: Tom Rini <trini@konsulko.com>
2018-02-07 22:06:17 -05:00
Tom Rini 76cc372879 Merge git://git.denx.de/u-boot-sunxi 2017-12-19 07:57:33 -05:00
Maxime Ripard 5dc0256d12 part: efi: Add default number of partition entries for sunxi
The SPL must be located at 8kB (16 sectors) offset. That's right in the
middle of the GPT, so we need to define a smaller amount of partitions to
accomodate for that location.

Reviewed-by: Andre Przywara <andre.przywara@arm.com>
Signed-off-by: Maxime Ripard <maxime.ripard@free-electrons.com>
2017-12-07 16:24:31 +01:00
Maxime Ripard 4ce521977f part: efi: Add a Kconfig option for the number of partition entries
On some SoCs, the SPL needs to be located right in the middle of the GPT
partition entries.

One way to work around that is to create partition entries for a smaller
number of partitions to accomodate with where the SPL will be. Create a
Kconfig option to allow to do that.

Reviewed-by: Andre Przywara <andre.przywara@arm.com>
Reviewed-by: Tom Rini <trini@konsulko.com>
Signed-off-by: Maxime Ripard <maxime.ripard@free-electrons.com>
2017-12-07 16:24:31 +01:00
Patrick Delaunay 3cc566117e disk: efi: correct the allocation size for mbr header in stack
use ALLOC_CACHE_ALIGN_BUFFER_PAD for mbr header allocation
in stack to fix alloc issue in is_gpt_valid()

this patch fix also issue for GPT partition handling
with blocksize != 512 in set_protective_mbr()

Signed-off-by: Patrick Delaunay <patrick.delaunay@st.com>
2017-11-29 22:30:50 -05:00
Shawn Guo 8f7102cf6b disk: part_dos: fix part_get_info_extended() function
The check in part_get_info_extended() for a successful partition
searching misses a condition for extended partition. In case of
(ext_part_sector == 0), we should anyway mark the partition as found,
even if it's an extended partition, i.e. (is_extended(pt->sys_ind) == 0).
Otherwise, the extended partition (type 0x0f) will never be identified,
and the following recursive call to part_get_info_extended() will get a
wrong 'part_num' and 'which_part' parameter.  In the end, all those
partitions in extended table will not be identified.

Let's add the missing OR condition of (ext_part_sector == 0) for
is_extended() check to fix the problem.

The issue is discovered by running fastboot flash to an extended
partition on eMMC.

  $ fastboot flash mmcsda5 cache.img
  target reported max download size of 536870912 bytes
  sending 'mmcsda5' (18796 KB)...
  OKAY [  2.144s]
  writing 'mmcsda5'...
  FAILED (remote: cannot find partition)
  finished. total time: 2.261s

Signed-off-by: Shawn Guo <shawn.guo@linaro.org>
2017-11-06 09:59:01 -05:00
Lukasz Majewski bb021013ba gpt: Use cache aligned buffers for gpt_h and gpt_e
Before this patch one could receive following errors when executing
"gpt write" command on machine with cache enabled:

display5 factory > gpt write mmc ${mmcdev} ${partitions}
Writing GPT:
CACHE: Misaligned operation at range [4ef8f7f0, 4ef8f9f0]
CACHE: Misaligned operation at range [4ef8f9f8, 4ef939f8]
CACHE: Misaligned operation at range [4ef8f9f8, 4ef939f8]
CACHE: Misaligned operation at range [4ef8f7f0, 4ef8f9f0]
success!

To alleviate this problem - the calloc()s have been replaced with
malloc_cache_aligned() and memset().

After those changes the buffers are properly aligned (with both start
address and size) to SoC cache line.

Signed-off-by: Lukasz Majewski <lukma@denx.de>
2017-11-06 09:59:01 -05:00
Patrick Delaunay ae0e0228e6 disk: efi: correct the overlap check on GPT header and PTE
the partition starting at 0x4400 is refused with overlap error:
  $> gpt write mmc 0 "name=test,start=0x4400,size=0"
  Writing GPT: Partition overlap
  error!

even if the 0x4400 is the first available offset for LBA35 with default
value:
- MBR=LBA1
- GPT header=LBA2
- PTE= 32 LBAs (128 entry), 3 to 34

And the command to have one partition for all the disk failed also :
  $> gpt write mmc 0 "name=test,size=0"

After the patch :

  $> gpt write mmc 0 "name=test,size=0"
  Writing GPT: success!
  $> part list mmc 0

  Partition Map for MMC device 0  --   Partition Type: EFI

  Part	Start LBA	End LBA		Name
	Attributes
	Type GUID
	Partition GUID
  1	0x00000022	0x01ce9fde	"test"
	attrs:	0x0000000000000000
	type:	ebd0a0a2-b9e5-4433-87c0-68b6b72699c7
	type:	data
	guid:	b4b84b8a-04e3-4000-0036-aff5c9c495b1

And 0x22 = 34 LBA => offset = 0x4400 is accepted as expected

Reviewed-by: Łukasz Majewski <lukma@denx.de>
Tested-by: Stephen Warren <swarren@nvidia.com>
Signed-off-by: Patrick Delaunay <patrick.delaunay@st.com>
2017-10-23 17:27:48 -04:00
Alexander Graf b16339e254 iso: Reduce verbosity on test and info calls
The test and info callbacks into the partition callback struct are
used by the "part list" command on the command line. That command
is used by the distro script.

With verb=1 set, "part list" thus throws a lot of warnings about
partitions it can't find when an upper layer searches for partitions.

So let's reduce verbosity to bring it to the same level of noise
as the other partition targets.

Signed-off-by: Alexander Graf <agraf@suse.de>
2017-10-16 09:42:51 -04:00
Tom Rini b351ccf11a part_efi: In is_gpt_valid() check argument validity before allocation
While this goes somewhat against normal coding style we should ensure
that dev_desc is not NULL before we dereference it in allocation of
legacy_mbr.

Reported-by: Coverity (CID: 167292)
Signed-off-by: Tom Rini <trini@konsulko.com>
2017-10-16 09:42:51 -04:00
Sam Protsenko 3078909556 disk: Provide API to get partition by name for specific type
There is already existing function part_get_info_by_name().
But sometimes user is particularly interested in looking for only
specific partition type. This patch implements such an API that
provides partition searching by name for specified partition type.

Signed-off-by: Sam Protsenko <semen.protsenko@linaro.org>
Reviewed-by: Simon Glass <sjg@chromium.org>
2017-10-06 11:28:17 -04:00
Fabio Estevam 3ea0520512 disk: part_dos: Use the original allocation scheme for the SPL case
Since commit ff98cb9051 ("part: extract MBR signature from partitions")
SPL boot on i.MX6 starts to fail:

U-Boot SPL 2017.09-00221-g0d6ab32 (Oct 02 2017 - 15:13:19)
Trying to boot from MMC1
(keep in loop)

Use the original allocation scheme for the SPL case, so that MX6 boards
can boot again.

This is a temporary solution to avoid the boot regression.

Signed-off-by: Fabio Estevam <fabio.estevam@nxp.com>
Acked-by: Rob Clark <robdclark@gmail.com>
Tested-by: Peter Robinson <pbrobinson@gmail.com>
2017-10-05 10:45:33 -04:00
Masahiro Yamada 9b643e312d treewide: replace with error() with pr_err()
U-Boot widely uses error() as a bit noisier variant of printf().

This macro causes name conflict with the following line in
include/linux/compiler-gcc.h:

  # define __compiletime_error(message) __attribute__((error(message)))

This prevents us from using __compiletime_error(), and makes it
difficult to fully sync BUILD_BUG macros with Linux.  (Notice
Linux's BUILD_BUG_ON_MSG is implemented by using compiletime_assert().)

Let's convert error() into now treewide-available pr_err().

Done with the help of Coccinelle, excluing tools/ directory.

The semantic patch I used is as follows:

// <smpl>
@@@@
-error
+pr_err
 (...)
// </smpl>

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
[trini: Re-run Coccinelle]
Signed-off-by: Tom Rini <trini@konsulko.com>
2017-10-04 11:59:44 -04:00
Peter Jones ff98cb9051 part: extract MBR signature from partitions
EFI client programs need the signature information from the partition
table to determine the disk a partition is on, so we need to fill that
in here.

Signed-off-by: Peter Jones <pjones@redhat.com>
[separated from efi_loader part, and fixed build-errors for non-
 CONFIG_EFI_PARTITION case]
Signed-off-by: Rob Clark <robdclark@gmail.com>
Signed-off-by: Alexander Graf <agraf@suse.de>
2017-09-20 10:20:19 +02:00
Andre Przywara eefa0a647d EFI: find EFI system partition by legacy MBR partition type
The UEFI spec allows an EFI system partition (ESP, with the bootloader or
kernel EFI apps on it) to reside on a disk using a "legacy" MBR
partitioning scheme.
But in contrast to actual legacy disks the ESP is not marked as
"bootable" using bit 7 in byte 0 of the legacy partition entry, but is
instead using partition *type* 0xef (in contrast to 0x0b or 0x0c for a
normal FAT partition). The EFI spec isn't 100% clear on this, but it even
seems to discourage the use of the bootable flag for ESPs.
Also it seems that some EFI implementations (EDK2?) even seem to ignore
partitions marked as bootable (probably since they believe they contain
legacy boot code).
The Debian installer [1] (*not* mini.iso), for instance, contains such an
MBR, where none of the two partitions are marked bootable, but the ESP
has clearly type 0xef.
Now U-Boot cannot find the ESP on such a disk (USB flash drive) and
fails to load the EFI grub and thus the installer.

Since it all boils down to the distro bootcmds eventually calling
"part list -bootable" to find potential boot partitions, it seems logical
to just add this "partition type is 0xef" condition to the is_bootable()
implementation.

This allows the bog standard arm64 Debian-testing installer to boot from
an USB pen drive on Allwinner A64 boards (Pine64, BananaPi-M64).
(Ubuntu and other distribution installers don't have a legacy MBR, so
U-Boot falls back to El Torito there).

[1] https://cdimage.debian.org/cdimage/daily-builds/daily/arch-latest/arm64/iso-cd/
Signed-off-by: Andre Przywara <andre.przywara@arm.com>
Reviewed-by: Alexander Graf <agraf@suse.de>
Signed-off-by: Alexander Graf <agraf@suse.de>
2017-09-18 23:53:56 +02:00
Rob Clark 4bbcc965f9 fs: add fs_readdir()
Needed to support efi file protocol.  The fallback.efi loader wants
to be able to read the contents of the /EFI directory to find an OS
to boot.

Modelled after POSIX opendir()/readdir()/closedir().  Unlike the other
fs APIs, this is stateful (ie. state is held in the FS_DIR "directory
stream"), to avoid re-traversing of the directory structure at each
step.  The directory stream must be released with closedir() when it
is no longer needed.

Signed-off-by: Rob Clark <robdclark@gmail.com>
Reviewed-by: Łukasz Majewski <lukma@denx.de>
Reviewed-by: Simon Glass <sjg@chromium.org>
2017-09-15 09:03:11 -04:00
Bin Meng 337e3b897d part: mac: Suppress the error message after reading ddb
Change to use 'debug' to output the error message if it fails to
read the driver descriptor block.

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
2017-09-07 10:44:33 -04:00
Heinrich Schuchardt 5eae466ea1 disk: part: fix typo
%s/Desriptor/Descriptor/g

Fix lines over 80 characters with said typo.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2017-09-03 15:30:32 -04:00
Maxime Ripard 79c5912e8d part: efi: Disable overlap check
The current code checks that no partitions overlap with the GPT partition
table using the offset of the first LBA usable for that partition.

This works fine, unless you have a partition entry that is further away
than it usually is and you want to create partitions in the gap between the
GPT header and the GPT partition entries, for example to reflash a
bootloader that needs to be set there.

Rework the test to something a bit smarter that checks whether a partition
would overlap with either the GPT header or the partition entries, no
matter where it is on the disk.

Partitions that do not have a start LBA specified will still start at the
first LBA usable set in the GPT header, to avoid weird behaviours.

Signed-off-by: Maxime Ripard <maxime.ripard@free-electrons.com>
Reviewed-by: Tom Rini <trini@konsulko.com>
2017-09-03 11:04:51 -04:00
Maxime Ripard 47d7ee47ba part: efi: make gpt_fill_pte take the device descriptor
The gpt_fill_pte will need to access the device block size. Let's pass the
device descriptor as an argument.

Signed-off-by: Maxime Ripard <maxime.ripard@free-electrons.com>
Reviewed-by: Tom Rini <trini@konsulko.com>
2017-09-03 11:04:51 -04:00
Maxime Ripard 5276e8b62d part: efi: rework the partition start and size in gpt_fill_pte
The start variable is only used inside a loop, and is never affected inside
it, so it's a purely local variable.

In the same way the partition size is accessed several times, so we can
store it in a variable.

Signed-off-by: Maxime Ripard <maxime.ripard@free-electrons.com>
Reviewed-by: Tom Rini <trini@konsulko.com>
2017-09-03 11:04:48 -04:00
Maxime Ripard 89d33a2c0d part: efi: Fix offset
Both the config option and the DT options specify the offset to set the GPT
at in bytes, yet the code treats those values as block numbers.

Fix that.

Signed-off-by: Maxime Ripard <maxime.ripard@free-electrons.com>
Reviewed-by: Tom Rini <trini@konsulko.com>
Reviewed-by: Philipp Tomsich <philipp.tomsich@theobroma-systems.com>
2017-09-03 11:04:47 -04:00
Stefan Agner 5c27535dc9 disk: part: align buffer so it can be used with DMA enabled drivers
When using ISO partitions with a DMA enabled block device driver
reading the ISO partition leads to unaligned DMA operations:
  CACHE: Misaligned operation at range [bffb7da8, bffb85a8]

Align the buffer to make sure we pass a buffer which works for
DMA operations.

Signed-off-by: Stefan Agner <stefan.agner@toradex.com>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
2017-08-26 14:56:15 -04:00
Simon Glass 00caae6d47 env: Rename getenv/_f() to env_get()
We are now using an env_ prefix for environment functions. Rename these
two functions for consistency. Also add function comments in common.h.

Quite a few places use getenv() in a condition context, provoking a
warning from checkpatch. These are fixed up in this patch also.

Suggested-by: Wolfgang Denk <wd@denx.de>
Signed-off-by: Simon Glass <sjg@chromium.org>
2017-08-16 08:30:24 -04:00
Zhikang Zhang ffab6945ec dm: blk: part: Add UCLASS_NVME and IF_TYPE_NVME
This adds a new uclass id and block interface type for NVMe.

Signed-off-by: Zhikang Zhang <zhikang.zhang@nxp.com>
Signed-off-by: Wenbin Song <wenbin.song@nxp.com>
Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
Signed-off-by: Jon Nettleton <jon@solid-run.com>
Reviewed-by: Tom Rini <trini@konsulko.com>
2017-08-13 15:17:30 -04:00
Alison Chaiken 73d6d18b71 GPT: add accessor function for disk GUID
In order to read the GPT, modify the partition name strings, and then
write out a new GPT, the disk GUID is needed.  While there is an
existing accessor for the partition UUIDs, there is none yet for the
disk GUID.

Changes since v6: none.

Signed-off-by: Alison Chaiken <alison@peloton-tech.com>
2017-08-04 09:56:04 -04:00
Alison Chaiken e6faf21f25 partitions: increase MAX_SEARCH_PARTITIONS and move to part.h
Move MAX_SEARCH_PARTITIONS to part.h so that functions in cmd
directory can find it.  At the same time, increase the value to
64 since some operating systems use many, and the resources
consumed by a larger value are minimal.

Changes since v6: none.

Signed-off-by: Alison Chaiken <alison@peloton-tech.com>
2017-08-04 09:56:03 -04:00
Alison Chaiken db9b6200a4 EFI: replace number with UUID_STR_LEN macro
Changes since v6: none.

Signed-off-by: Alison Chaiken <alison@peloton-tech.com>
2017-08-04 09:55:29 -04:00
Alex Deymo 88b6329cce disk: Return the partition number in part_get_info_by_name()
Similar to what blk_get_device_part_str() does, this patch makes
part_get_info_by_name() return the partition number in case of a match.
This is useful when the partition number is needed and not just the
descriptor.

Signed-off-by: Alex Deymo <deymo@google.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
2017-05-11 22:03:37 -04:00
Tom Rini 936478e797 SPARC: Remove
The SPARC architecture is currently unmaintained, remove.

Cc: Francois Retief <fgretief@spaceteq.co.za>
Signed-off-by: Tom Rini <trini@konsulko.com>
2017-04-05 13:52:20 -04:00
Philipp Tomsich 02e43537b3 part_efi: support padding between the GPT header and partition entries
Some architectures require their SPL loader at a fixed address within
the first 16KB of the disk. To avoid an overlap with the partition
entries of the EFI partition table, the first safe offset (in bytes,
from the start of the device) for the entries can be set through
CONFIG_EFI_PARTITION_ENTRIES_OFF (via Kconfig)

When formatting a device with an EFI partition table, we may need to
leave a gap between the GPT header (always in LBA 1) and the partition
entries. The GPT header already contains a field to specify the
on-disk location, which has so far always been set to LBA 2. With this
change, a configurable offset will be translated into a LBA address
indicating where to put the entries.

Now also allows an override via device-tree using a config-node (see
doc/device-tree-bindings/config.txt for documentation).

Tested (exporting an internal MMC formatted with this) against Linux,
MacOS X and Windows.

Signed-off-by: Philipp Tomsich <philipp.tomsich@theobroma-systems.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
[trini: __maybe_unused on config_offset to avoid warning]
Signed-off-by: Tom Rini <trini@konsulko.com>
2017-03-20 18:04:18 -04:00
Vincent Tinelli 9da52f8f67 gpt: Fix uuid string format
Change GPT UUID string format from UUID to GUID per specification.

Signed-off-by: Vincent Tinelli <vincent.tinelli@intel.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
2017-03-17 14:15:10 -04:00
Dalon Westergreen f0fb4fa7d5 SPL: add support to boot from a partition type
the socfpga bootrom supports mmc booting from either a raw image
starting at 0x0, or from a partition of type 0xa2.  This patch
adds support for locating the boot image in the first type 0xa2
partition found.

Assigned a partition number of -1 will cause a search for a
partition of type CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_PARTITION_TYPE
and use it to find the u-boot image

Signed-off-by: Dalon Westergreen <dwesterg@gmail.com>
2017-02-17 14:15:14 -05:00
Vincent Tinelli e163a931af cmd: gpt: backup boot code before writing MBR
On some cases the first 440 bytes of MBR are used to keep an additional
information for ROM boot loader. 'gpt write' command doesn't preserve
that area and makes boot code gone.

Preserve boot code area when run 'gpt write' command.

Signed-off-by: Vincent Tinelli <vincent.tinelli@intel.com>
Signed-off-by: Brennan Ashton <brn@deako.com>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
2017-02-08 15:56:29 -05:00
Patrick Delaunay aed8fdaae9 disk: convert CONFIG_PARTITION_TYPE_GUID to Kconfig
Signed-off-by: Patrick Delaunay <patrick.delaunay@st.com>
Signed-off-by: Patrick Delaunay <patrick.delaunay73@gmail.com>
2017-01-28 08:48:04 -05:00
Patrick Delaunay b331cd6204 cmd, disk: convert CONFIG_PARTITION_UUIDS, CMD_PART and CMD_GPT
We convert CONFIG_PARTITION_UUIDS to Kconfig first.  But in order to cleanly
update all of the config files we must also update CMD_PART and CMD_GPT to also
be in Kconfig in order to avoid complex logic elsewhere to update all of the
config files.

Signed-off-by: Patrick Delaunay <patrick.delaunay@st.com>
Signed-off-by: Patrick Delaunay <patrick.delaunay73@gmail.com>
Signed-off-by: Tom Rini <trini@konsulko.com>
2017-01-28 08:48:03 -05:00
Patrick Delaunay bd42a94268 disk: convert CONFIG_EFI_PARTITION to Kconfig
Signed-off-by: Patrick Delaunay <patrick.delaunay@st.com>
Signed-off-by: Patrick Delaunay <patrick.delaunay73@gmail.com>
2017-01-28 08:47:42 -05:00
Patrick Delaunay 863c5b6cdd disk: convert CONFIG_AMIGA_PARTITION to Kconfig
Signed-off-by: Patrick Delaunay <patrick.delaunay@st.com>
Signed-off-by: Patrick Delaunay <patrick.delaunay73@gmail.com>
2017-01-28 08:47:36 -05:00
Patrick Delaunay 1acc008787 disk: convert CONFIG_ISO_PARTITION to Kconfig
Signed-off-by: Patrick Delaunay <patrick.delaunay@st.com>
Signed-off-by: Patrick Delaunay <patrick.delaunay73@gmail.com>
2017-01-28 08:47:35 -05:00
Patrick Delaunay b0cf733933 disk: convert CONFIG_DOS_PARTITION to Kconfig
Signed-off-by: Patrick Delaunay <patrick.delaunay@st.com>
Signed-off-by: Patrick Delaunay <patrick.delaunay73@gmail.com>
2017-01-28 08:47:34 -05:00
Patrick Delaunay f18fa31cdc disk: convert CONFIG_MAC_PARTITION to Kconfig
Signed-off-by: Patrick Delaunay <patrick.delaunay@st.com>
Signed-off-by: Patrick Delaunay <patrick.delaunay73@gmail.com>
2017-01-28 08:47:31 -05:00
Patrick Delaunay e274ef6b57 disk: convert CONFIG_PARTITIONS to Kconfig
Signed-off-by: Patrick Delaunay <patrick.delaunay@st.com>
Signed-off-by: Patrick Delaunay <patrick.delaunay73@gmail.com>
2017-01-28 08:47:30 -05:00
Jean-Jacques Hiblot 139f7b1ded disk: Fixed capacity message
With capacities getting bigger, we can see see messages with negative
numbers like "Capacity: 1907729.0 MB = 1863.0 GB (-387938128 x 512)".
Here the printed LBA is -387938128 when it should have been 3907029168.
To fix this, use the right format when displaying the unsigned integers.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reported-by: Yan Liu <yan-liu@ti.com>
2016-12-27 11:24:18 -05:00
Petr Kulhavy da2ee24d91 disk: part: refactor generic name creation for DOS and ISO
In both DOS and ISO partition tables the same code to create partition name
like "hda1" was repeated.

Code moved to into a new function part_set_generic_name() in part.c and optimized.
Added recognition of MMC and SD types, name is like "mmcsda1".

Signed-off-by: Petr Kulhavy <brain@jikos.cz>
Reviewed-by: Tom Rini <trini@konsulko.com>
Acked-by: Steve Rae <steve.rae@raedomain.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
2016-10-01 20:04:56 -04:00
Petr Kulhavy b6dd69a4d6 fastboot: add support for writing MBR
Add special target "mbr" (otherwise configurable via CONFIG_FASTBOOT_MBR_NAME)
to write MBR partition table.
Partitions are now searched using the generic function which finds any
partiiton by name. For MBR the partition names hda1, sda1, etc. are used.

Signed-off-by: Petr Kulhavy <brain@jikos.cz>
Reviewed-by: Tom Rini <trini@konsulko.com>
Acked-by: Steve Rae <steve.rae@raedomain.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
2016-10-01 20:04:51 -04:00
Petr Kulhavy 87b8530fe2 disk: part: implement generic function part_get_info_by_name()
So far partition search by name has been supported only on the EFI partition
table. This patch extends the search to all partition tables.

Rename part_get_info_efi_by_name() to part_get_info_by_name(), move it from
part_efi.c into part.c and make it a generic function which traverses all part
drivers and searches all partitions (in the order given by the linked list).

For this a new variable struct part_driver.max_entries is added, which limits
the number of partitions searched. For EFI this was GPT_ENTRY_NUMBERS.
Similarly the limit is defined for DOS, ISO, MAC and AMIGA partition tables.

Signed-off-by: Petr Kulhavy <brain@jikos.cz>
Reviewed-by: Tom Rini <trini@konsulko.com>
Acked-by: Steve Rae <steve.rae@raedomain.com>
2016-10-01 20:04:45 -04:00
Kever Yang c2fdd34569 cmd: gpt: fix the wrong size parse for the last partition
The calculation of "dev_desc->lba - 34  - 1 - offset" is not correct for
size '-', because both fist_usable_lba and last_usable_lba will remain
34 sectors.

We can simply use 0 for size '-' because the part_efi module will decode
the size and auto extend the size to maximum available size.

Signed-off-by: Kever Yang <kever.yang@rock-chips.com>
2016-08-05 20:55:16 -04:00
Simon Glass 5afb8d151f part_efi: Fix compiler warning on 32-bit sandbox
This fixes a mismatch between the %zu format and the type used on sandbox.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Tom Rini <trini@konsulko.com>
2016-07-25 12:05:54 -04:00
Alexander Graf 28f0014bde iso: Fix part info command
Partitions on the iso el torito partition table interpreter
only start from partition 1. So when printing out the tables,
let's also start counting at 1.

Signed-off-by: Alexander Graf <agraf@suse.de>
2016-07-22 14:46:19 -04:00
Patrick Delaunay a565386762 disk: part_efi: fix check of the max partition size
the last value acceptable value for offset is last_usable_lba + 1
and not last_usable_lba - 1

issue found with SDCARD partition commands on u-boot 2015.10
but this part of code don't change

1- create GPT partion on all the card
  > gpt write mmc 0 name=test,start=0,size=0
  > part list mmc 0

Partition Map for MMC device 0  --   Partition Type: EFI

Part      Start LBA          End LBA                       Name
            Attributes
            Type GUID
            Partition GUID
  1        0x00000022       0x003a9fde       "test"
            attrs:     0x0000000000000000
            type:     ebd0a0a2-b9e5-4433-87c0-68b6b72699c7
            type:     data
            guid:     b710eb04-45b9-e94a-8d0b-21458d596f54

=> Start = 0x22*512 = 0x4400
=> Size = (0x003a9fde-0x22+1) * 512  = 0x753F7A00

2- try to recreate the same partition with the next command
   (block size:512 bytes = 0x200)

  > gpt write mmc 0 name=test,start=0x4400,size=0x753F7A00
    Writing GPT: Partitions layout exceds disk size

  > gpt write mmc 0 name=test,start=0x4400,size=0x753F7800
    Writing GPT: Partitions layout exceds disk size

  > gpt write mmc 0 name=test,start=0x4400,size=0x753F7600
    Writing GPT: success!

Partition Map for MMC device 0  --   Partition Type: EFI

Part      Start LBA          End LBA                       Name
            Attributes
            Type GUID
            Partition GUID
  1        0x00000022       0x003a9fdc       "test"
            attrs:     0x0000000000000000
            type:     ebd0a0a2-b9e5-4433-87c0-68b6b72699c7
            type:     data
            guid:     36ec30ef-7ca4-cd48-97cd-ea9fb95185d0

the max LBA when the size is indicated (0x003a9fdc) is lower than
when u-boot compute the max allowed value with size=0 (0x003a9fde)

in the code :

     /* partition ending lba */
     if ((i == parts - 1) && (partitions[i].size == 0))
		/* extend the last partition to maximuim */
		gpt_e[i].ending_lba = gpt_h->last_usable_lba;
     else
		gpt_e[i].ending_lba = cpu_to_le64(offset - 1);

so offset = gpt_h->last_usable_lba + 1 is acceptable !
but the test (offset >= last_usable_lba) cause the error

END

Signed-off-by: Patrick Delaunay <patrick.delaunay73@gmail.com>disk: part_efi: fix check of the max partition size
the last value acceptable value for offset is (last_usable_lba + 1)
and not (last_usable_lba - 1)

issue found with SDCARD partition commands on u-boot 2015.10
but this part of code don't change

1- I create GPT partion on all the card (start and size undefined)

  > gpt write mmc 0 name=test,start=0,size=0
  > part list mmc 0

Partition Map for MMC device 0  --   Partition Type: EFI

Part      Start LBA          End LBA                       Name
            Attributes
            Type GUID
            Partition GUID
  1        0x00000022       0x003a9fde       "test"
            attrs:     0x0000000000000000
            type:     ebd0a0a2-b9e5-4433-87c0-68b6b72699c7
            type:     data
            guid:     b710eb04-45b9-e94a-8d0b-21458d596f54

=> Start = 0x22*512 = 0x4400
=> Size = (0x003a9fde-0x22+1) * 512  = 0x753F7A00

2- I try to recreate the same partition with the command gpt write
   and with start and size values (block size:512 bytes = 0x200)

  > gpt write mmc 0 name=test,start=0x4400,size=0x753F7A00
    Writing GPT: Partitions layout exceds disk size

  > gpt write mmc 0 name=test,start=0x4400,size=0x753F7800
    Writing GPT: Partitions layout exceds disk size

  > gpt write mmc 0 name=test,start=0x4400,size=0x753F7600
    Writing GPT: success!

  I check the partition created :

  > part list mmc 0

Partition Map for MMC device 0  --   Partition Type: EFI

Part      Start LBA          End LBA                       Name
            Attributes
            Type GUID
            Partition GUID
  1        0x00000022       0x003a9fdc       "test"
            attrs:     0x0000000000000000
            type:     ebd0a0a2-b9e5-4433-87c0-68b6b72699c7
            type:     data
            guid:     36ec30ef-7ca4-cd48-97cd-ea9fb95185d0

=> but the max LBA when the size is indicated (0x003a9fdc) is lower than
   when u-boot compute the max allowed value with size=0 (0x003a9fde)

3- in the code, just after my patch, line 446

     /* partition ending lba */
     if ((i == parts - 1) && (partitions[i].size == 0))
		/* extend the last partition to maximuim */
		gpt_e[i].ending_lba = gpt_h->last_usable_lba;
     else
		gpt_e[i].ending_lba = cpu_to_le64(offset - 1);

  so offset = gpt_h->last_usable_lba + 1 is acceptable !
  (it the value used when size is 0)

  but today the test (offset >= last_usable_lba) cause the error
  my patch only solve this issue

END

Signed-off-by: Patrick Delaunay <patrick.delaunay73@gmail.com>
2016-05-27 10:01:07 -04:00
Simon Glass 1598dfcb10 dm: blk: Use the correct error code for blk_get_device_by_str()
Return -EINVAL instead of -1 in this function, to provide a more meaningful
error.

Signed-off-by: Simon Glass <sjg@chromium.org>
2016-05-17 09:54:43 -06:00
Simon Glass 6dd9faf8f9 dm: part: Drop the block_drvr table
This is not needed since we can use the functions provided by the legacy
block device support.

Signed-off-by: Simon Glass <sjg@chromium.org>
2016-05-17 09:54:43 -06:00
Simon Glass 1fde473da7 dm: part: Use the legacy block driver for hardware partition support
Drop use of the table in part.c for this feature.

Signed-off-by: Simon Glass <sjg@chromium.org>
2016-05-17 09:54:43 -06:00
Simon Glass f1d86fd3b1 dm: sandbox: Drop the host_get_dev() function
This function is implemented by the legacy block functions now. Drop it.

Signed-off-by: Simon Glass <sjg@chromium.org>
2016-05-17 09:54:43 -06:00
Simon Glass f6d000edbe dm: systemace: Drop the get_dev() function
This function is implemented by the legacy block functions now. Drop it.

Signed-off-by: Simon Glass <sjg@chromium.org>
2016-05-17 09:54:43 -06:00
Simon Glass 4e7189d4d8 dm: sata: Drop the get_dev() function
This function is implemented by the legacy block functions now. Drop it.

We cannot yet make sata_dev_desc[] private to common/sata.c as it is used by
the SATA drivers. This will require the SATA interface to be reworked.

Signed-off-by: Simon Glass <sjg@chromium.org>
2016-05-17 09:54:43 -06:00
Simon Glass edd82ab354 dm: scsi: Drop the get_dev() function
This function is implemented by the legacy block functions now. Drop it.

Signed-off-by: Simon Glass <sjg@chromium.org>
2016-05-17 09:54:43 -06:00
Simon Glass 3c457f4d2e dm: mmc: Drop the get_dev() function
This function is implemented by the legacy block functions now. Drop it.

Signed-off-by: Simon Glass <sjg@chromium.org>
2016-05-17 09:54:43 -06:00
Simon Glass 74001a2570 dm: ide: Drop the get_dev() function
This function is implemented by the legacy block functions now. Drop it.

Signed-off-by: Simon Glass <sjg@chromium.org>
2016-05-17 09:54:43 -06:00
Simon Glass 57ebf67bad dm: usb: Drop the get_dev() function
This function is implemented by the legacy block functions now. Drop it.

Signed-off-by: Simon Glass <sjg@chromium.org>
2016-05-17 09:54:43 -06:00
Simon Glass a6331fa83c dm: disk: Use legacy block driver info for block device access
Instead of calling xx_get_dev() functions for each interface type, use the
new legacy block driver which can provide the device through its interface.

Signed-off-by: Simon Glass <sjg@chromium.org>
2016-05-17 09:54:43 -06:00
Simon Glass c649e3c91c dm: scsi: Rename CONFIG_CMD_SCSI to CONFIG_SCSI
This option currently enables both the command and the SCSI functionality.
Rename the existing option to CONFIG_SCSI since most of the code relates
to the feature.

Signed-off-by: Simon Glass <sjg@chromium.org>
2016-05-17 09:54:43 -06:00
Alexander Graf a2adb173ec iso: Allow 512 byte sector size
Real CD-ROMs are pretty obsolete these days. Usually people still keep
iso files around, but just put them on USB sticks or SD cards and expect
them to "just work".

To support this use case with El Torito images, add support for 512 byte
sector size to the iso parsing code.

Signed-off-by: Alexander Graf <agraf@suse.de>
2016-04-18 17:11:35 -04:00
Alexander Graf 2579c67478 iso: Start with partition 1
The generic partition code treats partition 0 as "whole disk". So
we should start with partition 1 as the first partition in the iso
partition table.

Signed-off-by: Alexander Graf <agraf@suse.de>
2016-04-18 17:11:34 -04:00
Alexander Graf ef9e6de540 iso: Make little endian and 64bit safe
The iso partition table implementation has a few endian and 64bit
problems. Clean it up a bit to become endian and bitness safe.

Signed-off-by: Alexander Graf <agraf@suse.de>
2016-04-18 17:11:33 -04:00
Nishanth Menon 2ae67aec5e dm: part: fix missing driver name in debug print
Fixes the following warning with PART_DEBUG enabled:
disk/part.c: In function ‘get_partition_info’:
disk/part.c:372:3: warning: format ‘%s’ expects a matching ‘char *’ argument [-Wformat]

Signed-off-by: Nishanth Menon <nm@ti.com>
2016-04-14 11:51:39 -06:00
Eric Nelson e40cf34a29 drivers: block: add block device cache
Add a block device cache to speed up repeated reads of block devices by
various filesystems.

This small amount of cache can dramatically speed up filesystem
operations by skipping repeated reads of common areas of a block
device (typically directory structures).

This has shown to have some benefit on FAT filesystem operations of
loading a kernel and RAM disk, but more dramatic benefits on ext4
filesystems when the kernel and/or RAM disk are spread across
multiple extent header structures as described in commit fc0fc50.

The cache is implemented through a minimal list (block_cache) maintained
in most-recently-used order and count of the current number of entries
(cache_count). It uses a maximum block count setting to prevent copies
of large block reads and an upper bound on the number of cached areas.

The maximum number of entries in the cache defaults to 32 and the maximum
number of blocks per cache entry has a default of 2, which has shown to
produce the best results on testing of ext4 and FAT filesystems.

The 'blkcache' command (enabled through CONFIG_CMD_BLOCK_CACHE) allows
changing these values and can be used to tune for a particular filesystem
layout.

Signed-off-by: Eric Nelson <eric@nelint.com>
2016-04-01 17:18:27 -04:00
Simon Glass 4708a07c7c part_efi: Drop NULL check in part_get_info_efi()
This cannot be NULL since part_get_info() calls this function and requires
it to be non-NULL.

Reported-by: Coverity (CID: 138497)

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Tom Rini <trini@konsulko.com>
2016-03-22 12:16:19 -04:00
Simon Glass 5f095f0c7a part_efi: Drop the NULL check on dev_desc in part_print_efi()
This cannot be NULL since part_print() calls this function and requires it
to be non-NULL.

Reported-by: Coverity (CID: 138498)
Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Tom Rini <trini@konsulko.com>
2016-03-22 12:16:19 -04:00
Simon Glass 0919228cf4 part_iso: Drop the customer unaligned access functions
One of these is causing a coverity warning. Drop these functions and use the
standard U-Boot ones instead.

Reported-by: Coverity (CID: 138499)

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Tom Rini <trini@konsulko.com>
2016-03-22 12:16:18 -04:00
Alexander Graf d96a98045a disk/part.c: Expose list of available block drivers
We have a pretty nice and generic interface to ask for a specific block
device. However, that one is still based around the magic notion that
we know the driver name.

In order to be able to write fully generic disk access code, expose the
currently internal list to other source files so that they can scan through
all available block drivers.

Signed-off-by: Alexander Graf <agraf@suse.de>
Reviewed-by: Simon Glass <sjg@chromium.org>
Tested-by: Simon Glass <sjg@chromium.org>
2016-03-15 15:19:22 -04:00
Simon Glass 084bf4c244 part: Rename test_part_xx() and print_part_xx()
Rename these functions so that part_ is at the start. This more clearly
identifies these functions as partition functions.

Signed-off-by: Simon Glass <sjg@chromium.org>
2016-03-14 15:34:50 -06:00
Simon Glass 2a981dc2c6 dm: block: Adjust device calls to go through helpers function
To ease conversion to driver model, add helper functions which deal with
calling each block device method. With driver model we can reimplement these
functions with the same arguments.

Use inline functions to avoid increasing code size on some boards.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Stephen Warren <swarren@nvidia.com>
2016-03-14 15:34:50 -06:00
Simon Glass bcce53d048 dm: block: Rename device number member dev to devnum
This is a device number, and we want to use 'dev' to mean a driver model
device. Rename the member.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Stephen Warren <swarren@nvidia.com>
2016-03-14 15:34:50 -06:00
Simon Glass 3e8bd46950 dm: part: Rename some partition functions
Rename three partition functions so that they start with part_. This makes
it clear what they relate to.

Signed-off-by: Simon Glass <sjg@chromium.org>
Tested-by: Stephen Warren <swarren@nvidia.com>
2016-03-14 15:34:50 -06:00
Simon Glass 96e5b03c8a dm: part: Convert partition API use to linker lists
We can use linker lists instead of explicitly declaring each function.
This makes the code shorter by avoiding switch() statements and lots of
header file declarations.

While this does clean up the code it introduces a few code issues with SPL.
SPL never needs to print partition information since this all happens from
commands. SPL mostly doesn't need to obtain information about a partition
either, except in a few cases. Add these cases so that the code will be
dropped from each partition driver when not needed. This avoids code bloat.

I think this is still a win, since it is not a bad thing to be explicit
about which features are used in SPL. But others may like to weigh in.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Tom Rini <trini@konsulko.com>
Tested-by: Stephen Warren <swarren@nvidia.com>
2016-03-14 15:34:50 -06:00
Simon Glass 95a6f9dfcb dm: part: Add a cast to avoid a compiler warning
In part_amiga.c the name is unsigned but bcpl_strcpy() requires a signed
pointer. Add a cast to fix the warning.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Stephen Warren <swarren@nvidia.com>
2016-03-14 15:34:50 -06:00
Simon Glass e35929e4a1 dm: blk: Rename get_device_and_partition()
Rename this function to blk_get_device_part_str(). This is a better name
because it makes it clear that the function returns a block device and
parses a string.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Stephen Warren <swarren@nvidia.com>
2016-03-14 15:34:50 -06:00
Simon Glass ebac37cfbf dm: blk: Rename get_device() to blk_get_device_by_str()
The current name is too generic. The function returns a block device based
on a provided string. Rename it to aid searching and make its purpose
clearer. Also add a few comments.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Stephen Warren <swarren@nvidia.com>
2016-03-14 15:34:50 -06:00
Simon Glass db1d9e78e6 dm: blk: Rename get_dev() to blk_get_dev()
The current name is too generic. Add a 'blk_' prefix to aid searching and
make its purpose clearer.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Stephen Warren <swarren@nvidia.com>
2016-03-14 15:34:50 -06:00
Simon Glass f8d6165d4b dm: part: Correct a sandbox build warning
Adjust the cast to avoid a warning when stdint.h is used.

Signed-off-by: Simon Glass <sjg@chromium.org>
Tested-by: Stephen Warren <swarren@nvidia.com>
2016-03-14 15:34:50 -06:00
Simon Glass 4101f68792 dm: Drop the block_dev_desc_t typedef
Use 'struct' instead of a typdef. Also since 'struct block_dev_desc' is long
and causes 80-column violations, rename it to struct blk_desc.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Stephen Warren <swarren@nvidia.com>
2016-03-14 15:34:50 -06:00
Erik Tideman 99e7fc8a26 mmc: emmc and hw partitions partition table id bugfix.
On bootup the emmc's hw partition is always set to 0 and the partition
table is read from it. When switching to another hw partition the
partition table's id is not updated but instead the old one from
hw partition 0 is used. If there is no partition table on hw partition 0
then the code will terminate and return error even if the desired hw
partition contains a perfectly fine partition table. This fix updates
the partition table struct to correspond to the specified hw partition
before testing if the partition table is valid or not.

Signed-off-by: Erik Tideman <erik.tideman@faltcom.se>
Reviewed-by: Tom Rini <trini@konsulko.com>
[trini: Squash the patch that corrected whitespace in the original into
this one, wrap with HAVE_BLOCK_DEVICE test]
Signed-off-by: Tom Rini <trini@konsulko.com>
2016-01-20 10:19:19 -05:00
Ben Whitten 192bc6948b Fix GCC format-security errors and convert sprintfs.
With format-security errors turned on, GCC picks up the use of sprintf with
a format parameter not being a string literal.

Simple uses of sprintf are also converted to use strcpy.

Signed-off-by: Ben Whitten <ben.whitten@gmail.com>
Acked-by: Wolfgang Denk <wd@denx.de>
Reviewed-by: Tom Rini <trini@konsulko.com>
2016-01-14 22:11:34 -05:00
Stephen Warren 7c4213f6a5 block: pass block dev not num to read/write/erase()
This will allow the implementation to make use of data in the block_dev
structure beyond the base device number. This will be useful so that eMMC
block devices can encompass the HW partition ID rather than treating this
out-of-band. Equally, the existence of the priv field is crying out for
this patch to exist.

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Reviewed-by: Tom Rini <trini@konsulko.com>
2016-01-13 21:05:18 -05:00
Stefan Monnier d29892ba85 part_dos.c: Don't wrap to negative after 2G sectors
In order to support large IDE disks we need to make certain types be
lbaint_t now.

Reviewed-by: Tom Rini <trini@konsulko.com>
Signed-off-by: Stefan Monnier <monnier@iro.umontreal.ca>
2016-01-13 16:33:20 -05:00
Patrick Delaunay cfdaf4caa2 part:efi: add bootable parameter in gpt command
The optional parameter bootable is added in gpt command to set the
partition attribute flag "Legacy BIOS bootable"

This flag is used in extlinux and so in with distro to select
the boot partition where is located the configuration file
(please check out doc/README.distro for details).

With this parameter, U-Boot can be used to create the boot partition
needed for device using distro.

example of use:

setenv partitions "name=u-boot,size=60MiB;name=boot,size=60Mib,bootable;\
                   name=rootfs,size=0"

> gpt write mmc 0 $partitions

> part list mmc 0

Partition Map for MMC device 0  --   Partition Type: EFI

Part	Start LBA	End LBA		Name
	Attributes
	Type GUID
	Partition GUID
  1	0x00000022	0x0001e021	"u-boot"
	attrs:	0x0000000000000000
	type:	ebd0a0a2-b9e5-4433-87c0-68b6b72699c7
	guid:	cceb0b18-39cb-d547-9db7-03b405fa77d4
  2	0x0001e022	0x0003c021	"boot"
	attrs:	0x0000000000000004
	type:	ebd0a0a2-b9e5-4433-87c0-68b6b72699c7
	guid:	d4981a2b-0478-544e-9607-7fd3c651068d
  3	0x0003c022	0x003a9fde	"rootfs"
	attrs:	0x0000000000000000
	type:	ebd0a0a2-b9e5-4433-87c0-68b6b72699c7
	guid:	6d6c9a36-e919-264d-a9ee-bd00379686c7

> part list mmc 0 -bootable devplist

> printenv devplist

devplist=2

Then the distro scripts will search extlinux in partition 2
and not in the first partition.

Signed-off-by: Patrick Delaunay <patrick.delaunay73@gmail.com>
2015-11-23 11:01:52 -05:00
Lukasz Majewski cef68bf904 gpt: part: Definition and declaration of GPT verification functions
This commit provides definition and declaration of GPT verification
functions - namely gpt_verify_headers() and gpt_verify_partitions().
The former is used to only check CRC32 of GPT's header and PTEs.
The latter examines each partition entry and compare attributes such as:
name, start offset and size with ones provided at '$partitions' env
variable.

Signed-off-by: Lukasz Majewski <l.majewski@majess.pl>
Reviewed-by: Tom Rini <trini@konsulko.com>
Reviewed-by: Przemyslaw Marczak <p.marczak@samsung.com>
2015-11-23 11:01:50 -05:00
Patrick Delaunay bcb41dcaef uuid: add selection by string for known partition type GUID
short strings can be used in type parameter of gpt command
to replace the guid string for the types known by u-boot

      partitions = name=boot,size=0x6bc00,type=data; \
                   name=root,size=0x7538ba00,type=linux;
      gpt write mmc 0 $partitions

and they are also used to display the type of partition
in "part list" command

  Partition Map for MMC device 0  --   Partition Type: EFI

  Part	Start LBA	End LBA		Name
	Attributes
	Type GUID
	Partition GUID
    1	0x00000022	0x0000037f	"boot"
	attrs:	0x0000000000000000
	type:	ebd0a0a2-b9e5-4433-87c0-68b6b72699c7
	type:	data
	guid:	d117f98e-6f2c-d04b-a5b2-331a19f91cb2
    2	0x00000380	0x003a9fdc	"root"
	attrs:	0x0000000000000000
	type:	0fc63daf-8483-4772-8e79-3d69d8477de4
	type:	linux
	guid:	25718777-d0ad-7443-9e60-02cb591c9737

Signed-off-by: Patrick Delaunay <patrick.delaunay73@gmail.com>
2015-11-12 15:58:58 -05:00
Patrick Delaunay 7561b258a1 gpt: add optional parameter type in gpt command
code under flag CONFIG_PARTITION_TYPE_GUID
add parameter "type" to select partition type guid

example of use with gpt command :

  partitions = uuid_disk=${uuid_gpt_disk}; \
      name=boot,size=0x6bc00,uuid=${uuid_gpt_boot}; \
      name=root,size=0x7538ba00,uuid=${uuid_gpt_root}, \
         type=0fc63daf-8483-4772-8e79-3d69d8477de4;

  gpt write mmc 0 $partitions

Signed-off-by: Patrick Delaunay <patrick.delaunay73@gmail.com>
2015-11-12 15:58:58 -05:00