summaryrefslogtreecommitdiff
path: root/cgpt/cgpt_add.c
Commit message (Collapse)AuthorAgeFilesLines
* vboot: fix up some headers, includes, comments, spacingJoel Kitching2019-08-281-3/+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>
* vboot_reference: add const to char* params in cgptFletcher Woodruff2019-02-121-1/+1
| | | | | | | | | | | | | | | | | | | | 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 support for managing GPT platform required partition bitBen Chan2018-02-061-0/+6
| | | | | | | | | | | | | | | | 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-091-4/+2
| | | | | | | | | | | | | | | | | 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>
* 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
* cgpt: add support for managing the legacy boot gpt bitstabilize-kevin-8785.94.BMike Frysinger2016-09-081-0/+6
| | | | | | | | | | | | | | | | | | | | | | | 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>
* vboot: Remove FTS codeNam T. Nguyen2014-11-261-87/+21
| | | | | | | | | | | | | | | 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-3/+6
| | | | | | | | | | | | | | | | | | | | | | 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>
* 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-4/+3
| | | | | | | | | | | | | | | | | | | | | | 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-3/+5
| | | | | | | | | | | | | | | | | | | 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>
* Add labels to MTD partitions.Albert Chaulk2013-07-311-0/+3
| | | | | | | | | | | | | | | Add labels to MTD partitions and clean up some of the show code, adding more info on the MTD prints and eliminating duplicated code. BRANCH=none TEST=make runtests & manual cgpt add -l "label"; cgpt show to verify labels BUG=none Change-Id: I59736128f394c2aca937a3a0bb5fc5d42b0149a9 Reviewed-on: https://gerrit.chromium.org/gerrit/63367 Reviewed-by: Bill Richardson <wfrichar@chromium.org> Commit-Queue: Albert Chaulk <achaulk@chromium.org> Tested-by: Albert Chaulk <achaulk@chromium.org>
* Don't always enable MTD mode unless MTD device is specifiedfactory-4455.Bfactory-4455.228.BAlbert Chaulk2013-07-241-2/+0
| | | | | | | | | | | | | | | | On MTD devices, don't always enable MTD mode - the installer needs to be able to access both the GPT disk and the MTD disk, so only enable it if we install to /dev/fts BRANCH=none BUG=chromium:221745 TEST=make runtests Change-Id: I7688e6bc758ef47cfb9d468c1224ef43b2043d02 Reviewed-on: https://gerrit.chromium.org/gerrit/62662 Reviewed-by: Randall Spangler <rspangler@chromium.org> Commit-Queue: Albert Chaulk <achaulk@chromium.org> Tested-by: Albert Chaulk <achaulk@chromium.org>
* MTD: When running on the host (as during install) use the host FTS if possible.Albert Chaulk2013-07-161-0/+2
| | | | | | | | | | | | BUG=chromium:252331 TEST='make runtests' still passes BRANCH=none Change-Id: I1deb70766b811b070f0f412cb5cfa583250dd687 Reviewed-on: https://gerrit.chromium.org/gerrit/61328 Commit-Queue: Albert Chaulk <achaulk@chromium.org> Reviewed-by: Albert Chaulk <achaulk@chromium.org> Tested-by: Albert Chaulk <achaulk@chromium.org>
* Port MTD structures to use 64-bit byte offsets instead of sectors.Albert Chaulk2013-07-031-8/+9
| | | | | | | | | | | | | | | | | 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>
* MTD modification commands: add & prioritizeAlbert Chaulk2013-07-031-35/+101
| | | | | | | | | | | | | | | | | | | | | Additionally renames the new functions in add to be CamelCase style BUG=chromium:221745 TEST=MTD version of run_cgpt_tests.sh passes BRANCH=none Original-Change-Id: Ic173f99d7ca4af025403ab11f37061c33c9d59ea Reviewed-on: https://gerrit.chromium.org/gerrit/47173 Tested-by: Albert Chaulk <achaulk@chromium.org> Reviewed-by: Bill Richardson <wfrichar@chromium.org> Commit-Queue: Albert Chaulk <achaulk@chromium.org> (cherry picked from commit c3aad2fd06a21097cffd10ec5b168e728616b868) Change-Id: Ib3bb947ffcd5c0f40398a27a721e392b895c9da0 Reviewed-on: https://gerrit.chromium.org/gerrit/49795 Reviewed-by: Bill Richardson <wfrichar@chromium.org> Commit-Queue: Albert Chaulk <achaulk@chromium.org> Tested-by: Albert Chaulk <achaulk@chromium.org>
* Refactor CgptAdd and CgptPrioitize to remove gpt-specific codeAlbert Chaulk2013-05-061-156/+130
| | | | | | | | | | | | | | | | | | | | - Refactor cgpt_prioitize.c to completely remove gpt-specific code. - Refactor cgpt_add.c to isolate gpt-dependence to one helper function and the backup/restore logic - Change several common apis to take a struct drive* rather than a GptData*, this provides a path to cleanly implement mtd versions BUG=chromium:221745 TEST=no functional changes, existing tests cover this BRANCH=none Change-Id: I27ed166aae390aa5dc83062f62939e45122edc76 Original-Change-Id: I1b0a73509efbf22411c4ae5cf044feede0a49a33 Reviewed-on: https://gerrit.chromium.org/gerrit/46548 Tested-by: Albert Chaulk <achaulk@chromium.org> Reviewed-by: Bill Richardson <wfrichar@chromium.org> Commit-Queue: Albert Chaulk <achaulk@chromium.org> Reviewed-on: https://gerrit.chromium.org/gerrit/49788
* Massive refactoring of external header files.Bill Richardson2013-04-021-4/+5
| | | | | | | | | | | | | | | | | | | | | | | | 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-6/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* Rename Strncat to StrnAppend, use it instead of strncat.firmware-spring-3824.Bfirmware-spring-3824.84.Bfirmware-spring-3824.55.Bfirmware-spring-3824.4.Bfirmware-skate-3824.129.BBill Richardson2013-03-061-16/+17
| | | | | | | | | | | | | | | | | | Strncat() looks almost like strncat(), but it's completely different. Change the name to reduce confusion. Also fix a place where strncat() was misused anyway. BUG=none BRANCH=all TEST=manual sudo FEATURES=test emerge vboot_reference FEATURES=test emerge-$BOARD vboot_reference Change-Id: I39c30d391aa6566ec67461462e800720ade66a91 Signed-off-by: Bill Richardson <wfrichar@chromium.org> Reviewed-on: https://gerrit.chromium.org/gerrit/44572
* Make cgpt_add error messages a little more verboseVadim Bendebury2012-09-261-4/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | When the cgpt utility complaints about parameter errors, it is impossible to tell what exactly went wrong. This change consolidates error definitions and adds a function to convert integer error values into text messages. BRANCH=none BUG=none TEST=manual . emerge-link vbooot_reference . copy generated `cgpt' to a Link device . run command with wrong arguments with respect to the existing GPT: localhost var # ./cgpt add -i 3 -b 3985408 -s 1757184 -t rootfs -l ROOT-A /dev/sda ERROR: cgpt add: Starting LBA overlaps ERROR: cgpt add: -i 3 -l ROOT-A -b 3985408 -s 1757184 -t 3CB8E202-3B7E-47DD-8A3C-7FF2A13CFCEC . on the host, in the chroot in src/platform/vboot_reference run $ make && make runtests observe all tests succeed Change-Id: Ibd23ca0430a875f70524adc99e0509b26ae699b2 Signed-off-by: Vadim Bendebury <vbendeb@chromium.org> Reviewed-on: https://gerrit.chromium.org/gerrit/34003 Reviewed-by: Randall Spangler <rspangler@chromium.org>
* cgpt: Fix error in modifying size of an existing partitionBill Richardson2012-08-241-2/+2
| | | | | | | | | | | | | | | | | | | Modifying the size of an existing partition without modifying the start as well assumed the start was at block 0. Sometimes it was caught, often it wasn't. Fix the error, add a test to catch the problem. BUG=chrome-os-partner:13090 BRANCH=all TEST=manual make && make runtests Change-Id: I4f5a5031a90a3e78d886ed3573f61305316a3f1f Signed-off-by: Bill Richardson <wfrichar@chromium.org> Reviewed-on: https://gerrit.chromium.org/gerrit/31418 Reviewed-by: Randall Spangler <rspangler@chromium.org>
* cgpt: verify the modifications of 'cgpt add' before effected.Louis Yung-Chieh Lo2012-06-271-2/+64
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Current code only does basic check on parameters, but doesn't validate if it can pass the CheckEntries(). So a user can accidentally break the cgpt table by: cgpt add /dev/sda -i 6 -s 0 # 0 sector is not allowed for a partition. cgpt show /dev/sda ... INVALID_ENTRIES ... This CL checks the new entry before we write it to disk. If new entry is not good, we return fail. Signed-off-by: Louis Yung-Chieh Lo <yjlou@chromium.org> BUG=None TEST=tested on link. % cgpt add /dev/sda -i 6 -s 0 ERROR: cgpt add: A given parameter is not allowed. % cgpt show /dev/sda (no error, and partition 6 is still good) Change-Id: Iee0ad24f73ca12028c0b8a0a5490b67c815488cf Reviewed-on: https://gerrit.chromium.org/gerrit/25914 Commit-Ready: Yung-Chieh Lo <yjlou%chromium.org@gtempaccount.com> Reviewed-by: Yung-Chieh Lo <yjlou%chromium.org@gtempaccount.com> Tested-by: Yung-Chieh Lo <yjlou%chromium.org@gtempaccount.com>
* Let cgpt open devices in read-only mode when possible.Bill Richardson2012-05-021-3/+3
| | | | | | | | | | | | | | | | 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/+5
| | | | | | | | | | | | | | | | | | | 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-16/+172
| | | | | | | | | | | | | | | | | | | | | | | | | | 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/+115
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>