summaryrefslogtreecommitdiff
path: root/cgpt
Commit message (Collapse)AuthorAgeFilesLines
* cgptlib: Minor edge case fixesJulius Werner2019-11-023-41/+18
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This patch fixes a sanitizer issue in cgpt where a GPT entries array may have been passed even though it was not loaded from disk (parsing an uninitialized buffer). The GPT library seems to have been written with the assumption that both headers and entries would always be loaded and it could recover even if only the primary header and the secondary entries were valid. In practice, this doesn't really work because the caller doesn't know how to read entries for an invalid header. Therefore, change the code so that entries are only assumed to be loaded for valid headers. Also fix some minor problems with loading GPTs by aligning sizes up (not down) to the next sector boundary and making sure we always allocate the maximum amount of space for entry arrays, even if the current header may not need that much (in case a repair wants to overwrite it). This practically reverts CL:276766 which becomes obsolete (and was really just a dirty hack to hide an underlying problem). BRANCH=none BUG=chromium:1017797 TEST=make runtests Change-Id: I86c601dc074261d53f013b98ae214efdc44f3563 Signed-off-by: Julius Werner <jwerner@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/vboot_reference/+/1885098 Reviewed-by: Mattias Nissler <mnissler@chromium.org> Reviewed-by: Randall Spangler <rspangler@chromium.org>
* vboot: format hex numbers with %#x instead of 0x%xJoel Kitching2019-10-232-2/+2
| | | | | | | | | | | | | | | | Also standardize on using hex for printing ASCII key values across vboot_ui.c and vboot_ui_menu.c. BUG=b:124141368 TEST=make clean && make runtests BRANCH=none Change-Id: Ib10288d95e29c248ebe807d99108aea75775b155 Signed-off-by: Joel Kitching <kitching@google.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/vboot_reference/+/1840191 Reviewed-by: Joel Kitching <kitching@chromium.org> Tested-by: Joel Kitching <kitching@chromium.org> Commit-Queue: Joel Kitching <kitching@chromium.org>
* cgpt: Change stateful partition type GUID to TYPE_LINUX_FSstabilize-12593.Bfactory-kukui-12587.BHung-Te Lin2019-10-091-1/+3
| | | | | | | | | | | | | | | | | | | | | The TYPE_BASIC_DATA (called TYPE_LINUX_DATA before) is used by both Windows and Linux systems, and has caused problems when dual-booting. Modern Linux systems have been changed to TYPE_LINUX_FS. In Chrome OS, we usually find the stateful partition by number (1) instead of searching by type, so it should be fine simply replacing default mapping in the cgpt tool. BUG=chromium:944389 TEST=sudo emerge vboot_reference; make runtests BRANCH=None Change-Id: If18ff5180cbae5cdea8104f36203cffcf34db934 Signed-off-by: Hung-Te Lin <hungte@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/vboot_reference/+/1535456 Reviewed-by: Furquan Shaikh <furquan@chromium.org> Reviewed-by: Matt Delco <delco@google.com> Reviewed-by: Mike Frysinger <vapier@chromium.org>
* vboot: fix up some more includesJoel Kitching2019-09-235-6/+5
| | | | | | | | | | | | | | | | Should have no extra line breaks in between local includes, and should be sorted alphabetically. BUG=b:124141368 TEST=make clean && make runtests BRANCH=none Change-Id: I83c25d30d7376712857314965a7d93f57190aa3f Signed-off-by: Joel Kitching <kitching@google.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/vboot_reference/+/1776281 Tested-by: Joel Kitching <kitching@chromium.org> Commit-Queue: Joel Kitching <kitching@chromium.org> Reviewed-by: Julius Werner <jwerner@chromium.org>
* cgpt: show: dump drive details in verbose/debug modeMike Frysinger2019-09-011-1/+18
| | | | | | | | | | | | | | | | The drive details are the only place where block sizes are tracked, so make sure we display them so the user knows the bytes-per-block. Might as well dump all the other drive details while we're here. BUG=None TEST=CQ passes BRANCH=None Change-Id: I2f2546feec2d58a295ce69c2bfe89a5ecf392f46 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/vboot_reference/+/1773966 Reviewed-by: Julius Werner <jwerner@chromium.org> Tested-by: Mike Frysinger <vapier@chromium.org> Commit-Queue: Mike Frysinger <vapier@chromium.org>
* cgpt: improve help textMike Frysinger2019-08-299-25/+28
| | | | | | | | | | | | | | | | | | | | Standardize on the term "blocks" rather than "sectors" as this matches our disk layout configuration files. For cgpt show, split the specific field options out from the -i option. The current text makes it seem like they're always required when using the -i option, and it's not super clear that they only matter when the -i flag is used. BUG=None TEST=CQ passes BRANCH=None Change-Id: Idfd939cfe9501da78e323bc1ce8c1fbf772fbaa9 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/vboot_reference/+/1773965 Reviewed-by: Julius Werner <jwerner@chromium.org> Commit-Queue: Mike Frysinger <vapier@chromium.org> Tested-by: Mike Frysinger <vapier@chromium.org>
* cgpt: show: add some sanity checking to -i flagsstabilize-12464.BMike Frysinger2019-08-291-0/+14
| | | | | | | | | | | | | | | | | | | | | | | | | | If people use -i0, the code runs as if the flag wasn't specified. Since valid partition numbers are [1,128], and the lower layers already reject values outside that range (except for 0), add an explicit check to the CLI for -i0. Trying to display specific fields w/out -i makes no sense, and the lower layers just ignore it. Add an explicit check for it so users don't try to do `cgpt show /dev/sda -s` and wonder why the output is unchanged. Passing more than one specific field selector like -s -b doesn't work -- whatever flag was specified last wins. This isn't that obvious to users, so throw an explicit error when it happens. BUG=None TEST=CQ passes BRANCH=None Change-Id: I7c98822b79b389824b544b128ede93458b678342 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/vboot_reference/+/1773964 Reviewed-by: Julius Werner <jwerner@chromium.org> Commit-Queue: Mike Frysinger <vapier@chromium.org> Tested-by: Mike Frysinger <vapier@chromium.org>
* vboot: fix up some headers, includes, comments, spacingJoel Kitching2019-08-2821-68/+87
| | | | | | | | | | | | | BUG=b:124141368 TEST=make clean && make runtests BRANCH=none Change-Id: Id97f544da845f7070555e5e8cc6e782b2d45c300 Signed-off-by: Joel Kitching <kitching@google.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/vboot_reference/+/1758151 Tested-by: Joel Kitching <kitching@chromium.org> Reviewed-by: Joel Kitching <kitching@chromium.org> Commit-Queue: Joel Kitching <kitching@chromium.org>
* Makefile: Enable linker garbage collectionJulius Werner2019-08-161-1/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | This patch enables -ffunction-sections, -fdata-sections and -Wl,--gc-sections for host builds. These flags already get passed by firmware builds anyway, so having host builds match that behavior should be a good idea in general. They may also occasionally help save a bit of code size (though not much since vboot is a library, but I still get about half a KB out of futility), and they will prevent clang from omitting relocations for function calls inside the same file, which means we don't have to splatter test_mockable all over our codebase anymore. (We still need it for vb2_get_gbb() since that is so small that both GCC and clang want to inline it, even if they are outputting a discrete copy anyway.) (Also add a comment about why GenerateGuid() has nothing do to with this even though it is also a weak function, and why it is like that.) BRANCH=None BUG=chromium:991812 TEST=make runtests with both GCC and clang Change-Id: Iede9d29e20b99b75a0c86bc7ecb907d2a0e5e3a1 Signed-off-by: Julius Werner <jwerner@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1754969 Legacy-Commit-Queue: Commit Bot <commit-bot@chromium.org> Reviewed-by: Mike Frysinger <vapier@chromium.org>
* cgpt: Fix format specifiers for uint64_tJacob Garber2019-08-062-3/+3
| | | | | | | | | | | | | | | These variables are all uint64_t, and so we need to use PRIu64 to ensure they are printed with the correct format specifier. BUG=none TEST=make clean && make runtests BRANCH=none Change-Id: Idb8fee0ef525d224670a9d2b3a7915be1b19fd21 Signed-off-by: Jacob Garber <jgarber1@ualberta.ca> Found-by: Coverity CID 199873, 199878, 199889 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/vboot_reference/+/1737200 Reviewed-by: Julius Werner <jwerner@chromium.org>
* cgpt: Fix format specifier for size_tJacob Garber2019-08-061-1/+1
| | | | | | | | | | | | | | Use %zu, which is the format specifier for size_t. BUG=none TEST=make clean && make runtests BRANCH=none Change-Id: I3317c2f6a7b9d95c22a43ae3d786c7d7380342ad Signed-off-by: Jacob Garber <jgarber1@ualberta.ca> Found-by: Coverity CID 199882 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/vboot_reference/+/1737706 Reviewed-by: Julius Werner <jwerner@chromium.org>
* Makefile: Enable more warnings for host utilities / testsJulius Werner2019-05-145-23/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | This patch adds a bunch of more warnings that are already enabled in coreboot and thus already enabled for firmware builds anyway (because coreboot just passes its CFLAGS through). Enabling it in the vboot Makefile means they also apply to host utilities and tests, which sounds desirable for consistency. Fix enough of the cruft and bad coding practices that accumulated over the years of not having warnings enabled to get it to build again (this includes making functions static, removing dead code, cleaning up prototypes, etc.). Also remove -fno-strict-aliasing from the x86 firmware build options, because it's not clear why it's there (coreboot isn't doing this, so presumably it's not needed). BRANCH=None BUG=None TEST=make runtests Change-Id: Ie4a42083c4770a4eca133b22725be9ba85b24184 Signed-off-by: Julius Werner <jwerner@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1598721 Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
* cgpt: create: Don't modify existing IGNOREME headersRyan Case2019-04-241-0/+13
| | | | | | | | | | | | | | | | | Respect any existing IGNOREME signatures and do not attempt to make any modifications until a user has explicitly removed this flag via cgpt legacy or other method. BRANCH=None BUG=chromium:948742 TEST=chromeos-install on veyron_minnie with 4.19 kernel Change-Id: I110a95ee0c136ebbe2274139deebcaacde712e80 Signed-off-by: Ryan Case <ryandcase@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1572440 Commit-Ready: Ryan Case <ryandcase@google.com> Tested-by: Ryan Case <ryandcase@google.com> Reviewed-by: Julius Werner <jwerner@chromium.org>
* Fix memory leaks in cgptFletcher Woodruff2019-03-134-19/+19
| | | | | | | | | | | | | | | | | | | DriveOpen mallocs a couple of buffers, but DriveClose only freed them if a particular flag was passed causing GptSave to be called. Move the free calls out of GptSave so that the buffers are always freed, and add DriveClose calls to a couple of cgpt functions that are missing them. BUG=chromium:940543 TEST=precq passes, manual testing with cgpt/valgrind shows that memory leaks for cgpt find, show are fixed. BRANCH=none Change-Id: I58aeddfa6b8b4715ba4f8e064e95a660371a01c9 Reviewed-on: https://chromium-review.googlesource.com/1516413 Commit-Ready: Fletcher Woodruff <fletcherw@chromium.org> Tested-by: Fletcher Woodruff <fletcherw@chromium.org> Reviewed-by: Julius Werner <jwerner@chromium.org> Reviewed-by: Mike Frysinger <vapier@chromium.org>
* vboot_reference: add const to char* params in cgptFletcher Woodruff2019-02-122-5/+5
| | | | | | | | | | | | | | | | | | | | cgpt's C/C++ bindings use non-const char* parameters leading to compiler errors if a user attempts to pass a const char* parameter rather than creating an unnecessary mutable copy. Since the code doesn't need to modify the parameters, change them to const char* to make the library easier to use. BUG=none TEST=builds and test cgpt cli tool on-device. CQ-DEPEND=CL:1460081 BRANCH=none Change-Id: I6552db159e3dc4d9d07bb889a3f1e4e890b33cb0 Reviewed-on: https://chromium-review.googlesource.com/1459848 Commit-Ready: Fletcher Woodruff <fletcherw@chromium.org> Tested-by: Fletcher Woodruff <fletcherw@chromium.org> Reviewed-by: Julius Werner <jwerner@chromium.org>
* cgpt: add -D support to CgptEditstabilize-11686.BMatt Delco2019-01-302-2/+11
| | | | | | | | | | | | | | | | | | | | | | | | | The lack of -D support in CgptEdit introduced a test failure. This change adds support for -D. BRANCH=none BUG=chromium:605348 TEST=Verified that prior to this change the tests failed: cros_workon --host start vboot_reference sudo FEATURES=test emerge vboot_reference The tests fail in a different area prior to CgptEdit, so I applied the following temporary change to Makefile to see the relevant failure: ifeq (${MINIMAL},) # Bitmap utility isn't compiled for minimal variant - test_targets:: runbmptests runfutiltests + test_targets:: runbmptests # runfutiltests # Scripts don't work under qemu testing With this change the tests pass. Change-Id: Ia2127a3537c72e4ea6daf59c5c33b8701a89b0f6 Signed-off-by: Matt Delco <delco@google.com> Reviewed-on: https://chromium-review.googlesource.com/1436496 Tested-by: Matt Delco <delco@chromium.org> Reviewed-by: Julius Werner <jwerner@chromium.org>
* cgpt: enable calling CgptEditMatt Delco2018-12-061-1/+3
| | | | | | | | | | | | | | | | | | | | | This change allows CgptEdit to be called via the API. Prior to this change link fails in an app that uses CgptEdit due to undefined reference. The underlying implementation wasn't checking set_unique so I've fixed that as well. BRANCH=none BUG=None TEST=Added CgptEdit(0) call to extern.c and verified that build failed. Added cgpt_edit.c to Makefile and confirmed that build is now successful. Successfully ran unit tests on both vboot_reference and the app I'm working on that calls CgptEdit (which also has a unit test for setting the drive ID). Change-Id: Ie0a46ff96406eb83d0564d3f1eac978e0565ed76 Signed-off-by: Matt Delco <delco@google.com> Reviewed-on: https://chromium-review.googlesource.com/1361948 Reviewed-by: Hung-Te Lin <hungte@chromium.org> Reviewed-by: Julius Werner <jwerner@chromium.org>
* cgpt: add edit commandstabilize-nocturne-10986.Bstabilize-11021.84.Bstabilize-11020.Bstabilize-11005.Bstabilize-10985.Brelease-R70-11021.Bfirmware-servo-11011.Bfirmware-nocturne-10984.Bfactory-nocturne-10984.BMatt Delco2018-08-154-0/+127
| | | | | | | | | | | | | | | | This change adds a command to cgpt to change the GUID of the drive. BRANCH=none BUG=None TEST=Compiled and ran utility to verify that GUID changes. Also verified that the new and existing tests completed successfully. Change-Id: Ia8a815447509626312e2b06c6f293901290c73c3 Signed-off-by: Matt Delco <delco@google.com> Reviewed-on: https://chromium-review.googlesource.com/1171834 Reviewed-by: Julius Werner <jwerner@chromium.org>
* cgpt: show verbose details when primary ignoredMatt Delco2018-08-141-4/+5
| | | | | | | | | | | | | | | | | | A later change I authored has the tests check the GUID of the drive. When the primary table is ignored the GUID from the secondary wasn't being displayed either. This change has the details of the secondary table get displayed when the primary table is ignored. BRANCH=none BUG=None TEST=Compiled. The change was runtime tested as part of a larger change though I didn't unit test this particular change after it was split out into a separate commit. Change-Id: I300511cf65c67f4888e08ab49cd72c7acf234507 Signed-off-by: Matt Delco <delco@google.com> Reviewed-on: https://chromium-review.googlesource.com/1173410 Reviewed-by: Julius Werner <jwerner@chromium.org>
* cgpt: Remove hard coded 512 block size.Sam Hurst2018-04-124-20/+26
| | | | | | | | | | | | | | | | | | | | Remove 512 sector block size restriction so that UFS, with sector block size 4096 or greater, can be used. The sector block size is queried from the kernel with ioctl(BLKSSZGET) or queried from depthcharge with VbExDiskGetInfo(). BUG=b:77540192 BRANCH=none TEST=manual make runtests passed. Tested firmware on Kevin and boot to kernel from disk. Executed cgpt show /dev/mmcblk0 on eve device and verified output was correct. Should be tested on device with sector block size greater than 512. Change-Id: I8165c8ee4da68180eecc8d12b3fb501cc5c60a5d Reviewed-on: https://chromium-review.googlesource.com/1007498 Commit-Ready: Sam Hurst <shurst@google.com> Tested-by: Sam Hurst <shurst@google.com> Reviewed-by: Julius Werner <jwerner@chromium.org>
* cgpt: add support for managing GPT platform required partition bitBen Chan2018-02-066-4/+39
| | | | | | | | | | | | | | | | Bit 0 in the GPT partition attributes is defined to indicate whether a partition is required by the platform. This CL adds the support for managing this bit to cgpt. BUG=b:70807006 BRANCH=None TEST=Run unit tests. Change-Id: Iaf87c828438b3df6730de502ae420fcf4c61277b Reviewed-on: https://chromium-review.googlesource.com/902196 Commit-Ready: Ben Chan <benchan@chromium.org> Tested-by: Ben Chan <benchan@chromium.org> Reviewed-by: Mike Frysinger <vapier@chromium.org>
* cgpt: prioritize: Make sure all headers/entries are validJeffy Chen2017-08-092-4/+7
| | | | | | | | | | | | | | | | | The prioritize cmd expected primary gpt header and entries are valid. Add a validity check to guarantee that. BUG=b:35585016 TEST=Check on bob, the secondary gpt still valid after these commands: dd if=/dev/zero of=/dev/mmcblk0 bs=512 count=64 cgpt prioritize /dev/mmcblk0 Change-Id: I853e25211a46fa3ce93cef1e5169b93b0a6430a9 Signed-off-by: Jeffy Chen <jeffy.chen@rock-chips.com> Reviewed-on: https://chromium-review.googlesource.com/604814 Reviewed-by: Randall Spangler <rspangler@chromium.org> Reviewed-by: Julius Werner <jwerner@chromium.org>
* cgpt: show: Print partition size with 64-bit formatErdi Chen2017-06-231-23/+25
| | | | | | | | | | | | | | | Partition size on 4TB drive can overflow 32-bit integers. Running "cgpt show /dev/sda" prints negative number for the state partition (sda1). BRANCH=none BUG=none TEST=Run "cgpt show /dev/sda" with 4TB drive. Change-Id: I56f3b43594028695745de8c5a1626d940a3b4c5b Reviewed-on: https://chromium-review.googlesource.com/546879 Commit-Ready: Erdi Chen <erdi@google.com> Tested-by: Erdi Chen <erdi@google.com> Reviewed-by: Mike Frysinger <vapier@chromium.org>
* cgpt: find: filter out more devices before touching themJeffy Chen2017-02-241-4/+15
| | | | | | | | | | | | | | | | | | A partition's name would always start with the disk name. And in /proc/partitions, the partitions are always listed right after the disk. Let's filter out devices which are not followed by partitions when go through the /proc/partitions. BUG=chrome-os-partner:62955 TEST=run "cgpt find -t kernel" on kevin, no more this warning: blk_update_request: I/O error, dev mmcblk0rpmb Change-Id: If200a2476d26b1beaf644838d47ea2e60552855e Signed-off-by: Jeffy Chen <jeffy.chen@rock-chips.com> Reviewed-on: https://chromium-review.googlesource.com/444492 Reviewed-by: Julius Werner <jwerner@chromium.org>
* vboot: use malloc and free directlyRandall Spangler2016-11-061-2/+0
| | | | | | | | | | | | | | | | Originally, vboot1 code used VbExMalloc() and VbExFree() since it needed to talk to EFI firmware that didn't have standard malloc() and free(). Now, coreboot and depthcharge implement them as wrappers around those standard calls. vboot2 code already calls them directly, so let vboot1 code do that too. BUG=chromium:611535 BRANCH=none TEST=make runtests; emerge-kevin coreboot depthcharge Change-Id: I49ad0e32e38d278dc3589bfaf494bcf0e4b0a4bd Signed-off-by: Randall Spangler <rspangler@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/400905
* vboot: Remove the remainder of vb1 cryptolibRandall Spangler2016-11-061-1/+0
| | | | | | | | | | | | | | | At this point, all that's left are a few constants in the cryptolib header files, and they're only used by host-side code. So move them to a host-side header file and get rid of cryptolib. BUG=chromium:611535 BRANCH=none TEST=make runtests; emerge-kevin coreboot depthcharge Change-Id: I2235f0e84e13fef313afe54e749b73744b157884 Signed-off-by: Randall Spangler <rspangler@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/400903 Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
* cgpt: Add support for NVMeGwendal Grignou2016-10-211-1/+9
| | | | | | | | | | | | | | | | | | | | find: A p is added betwen device name and partition whenever the last character of a device is a number, as written in disk_name() in kernel block/partition-generic.c file. debug_vboot: Add regex for nvme device. BUG=chromium:655192 BRANCH=none TEST=Check that when a machine boots from NVMe, chromeos-setgoodkernel set "successful" field properly. Run " dev_debug_vboot --cleanup", check the NVMe device kernel partitions are verified. Change-Id: I6a9342c95500fa582f51f06e48c1ff90684c2a27 Signed-off-by: Gwendal Grignou <gwendal@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/398338 Reviewed-by: Mike Frysinger <vapier@chromium.org>
* Fix more coverity warnings in utilitiesRandall Spangler2016-09-153-8/+25
| | | | | | | | | | | | | | Assorted minor code issues, which we should fix so any new errors stand out more. BUG=chromium:643769 BRANCH=none TEST=make runtests Change-Id: I8fcf0c51e33d5dc49f650f4069f1579091cf188d Signed-off-by: Randall Spangler <rspangler@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/383713 Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
* cgpt: add support for managing the legacy boot gpt bitstabilize-kevin-8785.94.BMike Frysinger2016-09-086-9/+65
| | | | | | | | | | | | | | | | | | | | | | | Bit 2 in the GPT partition attributes has been allocated as the legacy bios boot (equivalent to the "active" or "boot" flag in MBR). If we try to boot images on newer x86 systems, syslinux dies because it can't find any GPT partition marked bootable. Update the various parts of cgpt add & show to manage this bit. Now we can run: cgpt add -i 12 -B 1 chromiumos_image.bin And the EFI partition will be marked bootable. BUG=chromium:644845 TEST=vboot_reference unittests pass TEST=booted an amd64-generic disk image via USB on a generic laptop BRANCH=None Change-Id: I78e17b8df5b0c61e9e2d8a3c703e6d5ad230fe92 Reviewed-on: https://chromium-review.googlesource.com/382411 Commit-Ready: Mike Frysinger <vapier@chromium.org> Tested-by: Mike Frysinger <vapier@chromium.org> Reviewed-by: Randall Spangler <rspangler@chromium.org>
* cgpt: fix -A documentation to match realityMike Frysinger2016-09-082-2/+2
| | | | | | | | | | | | | | | | The documentation claims the -A option shows the raw 64-bit attributes field when in reality it only shows the high reserved 16-bits. Change the docs to match the code. BUG=chromium:644845 TEST=vboot_reference unittests pass BRANCH=None Change-Id: If163896ddbca0dc27ac8205db313031e73a68fd7 Reviewed-on: https://chromium-review.googlesource.com/382431 Commit-Ready: Mike Frysinger <vapier@chromium.org> Tested-by: Mike Frysinger <vapier@chromium.org> Reviewed-by: Bill Richardson <wfrichar@chromium.org>
* cgpt: unify cli int parsing error checkingMike Frysinger2016-09-0810-121/+43
| | | | | | | | | | | | | | | | Most of the cmd funcs had the same logic copied & pasted multiple times over. Unify them into a common header. BUG=chromium:644845 TEST=precq passes TEST=passing invalid args to some funcs is caught BRANCH=None Change-Id: Ib7212bcbb17da1135b2508a52910aac37ee8e6cd Reviewed-on: https://chromium-review.googlesource.com/382691 Commit-Ready: Mike Frysinger <vapier@chromium.org> Tested-by: Mike Frysinger <vapier@chromium.org> Reviewed-by: Randall Spangler <rspangler@chromium.org>
* cgpt: Fix coverity warningsRandall Spangler2016-09-062-1/+6
| | | | | | | | | | | | | | Assorted minor code issues, which we should fix so any new errors stand out more. BUG=chromium:643769 BRANCH=none TEST=make runtests Change-Id: I9e7ce2ba226993fc53d1745c98381cb7cfcb7712 Signed-off-by: Randall Spangler <rspangler@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/380448 Reviewed-by: Stefan Reinauer <reinauer@chromium.org>
* vboot: Convert vboot1 SHA calls to use vboot2Randall Spangler2016-07-221-8/+15
| | | | | | | | | | | | | | | | | | This change replaces all calls to the old vboot1 SHA library with their vboot2 equivalents. This is the first in a long series of changes to move the core vboot kernel verification into vb2, and the control/display loop out to depthcharge. BUG=chromium:611535 BRANCH=none TEST=make runtests; build samus firmware and boot it Change-Id: I31986eb766176c0e39a192c5ce15730471c3cf94 Signed-off-by: Randall Spangler <rspangler@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/344342 Tested-by: Daisuke Nojiri <dnojiri@chromium.org> Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
* cgpt: Add cgpt legacy parameter to set primary GPT signature to IGNOREMEstabilize-8249.BJulius Werner2016-04-252-4/+34
| | | | | | | | | | | | | | | | | Now that we have support for the IGNOREME signature in cgpt, we need a way to set it on an existing disk. The easiest option is to shoehorn this into the cgpt legacy command, because that's already made to modify GPT header signatures (really, it would be nice to rename it to cgpt signature or something, but let's not break existing uses for now). BRANCH=None BUG=chrome-os-partner:52595 TEST=unit tests Change-Id: If2835fec28a9c39373abd050e2e057f73e5ec700 Signed-off-by: Julius Werner <jwerner@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/340073 Reviewed-by: Nam Nguyen <namnguyen@google.com>
* cgptlib: Add support for IGNOREME GPT signatureJulius Werner2016-04-252-89/+112
| | | | | | | | | | | | | | | | | | This patch makes cgpt aware of a special "IGNOREME" GPT header signature string that may appear in either the primary or the secondary GPT and cause cgpt (and other cgptlib clients) to completely ignore that GPT. It will continue to function correctly for all other purposes (using the data from the non-ignored GPT), but never write any data back to the ignored GPT. BRANCH=None BUG=chrome-os-partner:52595 TEST=unit tests Change-Id: I7e53542385ae9d8d24dc25b75e91f4ff4917f66f Signed-off-by: Julius Werner <jwerner@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/340072 Reviewed-by: Nam Nguyen <namnguyen@google.com>
* cgpt: Fully write out primary GPT before starting to write secondaryJulius Werner2016-04-251-16/+26
| | | | | | | | | | | | | | | | | | | | | | The point of having two GPTs is to always have a known good one if one of them gets corrupted. One of the most obvious ways that could happen is if the write stopped half-way through (e.g. due to a crash or random power loss). Unfortunately, the way we currently save modified GPTs can leave both copies invalid if we stop writing at just the wrong time. Since a GPT header contains a checksum over the GPT entries, we need to write both the header and entries for one GPT (and make sure they're synced to disk) before we start writing the other. BRANCH=None BUG=chrome-os-partner:52595 TEST=None Change-Id: I2d4b56bcfba9a94395af5896f274ebade9e39081 Signed-off-by: Julius Werner <jwerner@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/340071 Reviewed-by: Nam Nguyen <namnguyen@google.com>
* include sys/sysmacros.h for major()Mike Frysinger2016-04-201-0/+1
| | | | | | | | | | | | | | | | The major() func is defined in the sys/sysmacros.h header, so include it explicitly for the prototype. Upstream C libs are moving away from having sys/types.h include it all the time implicitly. BUG=None TEST=precq passes BRANCH=None Change-Id: I56b84138f08ded2376193403f9c9db22c5f24f71 Reviewed-on: https://chromium-review.googlesource.com/339680 Commit-Ready: Mike Frysinger <vapier@chromium.org> Tested-by: Mike Frysinger <vapier@chromium.org> Reviewed-by: Bill Richardson <wfrichar@google.com>
* cgpt repair: fix segfault which occurs when one of the headers is badstabilize-7202.Bstabilize-7199.Bstabilize-7173.BAndrey Ulanov2015-06-131-0/+18
| | | | | | | | | | | | | | | | | | | | | | | | | | When one of GPT headers is invalid the corresponding partition table is not loaded and corresponding pointers in GptData are NULL. GptRepair will try to memcpy one entries table to another which results in SIGSEGV. This change fixes it by freeing and then reallocating bad copy of partition table. This potentially fixes problems which would occur if two tables have different size. Change that initially introduced this problem by not always allocating secondary_entries: https://chromium-review.googlesource.com/223800 TEST="cgpt repair" works where it previously didn't TEST=make runtests BUG=brillo:1203 BRANCH=none Change-Id: Ibb2fcf33faa5ba157b0865d04c90ee3f26eee113 Reviewed-on: https://chromium-review.googlesource.com/276766 Reviewed-by: Randall Spangler <rspangler@chromium.org> Commit-Queue: Andrey Ulanov <andreyu@google.com> Tested-by: Andrey Ulanov <andreyu@google.com>
* cgpt_wrapper: Print error if execv() fails.Alex Deymo2015-02-231-1/+5
| | | | | | | | | | | | | | | | | | This shows an error message when cgpt.bin failed to run, with its reason. Without this patch, "cgpt" would just fail and return -1 in that case making it difficult to know the reason of the failure. BUG=chrome-os-partner:36061 TEST=replaced this binary in storm recovery initramfs 6699.0.0 and it shows the error message if cgpt.bin is not installed. BRANCH=None Change-Id: I3ffaba5a63c491ac7d5b16086d5ae21005f40317 Reviewed-on: https://chromium-review.googlesource.com/251868 Reviewed-by: Alex Deymo <deymo@chromium.org> Commit-Queue: Alex Deymo <deymo@chromium.org> Trybot-Ready: Alex Deymo <deymo@chromium.org> Tested-by: Alex Deymo <deymo@chromium.org>
* Changes to compile signing tools on darwinDavid Riley2015-02-113-1/+20
| | | | | | | | | | | | | | | | | | | The following works from a Mac with these changes: make Q= ARCH=arm HAVE_MACOS=1 `pwd`/build/futility/futility Only vbutil_keyblock and vbutil_kernel have been exercised. BUG=none TEST='make Q= ARCH=arm HAVE_MACOS=1 `pwd`/build/futility/futility' BRANCH=none Signed-off-by: David Riley <davidriley@chromium.org> Change-Id: Ie69cfee0c650d4ff96be6322083a2fea1543ee39 Reviewed-on: https://chromium-review.googlesource.com/246773 Reviewed-by: Bill Richardson <wfrichar@chromium.org> Tested-by: David Riley <davidriley@chromium.org> Commit-Queue: David Riley <davidriley@chromium.org>
* cgpt_wrapper: Fix non-zero return code when okayNam T. Nguyen2015-01-271-3/+4
| | | | | | | | | | | | | | | | I forgot to reset "ret" to zero in the case the two hashes come out the same. This CL fixes that silly logic bug. BUG=None BRANCH=None TEST=`cgpt show /dev/mtd0` should exit with status 0 Change-Id: I1c64ea215c861c8afb44e235d090c72a5d006d55 Reviewed-on: https://chromium-review.googlesource.com/243325 Reviewed-by: Bill Richardson <wfrichar@chromium.org> Commit-Queue: Nam Nguyen <namnguyen@chromium.org> Trybot-Ready: Nam Nguyen <namnguyen@chromium.org> Tested-by: Nam Nguyen <namnguyen@chromium.org>
* cgpt: Close stdout on exec'ing flashromNam T. Nguyen2015-01-221-2/+10
| | | | | | | | | | | | | | | | flashrom spills out "Reading flash... SUCCESS" and so on to stdout. This affects scripts calling to "cgpt". So this CL sets stdout to CLOEXEC before exec'ing flashrom. It still leaves stderr and stdin unclosed. BUG=None BRANCH=None TEST=cgpt show /dev/mtd0 2>/dev/null will not show any unnecessary text Change-Id: Ide1414c56f63ffe8bc2385a797f166476dacd732 Reviewed-on: https://chromium-review.googlesource.com/242295 Reviewed-by: Bill Richardson <wfrichar@chromium.org> Tested-by: Nam Nguyen <namnguyen@chromium.org> Commit-Queue: Nam Nguyen <namnguyen@google.com>
* cgpt_wrapper: Resolve the path to "cgpt" commandNam T. Nguyen2015-01-221-0/+17
| | | | | | | | | | | | | | | | Because we do not use "execvp", "cgpt.bin" is not resolved to the same directory as "cgpt". So we need to resolve the original command to its absolute path first, then append ".bin" to it. BUG=None BRANCH=None TEST="cgpt" no longer fails. Change-Id: Id22c2d97616867125e9744c00bbf527f8a176df4 Reviewed-on: https://chromium-review.googlesource.com/242294 Reviewed-by: Bill Richardson <wfrichar@chromium.org> Tested-by: Nam Nguyen <namnguyen@chromium.org> Commit-Queue: Nam Nguyen <namnguyen@google.com>
* cgpt_wrapper: Only write rw_gpt back if changedNam T. Nguyen2015-01-221-2/+12
| | | | | | | | | | | | | | | | We always wrote back the rw_gpt file to NOR flash. This operation is too slow. This CL compares if the original file has been changed by cgpt.bin before writing the file back to NOR. BUG=None BRANCH=None TEST=/usr/bin/cgpt show /dev/mtd0 now does not write back to NOR Change-Id: I4c63f0d4da72f3674e06a896fa329f5fc964a885 Reviewed-on: https://chromium-review.googlesource.com/242293 Reviewed-by: Bill Richardson <wfrichar@chromium.org> Tested-by: Nam Nguyen <namnguyen@chromium.org> Commit-Queue: Nam Nguyen <namnguyen@google.com>
* cgpt: Enable fast-verify when writing back to NORNam T. Nguyen2015-01-221-2/+2
| | | | | | | | | | | | | | | flashrom has been fixed, we could enable this flag for better performance. BUG=None BRANCH=None TEST=cgpt show /dev/mtd0 works much faster now. Change-Id: I7a6f5b8649b4293d9b4b4878ae8e599ea1c35289 Reviewed-on: https://chromium-review.googlesource.com/242292 Reviewed-by: Bill Richardson <wfrichar@chromium.org> Tested-by: Nam Nguyen <namnguyen@chromium.org> Commit-Queue: Nam Nguyen <namnguyen@google.com>
* cgpt: Properly show ChromeOS-scheme MTD partitionsNam T. Nguyen2015-01-221-4/+25
| | | | | | | | | | | | | | | | | | | When working on NAND, we do not actually work with one device name. We work on a temporary file instead. Moreover, depending on the type of the partition, we need to show different devices. BUG=None BRANCH=None TEST=All commands must be run on storm_nand TEST=/usr/bin/cgpt.bin find -t kernel should print out /dev/mtd2 TEST=/usr/bin/cgpt.bin find -t rootfs should print out /dev/ubiblock5_0 TEST=/usr/bin/cgpt.bin find -t data should print out /dev/ubi1_0 Change-Id: Ia36777ffa6a9cfc7c8ec4b128e49ece140428238 Reviewed-on: https://chromium-review.googlesource.com/242291 Reviewed-by: Bill Richardson <wfrichar@chromium.org> Tested-by: Nam Nguyen <namnguyen@chromium.org> Commit-Queue: Nam Nguyen <namnguyen@google.com>
* Add cgpt_wrapper binary to transparently support NANDNam T. Nguyen2015-01-174-4/+476
| | | | | | | | | | | | | | | | | | | | | | | | | | | This CL adds a "cgpt_wrapper" binary that will forward to "cgpt" binary as needed to transparently support NAND. The idea is that if we are working with an MTD device, this binary will exec out to "flashrom" to read in the GPT section, then exec out to the actual "cgpt" binary to work on that file, and finally write it back with "flashrom". This CL introduces a make target "install_mtd" to install this wrapper. The corresponding ebuild should use this make target when "mtd" USE flag is on. BUG=chromium:442518 BRANCH=none CQ-DEPEND=CL:239573 TEST=unittest and some trial runs with mtdram TEST=test on a real device with NOR flash and NAND Change-Id: I54534afa9a970ec858f313f698c0eb210c827477 Reviewed-on: https://chromium-review.googlesource.com/239580 Tested-by: Nam Nguyen <namnguyen@chromium.org> Reviewed-by: Daniel Ehrenberg <dehrenberg@chromium.org> Reviewed-by: Bill Richardson <wfrichar@chromium.org> Commit-Queue: Nam Nguyen <namnguyen@chromium.org>
* nand: vboot support for small GPTsDan Ehrenberg2015-01-051-1/+1
| | | | | | | | | | | | | | | | | | | | | | | This patch makes some small modifications to cgpt and vboot to root out the last vestigates of a fixed 128-entry GPT: - Get rid of the TOTAL_ENTRIES_SIZE constant and all users. - Reduce MAX_NUMBER_OF_ENTRIES to 128 (which is what the GPT spec specifies) so that this can be used for things like memory allocations without additional overhead. - Base the amount of GPT read/written on the number of entries specified in the GPT header on disk/flash. BUG=chromium:433433 TEST=make runalltests TEST=Modified fmap to make an 8k RW_GPT, wrote a GPT with cgpt, then rebooted and found that the GPT was correctly read after restarting and the appropriate mtd partitions were present. BRANCH=none Change-Id: I45317377da20259caf04a7a4fa077a892b03c45f Signed-off-by: Dan Ehrenberg <dehrenberg@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/238245 Reviewed-by: Randall Spangler <rspangler@chromium.org>
* cgpt: Rework number of entries calculationNam T. Nguyen2014-12-161-11/+21
| | | | | | | | | | | | | | | | | As pointed out by Daniel in CL:234996, the half_size_sectors should have been checked in both places. This CL reworks that part of the code to read easier. BUG=none BRANCH=none TEST=unittest Change-Id: I8faea3b094c375e4fd1a604a8fe759af88943fdf Reviewed-on: https://chromium-review.googlesource.com/235792 Reviewed-by: Daniel Ehrenberg <dehrenberg@chromium.org> Tested-by: Nam Nguyen <namnguyen@chromium.org> Commit-Queue: Nam Nguyen <namnguyen@chromium.org>
* cgpt: Support non-standard (smaller) entries tableNam T. Nguyen2014-12-123-31/+52
| | | | | | | | | | | | | | | | | | | | | The standard says that entries table must be at least 16384 bytes. On some of our devices, the NOR section is only 8 KiB and used to store both primary and secondary tables. On this device, we can only store 24 entries. Therefore, this CL adds support for non-standard entry table. It adjusts the MIN_NUMBER_OF_ENTRIES to 16, and replaces GPT_ENTRIES_SECTORS with CalculateEntriesSectors. BUG=chromium:441812 BRANCH=none TEST=unittest Change-Id: I6b85b35ce5612c7abb22142f8252bd0d45b676c5 Reviewed-on: https://chromium-review.googlesource.com/234996 Reviewed-by: Bill Richardson <wfrichar@chromium.org> Commit-Queue: Nam Nguyen <namnguyen@chromium.org> Tested-by: Nam Nguyen <namnguyen@chromium.org>