### Start OS Install Manually Source: https://github.com/chromiumos/platform2/blob/main/os_install_service/README.md Execute the `StartOsInstall` method on the OS install D-Bus service using `dbus-send`. This command requires root privileges and is typically run as the chronos user. ```bash sudo -u chronos dbus-send --print-reply --system \ --dest=org.chromium.OsInstallService \ /org/chromium/OsInstallService \ org.chromium.OsInstallService.StartOsInstall ``` -------------------------------- ### Emerge vhost_user_starter and dependencies Source: https://github.com/chromiumos/platform2/blob/main/vm_tools/vhost_user_starter/README.md After starting the packages with cros_workon, use emerge to install them on your board. This command ensures all necessary components are built and available. ```bash emerge-${BOARD} dev-rust/system_api chromeos-base/vhost_user_starter ``` -------------------------------- ### Define Service with Pre-start and Post-stop Scripts Source: https://github.com/chromiumos/platform2/blob/main/init/README.md Use this pattern when defining a service that requires setup before starting and cleanup after stopping. Omit pre-start or post-stop if not needed. ```upstart pre-start script # setup work here end script exec # daemon command-line here post-stop script # cleanup work here end script ``` -------------------------------- ### Build and Upload Metrics Example Source: https://github.com/chromiumos/platform2/blob/main/metrics/rust-client/README.md Build the release version of the examples and upload the compiled metrics binary to the DUT. This is a prerequisite for running the example on the device. ```shell (chroot)$ cargo build --release --examples (chroot)$ scp target/release/examples/metrics $DUT:/usr/local/bin ``` -------------------------------- ### Example configuration with custom features Source: https://github.com/chromiumos/platform2/blob/main/chromeos-config/README.md A comprehensive example demonstrating YAML anchors, templating, and local variable usage. ```yaml common_config: &common_config name: "{{$device-name}}" brand-code: "{{$brand-code}}" identity: platform-name: "SomePlatform" frid: "Google_SomeFirmware" sku-id: "{{$sku-id}}" firmware-signing: key-id: "{{$key-id}}" signature-id: "{{name}}" chromeos: devices: - $device-name: "SomeDevice" products: - $brand-code: "YYYY" $key-id: "SOME-KEY-ID" skus: - $sku-id: 0 config: <<: *common_config wallpaper: "some-wallpaper" - $sku-id: 1 config: *common_config ``` -------------------------------- ### Lab DUT MiniOS Setup - Verification and Installation Source: https://github.com/chromiumos/platform2/blob/main/minios/README.md After preparing the DUT in a lab environment, these commands are executed on the DUT itself to verify it's booting from USB and to initiate the ChromeOS installation process, which will include MiniOS. ```bash rootdev -s # should be /dev/sd* ``` ```bash /usr/sbin/chromeos-install ``` ```bash reboot ``` -------------------------------- ### Install Build Prerequisites Source: https://github.com/chromiumos/platform2/blob/main/vm_tools/baguette_image/README-build.md Run this script to install necessary dependencies for native builds. ```bash src/deps.sh ``` -------------------------------- ### Chrome OS Pre-chroot Hooks Example Source: https://github.com/chromiumos/platform2/blob/main/run_oci/README.md This JSON configuration demonstrates how to use the `precreate` and `prechroot` hooks to execute custom setup scripts before a container is created and before the chroot operation, respectively. These hooks are useful for setting up dynamic bind mounts that depend on runtime conditions. ```json { "hooks": { "precreate": [ { "path": "/usr/sbin/arc-setup", "args": ["arc-setup", "--setup"] } ], "prechroot": [ { "path": "/usr/sbin/arc-setup", "args": ["arc-setup", "--pre-chroot"] } ] } } ``` -------------------------------- ### Run QEMU with UEFI and Custom Variables Source: https://github.com/chromiumos/platform2/blob/main/os_install_service/README.md This command launches a QEMU virtual machine with UEFI support, utilizing a custom OVMF variables file (`OVMF_VARS.fd`) that includes the `ChromiumOSAutoInstall` variable. This setup is used for testing automatic OS installation. ```bash runvm --uefi --ovmf-vars OVMF_VARS.fd <...> > qemu-system-x86_64 \ > ... > -drive if=pflash,format=raw,readonly=on,file=/.../OVMF_CODE.fd \ > -drive if=pflash,format=raw,readonly=on,file=OVMF_VARS.fd ``` -------------------------------- ### Register and start an AsyncGrpcServer Source: https://github.com/chromiumos/platform2/blob/main/libbrillo/brillo/grpc/README.md Configure an AsyncGrpcServer by registering handlers for specific RPCs and calling Start to begin listening. ```cpp void OnSomeRpc( std::unique_ptr request, base::OnceCallback)> response_callback) { // Call |std::move(response_callback).Run(status, response)| when you have a // response! } std::string listening_address = ...; AsyncGrpcServer server( message_loop.task_runner(), listening_address); server.RegisterHandler(&SomeService::AsyncService::RequestSomeRpc, base::BindRepeating(&onSomeRpc)); server.Start(); ``` -------------------------------- ### Start cros_workon for vhost_user_starter Source: https://github.com/chromiumos/platform2/blob/main/vm_tools/vhost_user_starter/README.md Use this command to start working on the vhost_user_starter and its dependencies using cros_workon. Ensure you have the correct board specified. ```bash cros_workon --board ${BOARD} start \ dev-rust/system_api chromeos-base/vhost_user_starter ``` -------------------------------- ### Example JSON Policy File Source: https://github.com/chromiumos/platform2/blob/main/policy_utils/README.md An example of a JSON file used to set device policies. This specific example allows Bluetooth. ```json { "DeviceAllowBluetooth": true } ``` -------------------------------- ### Rebuild and install vm_concierge dependencies Source: https://github.com/chromiumos/platform2/blob/main/vm_tools/concierge/README.md Rebuild and install dependencies after modifications. Install system_api or vm_protos if they have changed, otherwise just build vm_host_tools. ```bash cros_workon_make --test --board=${BOARD} \ chromeos-base/system_api \ --install # If system_api changed. cros_workon_make --test --board=${BOARD} \ chromeos-base/vm_protos \ --install # If vm_protos changed. cros_workon_make --test --board=${BOARD} chromeos-base/vm_host_tools ``` -------------------------------- ### Disk Read Routine Support Examples Source: https://github.com/chromiumos/platform2/blob/main/diagnostics/docs/routine_supportability.md Examples of checking disk_read_v2 support status with various parameters. ```json # cros-health-tool diag disk_read_v2 --type=ab --check_supported { "debug_message": "Unexpected disk read type", "status": "Not supported" } # cros-health-tool diag disk_read_v2 --file_size_mib=0 --check_supported { "debug_message": "Test file size should not be zero", "status": "Not supported" } # cros-health-tool diag disk_read_v2 --file_size_mib=1 --check_supported { "status": "Supported" } ``` -------------------------------- ### Handle Kickoff Setup Result Source: https://github.com/chromiumos/platform2/blob/main/biod/study/collection-tool/html/index.html Processes the result of the kickoff setup request. Enables the OK button if successful or displays an error message. ```javascript function onKickoffSetupResult(result) { is_kickoff_waiting = false; if (result !== "ok") { document.getElementById("kickoff-server-state").textContent = result; return; } // Enable the Ok button to allow the study to proceed. document.getElementById("kickoff-server-state").hidden = true; document.getElementById("kickoff_finger").disabled = false; } ``` -------------------------------- ### Run Metrics Example on DUT Source: https://github.com/chromiumos/platform2/blob/main/metrics/rust-client/README.md Execute the compiled metrics example on the DUT. This command assumes the metrics binary has been successfully uploaded to the device. ```shell (DUT)$ metrics ``` -------------------------------- ### Configure and Start Perfetto Trace Source: https://github.com/chromiumos/platform2/blob/main/dbus_perfetto_producer/README.md Starts a trace session with the track_event data source configured for the dbus_perfetto_producer category. ```shell (device) perfetto -c - --txt -o ${output file location} \ < var.json virt-fw-vars -i OVMF_VARS.fd -o OVMF_VARS.fd --set-json var.json ``` -------------------------------- ### Example DLC Ebuild Configuration Source: https://github.com/chromiumos/platform2/blob/main/dlcservice/docs/developer.md This example demonstrates the essential configuration within a DLC ebuild file. It includes setting required variables and using dlc_src_install for proper packaging. ```bash inherit dlc.eclass DLC_PREALLOC_BLOCKS = "1000" DLC_SCALED = "true" def src_install(self): # Add DLC path prefix for installation insinto $(dlc_add_path "my_dlc_path") \ ${S}/my_file.txt # Call dlc_src_install at the end to pack the DLC dlc_src_install ``` -------------------------------- ### Example configuration for task usage Source: https://github.com/chromiumos/platform2/blob/main/init/README.md Illustrates a configuration that runs during boot-services without a stop condition, which is the specific use case for the 'task' stanza. ```text start on starting boot-services script : end script ``` -------------------------------- ### Install Gentoo/ChromiumOS SDK Dependencies Source: https://github.com/chromiumos/platform2/blob/main/biod/study/collection-tool/PREPARE_SAMPLES.md Installs imagemagick and python-gnupg on Gentoo or ChromiumOS SDK environments. Use this command for package installation. ```bash sudo emerge media-gfx/imagemagick dev-python/python-gnupg ``` -------------------------------- ### Build and Prepare Image for Local Experimentation Source: https://github.com/chromiumos/platform2/blob/main/vm_tools/reference_vm/README.md Builds the Reference VM image and then processes it for local experimentation by sparsifying, converting to qcow2, compressing with brotli, and updating Tast test dependencies. ```sh sudo ./build.py ./run_experiment.sh [path/to/refvm.img] ``` -------------------------------- ### Setup Python Virtual Environment Source: https://github.com/chromiumos/platform2/blob/main/biod/study/README.md Run this script to create the Python virtual environment for development. ```bash python-venv-setup.sh ``` -------------------------------- ### Install Python Dependencies for UEFI Source: https://github.com/chromiumos/platform2/blob/main/vm_tools/reference_vm/README.md Installs the 'virt-firmware' Python package using pip3 for creating the UEFI variables image. Installs to the user's local directory. ```sh pip3 install --user virt-firmware ``` -------------------------------- ### Build vhost_user_starter using cargo build in chroot Source: https://github.com/chromiumos/platform2/blob/main/vm_tools/vhost_user_starter/README.md To build vhost_user_starter using cargo, you must first enter the chroot environment. This command navigates to the project directory and executes the build. ```bash cros_sdk (chroot) cd /mnt/host/source/platform2/vm_tools/vhost_user_starter && cargo build ``` -------------------------------- ### Install Node Modules Source: https://github.com/chromiumos/platform2/blob/main/parallax/README.md Installs project dependencies after setting up the Node.js environment. ```bash npm install ``` -------------------------------- ### Install Node.js Toolchain Source: https://github.com/chromiumos/platform2/blob/main/parallax/README.md Installs the required Node.js environment within the Chroot. ```bash sudo emerge net-libs/nodejs ``` -------------------------------- ### Build and deploy guest kernel with pcserial Source: https://github.com/chromiumos/platform2/blob/main/vm_tools/docs/dev_conf.md Commands to build and deploy a kernel with pcserial support for capturing very early boot logs. ```bash chroot$ cros_workon --board=$BOARD start arcvm-kernel-5_4 chroot$ USE=pcserial emerge-$BOARD arcvm-kernel-5_4 chroot$ cros deploy DUT arcvm-kernel-5_4 ``` -------------------------------- ### Install Python venv dependency Source: https://github.com/chromiumos/platform2/blob/main/biod/study/analysis-tool/README.md Install the python3-venv package on Debian-based systems. ```bash sudo apt install -y python3-venv ``` -------------------------------- ### TPM2_Startup Implementation Source: https://github.com/chromiumos/platform2/blob/main/trunks/generator/raw_commands.txt The C implementation of the TPM2_Startup command, handling NV state validation, startup type determination, and subsystem initialization. ```c #include "InternalRoutines.h" #include "Startup_fp.h" Error Returns TPM_RC_VALUE Meaning start up type is not compatible with previous shutdown sequence TPM_RC TPM2_Startup( Startup_In *in // IN: input parameter list ) { STARTUP_TYPE TPM_RC BOOL startup; result; prevDrtmPreStartup; // The command needs NV update. Check if NV is available. // A TPM_RC_NV_UNAVAILABLE or TPM_RC_NV_RATE error may be returned at // this point result = NvIsAvailable(); if(result != TPM_RC_SUCCESS) return result; // Input Validation // Read orderly shutdown states from previous power cycle NvReadReserved(NV_ORDERLY, &g_prevOrderlyState); // HACK to extract the DRTM startup type associated with the previous shutdown prevDrtmPreStartup = (g_prevOrderlyState == (TPM_SU_STATE + 0x8000)); if(prevDrtmPreStartup) g_prevOrderlyState = TPM_SU_STATE; // if the previous power cycle was shut down with no StateSave command, or // with StateSave command for CLEAR, this cycle can not startup up with // STATE if( ( g_prevOrderlyState == SHUTDOWN_NONE || g_prevOrderlyState == TPM_SU_CLEAR ) && in->startupType == TPM_SU_STATE ) return TPM_RC_VALUE + RC_Startup_startupType; // Internal Date Update // Translate the TPM2_ShutDown and TPM2_Startup sequence into the startup // types. if(in->startupType == TPM_SU_CLEAR && g_prevOrderlyState == TPM_SU_STATE) { startup = SU_RESTART; // Read state reset data NvReadReserved(NV_STATE_RESET, &gr); } else if(in->startupType == TPM_SU_STATE && g_prevOrderlyState == TPM_SU_STATE) { // For a resume, the H-CRTM startup method must be the same if(g_DrtmPreStartup != prevDrtmPreStartup) return TPM_RC_LOCALITY; // Read state clear and state reset data NvReadReserved(NV_STATE_CLEAR, &gc); NvReadReserved(NV_STATE_RESET, &gr); startup = SU_RESUME; } else { startup = SU_RESET; } // Read persistent data from NV NvReadPersistent(); // Crypto Startup CryptUtilStartup(startup); // Start up subsystems // Start counters and timers TimeStartup(startup); // Start dictionary attack subsystem DAStartup(startup); // Enable hierarchies HierarchyStartup(startup); // Restore/Initialize PCR PCRStartup(startup); // Restore/Initialize command audit information CommandAuditStartup(startup); // Object context variables if(startup == SU_RESET) { // Reset object context ID to 0 gr.objectContextID = 0; // Reset clearCount to 0 gr.clearCount= 0; } // Initialize object table ObjectStartup(); // Initialize session table SessionStartup(startup); // Initialize index/evict data. // in NV index NvEntityStartup(startup); This function clear read/write locks // Initialize the orderly shut down flag for this cycle to SHUTDOWN_NONE. gp.orderlyState = SHUTDOWN_NONE; ``` -------------------------------- ### Battery Health Output Example Source: https://github.com/chromiumos/platform2/blob/main/diagnostics/docs/diag-routines-for-oems.md Example output for battery health diagnostic routines. ```text Progress: 100 Output: { "resultDetails": { "chargeFullAh": 6.156, "chargeFullDesignAh": 6.23, "chargeNowAh": 6.017, "currentNowA": 0.512, "cycleCount": 20, "manufacturer": "333-22-", "present": 1, "status": "Charging", "voltageNowV": 8.388, "wearPercentage": 13 } } Status: Passed Status message: Routine passed. ``` -------------------------------- ### Start Building update_engine from ToT Source: https://github.com/chromiumos/platform2/blob/main/update_engine/README.md Commands to enable workon for the update_engine and emerge it within the chroot. ```bash (chroot) $ cros_workon --host start update_engine (chroot) $ sudo emerge update_engine ``` -------------------------------- ### Battery Discharge Output Example Source: https://github.com/chromiumos/platform2/blob/main/diagnostics/docs/diag-routines-for-oems.md Example output for battery discharge diagnostic routines. ```text Progress: 0 Unplug the AC adapter. Press ENTER to continue. Progress: 100 Progress: 100 Output: { "resultDetails": { "dischargePercent": 1.123456789012345 } } Status: Passed Status message: Battery discharge routine passed. ``` -------------------------------- ### Battery Charge Output Example Source: https://github.com/chromiumos/platform2/blob/main/diagnostics/docs/diag-routines-for-oems.md Example output for battery charge diagnostic routines. ```text Progress: 0 Unplug the AC adapter. Press ENTER to continue. Progress: 0 Output: { "errorDetails": { "chargePercentRequested": 20, "startingBatteryChargePercent": 90 } } Status: Error Status message: Invalid minimum required charge percent requested. ``` ```text Progress: 0 Unplug the AC adapter. Press ENTER to continue. Progress: 100 Output: { "resultDetails": { "chargePercent": 12.123456789012345 } } Status: Passed Status message: Battery charge routine passed. ``` -------------------------------- ### Build and deploy screen-capture-utils Source: https://github.com/chromiumos/platform2/blob/main/screen-capture-utils/README.md Commands for building, deploying, and testing the screen-capture-utils package. Includes setting up the board, emerging the package, deploying to DUT, and running Tast tests. ```shell $ BOARD=rammus $ DUT=localhost:2229 $ setup_board --board=${BOARD} # required only once per board. $ cros_workon --board=${BOARD} start screen-capture-utils $ emerge-${BOARD} -j 100 chromeos-base/screen-capture-utils $ cros deploy --root=/usr/local/ "${DUT}" chromeos-base/screen-capture-utils $ tast run "${DUT}" graphics.KmsvncConnect $ tast run "${DUT}" graphics.Smoke.platform ``` -------------------------------- ### Create Baguette VM Source: https://github.com/chromiumos/platform2/blob/main/vm_tools/baguette_image/README.md Initialize the VM using the transferred image with a specified size. ```bash vmc create --vm-type baguette \ --size 15G \ --source /home/chronos/user/MyFiles/Downloads/baguette_rootfs.image.zst \ baguette ``` -------------------------------- ### Install Pandoc dependency Source: https://github.com/chromiumos/platform2/blob/main/biod/study/analysis-tool/README.md Install the pandoc utility on Debian-based systems for report generation. ```bash sudo apt install -y pandoc ``` -------------------------------- ### Install Python Packages Source: https://github.com/chromiumos/platform2/blob/main/biod/study/analysis-tool/benchmarks/boot_sample.ipynb Installs necessary Python packages for the project using pip. ```python %pip install pandas numpy matplotlib scipy ``` -------------------------------- ### Build Python3 virtual environment bundle Source: https://github.com/chromiumos/platform2/blob/main/biod/study/collection-tool/FPSTUDY_VENV_INSTALL.md Commands to set up the environment, install dependencies, and package the tool into a tarball. ```bash # Optionally, you can build the virtual environment in a Docker container. # docker run -v$HOME/Downloads:/Downloads -it debian # On Debian, ensure that git, python3, python3-pip, and virtualenv are installed. (outside) $ sudo apt update && apt install git python3 python3-pip virtualenv # Grab the fingerprint study tool source (outside) $ git clone https://chromium.googlesource.com/chromiumos/platform2 # Create an isolated python3 environment (outside) $ virtualenv -p python3 /tmp/fpstudy-virtualenv (outside) $ . /tmp/fpstudy-virtualenv/bin/activate # Install fingerprint study dependencies (outside) $ pip3 install -r platform2/biod/study/requirements.txt # Copy the fingerprint study source (outside) $ cp -r platform2/biod/study /tmp/fpstudy-virtualenv # Bundle the virtual environment with study source (outside) $ tar -C /tmp -czvf /tmp/fpstudy-virtualenv.tar.gz fpstudy-virtualenv # For Docker with Downloads volume shared, run the following command: # cp /tmp/fpstudy-virtualenv.tar.gz /Downloads/ ``` -------------------------------- ### Start Runtime Probe Development Source: https://github.com/chromiumos/platform2/blob/main/runtime_probe/README.md Use `cros_workon` to start development on the runtime_probe package. ```shell cros_workon-$BOARD start runtime_probe ``` -------------------------------- ### Enable fingerprint study Upstart job Source: https://github.com/chromiumos/platform2/blob/main/biod/study/collection-tool/FPSTUDY_VENV_INSTALL.md Commands to link the configuration file and start the service. ```bash (device) $ ln -s /opt/google/fpstudy-virtualenv/study/fingerprint_study_virtualenv.conf /etc/init (device) $ start fingerprint_study_virtualenv (device) $ sleep 2 (device) $ status fingerprint_study_virtualenv ```