Feature: Hardware Detection
Relevant source files
The following files were used as context for generating this wiki page:
Introduction
Hardware detection is a critical safety mechanism within the safe64switch utility. Its primary purpose is to ensure that the execution environment is a genuine Raspberry Pi before attempting to modify system-level boot configurations. By validating the hardware, the script prevents accidental execution on incompatible Linux distributions or hardware architectures that do not utilize the Raspberry Pi /boot/config.txt structure.
This feature acts as the first line of defense in the script's execution flow, ensuring that subsequent operations like enabling the 64-bit kernel or adjusting GPU memory are only performed on supported devices.
Sources: README.md:1-10, safe64.sh:11-15
Detection Logic and Implementation
Device Tree Verification
The core detection logic relies on querying the Linux device tree model information. Specifically, the script searches for the string "Raspberry Pi" within the file /proc/device-tree/model. This file is a standard interface on ARM-based Linux systems that provides the specific hardware model name as identified by the kernel.
The following flowchart illustrates the hardware validation process:
The diagram shows how hardware detection serves as a mandatory gateway before any file modifications occur.
Sources: safe64.sh:11-15
Error Handling
If the hardware detection fails (i.e., the string is not found or the file does not exist), the script immediately terminates with a non-zero exit code. This is enforced by the set -e directive at the start of the script, which ensures that the utility does not proceed if the hardware validation command returns an error.
| Component | Method | Target Path | Expected Value |
|---|---|---|---|
| Model Identifier | grep -q | /proc/device-tree/model | "Raspberry Pi" |
| Error Trigger | exit 1 | Standard Output | "Error: Not running on a Raspberry Pi." |
Sources: safe64.sh:6, safe64.sh:12-14
Impact on System Configuration
Once hardware detection confirms a valid environment, the system proceeds to interact with specific Raspberry Pi firmware configuration files. The hardware detection ensures that the following operations are performed safely:
- Backup Creation: A backup of
/boot/config.txtis created as/boot/config.txt.bak. - Kernel Bit-mode Switch: The script appends
arm_64bit=1to the configuration. - Performance Tuning: Specific Raspberry Pi parameters like
gpu_mem=16are applied.
The sequence of these operations is strictly dependent on the success of the initial hardware detection phase.
This diagram demonstrates the dependency of the configuration workflow on the initial hardware verification response.
Sources: safe64.sh:17-31, README.md:6-10
Conclusion
Hardware detection in safe64switch provides a simple yet effective safeguard for system administration. By verifying the hardware through the /proc filesystem, the script ensures that system modifications are restricted to the intended platform, thereby maintaining the integrity of non-Raspberry Pi systems where the script might be executed by mistake.
Sources: safe64.sh:11-15, README.md:1-5