summaryrefslogtreecommitdiff
path: root/cgpt/cgpt_create.c
Commit message (Collapse)AuthorAgeFilesLines
* vboot: fix up some headers, includes, comments, spacingJoel Kitching2019-08-281-4/+4
| | | | | | | | | | | | | 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>
* cgpt: Fix format specifiers for uint64_tJacob Garber2019-08-061-1/+1
| | | | | | | | | | | | | | | 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>
* 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>
* cgpt: Remove hard coded 512 block size.Sam Hurst2018-04-121-3/+5
| | | | | | | | | | | | | | | | | | | | 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>
* 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-121-16/+19
| | | | | | | | | | | | | | | | | | | | | 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>
* vboot: GPT interface cleanupDan Ehrenberg2014-12-111-4/+5
| | | | | | | | | | | | | | | | - Rename drive_sectors to streaming_drive_sectors, to contrast with gpt_drive_sectors - Replace stored_on_device field with flags field for future extensibility BUG=chromium:433433 TEST=make runtests BRANCH=none Change-Id: I785a3b735b8eb96f647a334659329db3ee43eb80 Signed-off-by: Dan Ehrenberg <dehrenberg@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/234283 Reviewed-by: Bill Richardson <wfrichar@chromium.org>
* vboot: Remove FTS codeNam T. Nguyen2014-11-261-32/+2
| | | | | | | | | | | | | | | flash_ts driver (from Android) was pulled to support Sonic. But now we go a different route, this CL is to drop the FTS code. BUG=chromium:436597 BRANCH=none TEST=unittest Change-Id: I86d6273f9f5f642b504ccb6a76e005cda12d0e78 Reviewed-on: https://chromium-review.googlesource.com/231896 Reviewed-by: Bill Richardson <wfrichar@chromium.org> Commit-Queue: Nam Nguyen <namnguyen@chromium.org> Tested-by: Nam Nguyen <namnguyen@chromium.org>
* vboot: cgpt: Treat drive_path as the GPT storageNam T. Nguyen2014-11-141-8/+9
| | | | | | | | | | | | | | | | | | | | | | Previously, "cgpt" called out to "flashrom" directly to read and write NOR area. This CL removes that dependency and always treats "drive_path" as the storage of GPT structs. This makes it consistent that whatever device that cgpt reads from or writes to is always the device that stores GPT structs. We only need to pass in the size of the drive that contains the partitions, but we do not need to access to that drive. More information is in the bug. BUG=chromium:432611 BRANCH=none TEST=unittest CQ-DEPEND=CL:228942 Change-Id: Id0139adf70463cec4f2924de8b9a4725dbec822b Reviewed-on: https://chromium-review.googlesource.com/229736 Reviewed-by: Bill Richardson <wfrichar@chromium.org> Commit-Queue: Nam Nguyen <namnguyen@chromium.org> Tested-by: Nam Nguyen <namnguyen@chromium.org>
* vboot: cgpt: Support writing GPT structs to NOR flashNam T. Nguyen2014-11-131-6/+29
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This CL allows the GPT headers and partition entry arrays to be stored in a NOR flash device. Instead of treating both the NOR and NAND devices as one (in a sandwich way), this CL writes and reads the GPT structs independently of the actual device that houses the partitions. Therefore, the first usable LBA of the partitions will be at 0, and the last usable LBA is at the end of the NAND. +------------------------+ | NOR houses GPT structs | +------------------------+ | 0 | Index into v v +------------------------+ | NAND houses partitions | +------------------------+ Note that the "my_lba", "alternate_lba", "entries_lba" in the GPT headers are no longer meaningful. Consumers of cgptlib will have to set "stored_on_device" to either GPT_STORED_ON_DEVICE or GPT_STORED_OFF_DEVICE, and "gpt_drive_sectors" to the number of 512-byte sectors available to store GPT structs. The NOR read and write operations are done by "flashrom". BUG=chromium:425677 BRANCH=none TEST=unittest TEST=build with DEBUG, cgpt create/add/show on a stumpy-moblab Change-Id: I083b3c94da3b0bb3da1a7b10c6969774080a2afd Reviewed-on: https://chromium-review.googlesource.com/226800 Reviewed-by: Nam Nguyen <namnguyen@chromium.org> Commit-Queue: Nam Nguyen <namnguyen@chromium.org> Tested-by: Nam Nguyen <namnguyen@chromium.org>
* cgpt: Validate GPT headers before loading themNam T. Nguyen2014-10-171-9/+23
| | | | | | | | | | | | | | | | | This CL validates the GPT headers before continue loading its fields. BRANCH=none BUG=chromium:422469 TEST=unittest TEST=cpgt show on a random file. There should be some warnings. TEST=boot from SD/USB on a device. cgpt show that boot device. It should not fail. Change-Id: I1e5e986cc46620643ec8ec6914fa696a3d04d23a Reviewed-on: https://chromium-review.googlesource.com/223800 Reviewed-by: Bill Richardson <wfrichar@chromium.org> Commit-Queue: Nam Nguyen <namnguyen@chromium.org> Tested-by: Nam Nguyen <namnguyen@chromium.org>
* vboot_reference: Rename *_SECTOR to *_SECTORSNam T. Nguyen2014-08-291-6/+6
| | | | | | | | | | | | | | | | This CL renames GPT_PMBR_SECTOR to GPT_PMBR_SECTORS and GPT_HEADER_SECTOR to GPT_HEADER_SECTORS to better indicate that these are constants for sizes, not location. BRANCH=None BUG=None TEST=unittest Change-Id: I26ed6d45d77dcb1eb714135edbb9e4124b54e953 Reviewed-on: https://chromium-review.googlesource.com/214830 Reviewed-by: Bill Richardson <wfrichar@chromium.org> Tested-by: Nam Nguyen <namnguyen@chromium.org> Commit-Queue: Nam Nguyen <namnguyen@chromium.org>
* vboot: cgpt: Refer to partition entries by entries_lba.Nam T. Nguyen2014-08-281-5/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | This CL accesses the partition entry array through its header's entries_lba value. Previously, we assume the primary entry array lies on third sector, and the secondary array lies (1 + 32) sectors from disk end. This assumption was fine, even Wikipedia assumed the same. But in order for us to support writing boot code to the third sector (as required by some Freescale board), the primary entry array must be moved to another location. Therefore, we must use "entries_lba" to locate the arrays from now on. BRANCH=none BUG=chromium:406432 TEST=unittest TEST=`cgpt create -p` and then `cgpt show`. Make sure the table header and entries are properly moved. Change-Id: Ia9008b0bb204f290b1f6240df562ce7d3a9bbff2 Reviewed-on: https://chromium-review.googlesource.com/213861 Reviewed-by: Bill Richardson <wfrichar@chromium.org> Tested-by: Bill Richardson <wfrichar@chromium.org> Commit-Queue: Nam Nguyen <namnguyen@chromium.org> Tested-by: Nam Nguyen <namnguyen@chromium.org>
* Clean up exported Mtd* functionsBill Richardson2014-07-091-2/+2
| | | | | | | | | | | | | | | | | | | | A lot of functions were added some time ago, nominally to support keeping the firmware in an MTD device that wasn't formatted with the GPT headers. That work was never completed, so these functions aren't used anywhere. We may want to resurrect this work at some future point. Until then, this CL just moves some of the functions into an "unused" file. BUG=chromium:231567 BRANCH=ToT TEST=manual All tests pass, all firmware and external repos build. Change-Id: I420dd52d1cea0418cedf2f8e834c61145915f20c Signed-off-by: Bill Richardson <wfrichar@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/207037 Reviewed-by: Randall Spangler <rspangler@chromium.org>
* Remove cgpt app-specific symbols from libvboot_host.aBill Richardson2014-06-261-3/+2
| | | | | | | | | | | | | | | | | | | | | | Three symbols used by the standalone cgpt executable were being referenced in the files used to create the external libvboot_host.a needed by non-vboot userspace applications. This cleans things up so those symbols don't have to be explictly defined by other repos just to link with that library. BUG=chromium:318536 BRANCH=ToT TEST=manual No new functionality, just code cleanup. Tested with make runtests runfutiltests runlongtests Change-Id: Ibc77fb9800c89d7109ebf38d4d6729f52665722f Signed-off-by: Bill Richardson <wfrichar@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/205667 Reviewed-by: Randall Spangler <rspangler@chromium.org>
* Fix some issues with LBA vs byte offsetsAlbert Chaulk2013-07-311-0/+8
| | | | | | | | | | | | | | | | | | | In several places the existing code assumes LBA, but was improperly converted to use byte offsets, so multiply by the sector size to correct it and maintain the same interface between MTD & GPT. Also, since we will need to cgpt create on /dev/fts, which isn't a stat()able device, allow providing the disk size on the commandline. BRANCH=none BUG=chromium:221745 TEST=make runtests; cgpt create -s 12345 on MTD image Change-Id: Icc89a4505aba9a3dfc39b176a372f6e12d106aed Reviewed-on: https://gerrit.chromium.org/gerrit/62675 Reviewed-by: Bill Richardson <wfrichar@chromium.org> Tested-by: Albert Chaulk <achaulk@chromium.org> Commit-Queue: Albert Chaulk <achaulk@chromium.org>
* Port MTD structures to use 64-bit byte offsets instead of sectors.Albert Chaulk2013-07-031-2/+2
| | | | | | | | | | | | | | | | | As per the discussion on issue 221745 we will be using 64-bit byte offsets for the MTD partition table and converting to/from sectors internally in cgpt. Existing interfaces do not change, eg sizes are still reported in sectors, only the on-disk representation is affected. BRANCH=none BUG=chromium:221745 TEST=unit tests pass Change-Id: Id312d42783acfdabe6eb8aea11dcbd298e00a100 Reviewed-on: https://gerrit.chromium.org/gerrit/60919 Commit-Queue: Albert Chaulk <achaulk@chromium.org> Reviewed-by: Albert Chaulk <achaulk@chromium.org> Tested-by: Albert Chaulk <achaulk@chromium.org>
* Bugfixes & MTD create commandAlbert Chaulk2013-06-241-27/+55
| | | | | | | | | | | | | | | | | | | | | | | | | Fix some bugs in the cgpt implementation of the flash I/O functions & load logic, it was validating too much at load time. Implement the create command for MTD BUG=chromium:221745 TEST=MTD version of run_cgpt_tests.sh passes BRANCH=none Original-Change-Id: I2f52637d82962f4d805aa827c5c37685f10e76ea Reviewed-on: https://gerrit.chromium.org/gerrit/47172 Tested-by: Albert Chaulk <achaulk@chromium.org> Reviewed-by: Bill Richardson <wfrichar@chromium.org> Reviewed-by: Randall Spangler <rspangler@chromium.org> Commit-Queue: Albert Chaulk <achaulk@chromium.org> (cherry picked from commit 931544744ba410dad267064b87d504b0b4c24772) Change-Id: If9364155fb2c030645adc6ee6f3fbe5373bcc153 Reviewed-on: https://gerrit.chromium.org/gerrit/49793 Commit-Queue: Albert Chaulk <achaulk@chromium.org> Reviewed-by: Albert Chaulk <achaulk@chromium.org> Tested-by: Albert Chaulk <achaulk@chromium.org>
* Massive refactoring of external header files.Bill Richardson2013-04-021-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | This reduces the number of exported header files to the minimum needed by the existing userspace utilities and firmware implementations. BUG=chromium:221544 BRANCH=none TEST=manual, trybots CQ-DEPEND=CL:47019,CL:47022,CL:47023 sudo FEATURES=test emerge vboot_reference FEATURES=test emerge-$BOARD \ vboot_reference \ chromeos-cryptohome \ chromeos-installer \ chromeos-u-boot \ peach-u-boot \ depthcharge Change-Id: I2946cc2dbaf5459a6c5eca92ca57d546498e6d85 Signed-off-by: Bill Richardson <wfrichar@chromium.org> Reviewed-on: https://gerrit.chromium.org/gerrit/47021 Reviewed-by: Randall Spangler <rspangler@chromium.org>
* Apply consistent naming scheme for hostlib functions.Bill Richardson2013-03-201-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The chromeos-installer uses several functions from the vboot_reference userspace library, but the names of those functions are inconsistent: IsZero MapFile VbGetSystemPropertyString cgpt_add cgpt_boot cgpt_create cgpt_get_boot_partition_number cgpt_get_num_non_empty_partitions cgpt_get_partition_details cgpt_prioritize cgpt_set_attributes find_kernel_config The Google C++ style guide says types and functions should use CamelCase, while variables use lower_case_with_underscores. Kernel style (which vboot_reference tries to be more-or-less compatible with) uses lower_case_with_underscores for everything, but that really only has to apply to firmware stuff. For userspace, we can use the Google style. BUG=chromium:221544 BRANCH=none TEST=buildbot CQ-DEPEND=CL:46045 Renaming/cleanup only; no functional changes. Change-Id: I9c82c9ff8909be88586194c8ffdb435fc771195f Signed-off-by: Bill Richardson <wfrichar@chromium.org> Reviewed-on: https://gerrit.chromium.org/gerrit/46044
* Let cgpt open devices in read-only mode when possible.Bill Richardson2012-05-021-1/+1
| | | | | | | | | | | | | | | | BUG=chromium-os:12430 TEST=manual Running "make; make runtests" in src/platform/vboot_refererence will test this change. Tests for use on a Chromebook are described in the bug report, but will require a USB or SD card that has a physical write-protect switch. Change-Id: I16a67bad3b59bec0981f4064f51fb1a29da65a90 Reviewed-on: https://gerrit.chromium.org/gerrit/21474 Tested-by: Bill Richardson <wfrichar@chromium.org> Commit-Ready: Bill Richardson <wfrichar@chromium.org> Reviewed-by: Richard Barnette <jrbarnette@chromium.org> Reviewed-by: Che-Liang Chiou <clchiou@chromium.org>
* Enable building of Cgpt C++ Library for 32-bit.Jay Srinivasan2012-02-231-1/+10
| | | | | | | | | | | | | | | | | | | The existing library had a bunch of dependencies which are too many to build for the 32-bit platform. So this checkin prunes the dependency list by building only things that are absolutely required for the functionality used in 32-bit Post-Installer. Made the use of libuuid restricted only to cgpt and unit tests so that libcgpt-cc.a doesn't depend on it. BUG=chromium-os:25374 TEST=Built 32-bit and 64-bit. Tested 32-bit post-install. Change-Id: Idd0826fdf507a95728fee8adac9520e26f05d469 Reviewed-on: https://gerrit.chromium.org/gerrit/16433 Reviewed-by: Don Garrett <dgarrett@chromium.org> Reviewed-by: Sonny Rao <sonnyrao@chromium.org> Commit-Ready: Jay Srinivasan <jaysri@chromium.org> Tested-by: Jay Srinivasan <jaysri@chromium.org>
* Implementation of CgptManager C++ library and unit tests.Jay Srinivasan2012-02-161-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | CgptManager exposes the cgpt commands via a C++ library so that the post-installer for 32- to 64-bit upgrade can link directly against a library and thus avoid any shell dependency. The default make target will not build libcgpt-cc.a since it requires some dependencies that are available only in chroot. A separate follow-up checkin to the vboot_reference ebuild will enable emerging the libcgpt-cc.a by default. BUG=chromium-os:25374 TEST=Tested with the new unit tests for CgptManager, ran existing cgpt unit tests, as well as running the cgpt commands manually. Built on both amd64 and x86. Tested that vboot_reference is also buildable outside of chroot. Tested that vboot_reference-firmware and vboot_reference-tests also build fine with these changes. CQ-DEPEND=I99f6c321e09c2425eaa8171d78685d2d731954c8 Change-Id: I59a896255b8ea2fc8b1b2150ae7c4ff9d0769699 Reviewed-on: https://gerrit.chromium.org/gerrit/15730 Reviewed-by: Bill Richardson <wfrichar@chromium.org> Reviewed-by: Gaurav Shah <gauravsh@chromium.org> Commit-Ready: Jay Srinivasan <jaysri@chromium.org> Tested-by: Jay Srinivasan <jaysri@chromium.org>
* Refactor of cgpt tool for 32->64 autoupdate work.release-R18-1660.BJay Srinivasan2012-01-301-0/+58
This check-in splits the cgpt into two layers. The top layer (cmd_* files) does the command-line parsing and the bottom layer (cgpt_* files) does the actual cgpt work. This is done so that the bottom layer can be reused for the monolithic C++ post-installer code that will be done in subsequent checkins. BUG=chromium-os:25374 TEST=Tested with existing cgpt unit tests as well as running the cgpt commands manually. Change-Id: I69a31eb3e867a1430cac9a694581331368aa7bb4 Reviewed-on: https://gerrit.chromium.org/gerrit/14940 Reviewed-by: Jay Srinivasan <jaysri@chromium.org> Tested-by: Jay Srinivasan <jaysri@chromium.org> Commit-Ready: Jay Srinivasan <jaysri@chromium.org>