#!/bin/bash # BBeOS Emulation Script # Emulates BBeOS on Linux using QEMU set -e # Configuration BBEOS_VERSION="1.0.0" QEMU_ARCH="arm" QEMU_MACHINE="vexpress-a9" QEMU_CPU="cortex-a9" QEMU_RAM="2G" QEMU_DISPLAY="720x720" QEMU_KERNEL="kernel-source/arch/arm/boot/zImage" QEMU_DTB="kernel-source/arch/arm/boot/dts/vexpress-v2p-ca9.dtb" QEMU_INITRAMFS="initramfs.img" QEMU_DISK="bbeos-emulation.img" # Colors for output RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' BLUE='\033[0;34m' NC='\033[0m' # No Color # Logging functions log_info() { echo -e "${BLUE}[INFO]${NC} $1" } log_success() { echo -e "${GREEN}[SUCCESS]${NC} $1" } log_warning() { echo -e "${YELLOW}[WARNING]${NC} $1" } log_error() { echo -e "${RED}[ERROR]${NC} $1" } # Check dependencies check_dependencies() { log_info "Checking dependencies..." local missing_deps=() # Check QEMU if ! command -v qemu-system-arm &> /dev/null; then missing_deps+=("qemu-system-arm") fi # Check ARM toolchain if ! command -v arm-linux-gnueabihf-gcc &> /dev/null; then missing_deps+=("gcc-arm-linux-gnueabihf") fi # Check additional tools for tool in make git wget; do if ! command -v $tool &> /dev/null; then missing_deps+=("$tool") fi done if [ ${#missing_deps[@]} -ne 0 ]; then log_error "Missing dependencies: ${missing_deps[*]}" log_info "Install them with:" log_info " sudo apt-get install ${missing_deps[*]}" exit 1 fi log_success "All dependencies found" } # Create virtual disk create_virtual_disk() { log_info "Creating virtual disk..." if [ ! -f "$QEMU_DISK" ]; then qemu-img create -f raw "$QEMU_DISK" 8G log_success "Created virtual disk: $QEMU_DISK" else log_info "Virtual disk already exists: $QEMU_DISK" fi } # Build kernel and initramfs build_system() { log_info "Building BBeOS system components..." # Build kernel if not exists if [ ! -f "$QEMU_KERNEL" ]; then log_info "Building kernel..." cd kernel-source make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- vexpress_defconfig make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- -j$(nproc) cd .. fi # Build initramfs if not exists if [ ! -f "$QEMU_INITRAMFS" ]; then log_info "Building initramfs..." ./scripts/build-rootfs.sh fi log_success "System components built" } # Create QEMU configuration create_qemu_config() { log_info "Creating QEMU configuration..." cat > qemu-bbeos.conf << EOF # BBeOS QEMU Configuration # Generated by BBeOS emulation script # Machine configuration -machine $QEMU_MACHINE -cpu $QEMU_CPU -m $QEMU_RAM # Display configuration -display gtk -vga none -fbdev /dev/fb0 # Input devices -kernel $QEMU_KERNEL -dtb $QEMU_DTB -initrd $QEMU_INITRAMFS # Storage -drive file=$QEMU_DISK,if=sd,format=raw # Network (optional) -net nic,model=lan9118 -net user # Serial console -serial stdio # Additional options -no-reboot -no-shutdown EOF log_success "QEMU configuration created: qemu-bbeos.conf" } # Start emulation start_emulation() { log_info "Starting BBeOS emulation..." # Check if components exist if [ ! -f "$QEMU_KERNEL" ]; then log_error "Kernel not found: $QEMU_KERNEL" log_info "Run: ./scripts/build-kernel.sh" exit 1 fi if [ ! -f "$QEMU_INITRAMFS" ]; then log_error "Initramfs not found: $QEMU_INITRAMFS" log_info "Run: ./scripts/build-rootfs.sh" exit 1 fi # Start QEMU log_info "Launching QEMU with BBeOS..." log_info "Press Ctrl+A, then X to exit" qemu-system-arm \ -machine $QEMU_MACHINE \ -cpu $QEMU_CPU \ -m $QEMU_RAM \ -display gtk \ -vga none \ -kernel $QEMU_KERNEL \ -dtb $QEMU_DTB \ -initrd $QEMU_INITRAMFS \ -drive file=$QEMU_DISK,if=sd,format=raw \ -net nic,model=lan9118 \ -net user \ -serial stdio \ -no-reboot \ -no-shutdown \ -append "console=ttyAMA0,115200 root=/dev/ram0 rw init=/init" } # Create development environment create_dev_environment() { log_info "Creating development environment..." # Create development directory mkdir -p bbeos-dev # Copy system components cp $QEMU_KERNEL bbeos-dev/ cp $QEMU_INITRAMFS bbeos-dev/ cp $QEMU_DISK bbeos-dev/ # Create development script cat > bbeos-dev/run-dev.sh << 'EOF' #!/bin/bash # BBeOS Development Environment echo "BBeOS Development Environment" echo "=============================" echo "" echo "Available commands:" echo " ./run-emulation.sh - Start BBeOS emulation" echo " ./build-apps.sh - Build applications" echo " ./test-apps.sh - Test applications" echo " ./debug.sh - Start with debugging" echo "" EOF chmod +x bbeos-dev/run-dev.sh # Create emulation script cat > bbeos-dev/run-emulation.sh << 'EOF' #!/bin/bash # Run BBeOS emulation qemu-system-arm \ -machine vexpress-a9 \ -cpu cortex-a9 \ -m 2G \ -display gtk \ -vga none \ -kernel zImage \ -dtb vexpress-v2p-ca9.dtb \ -initrd initramfs.img \ -drive file=bbeos-emulation.img,if=sd,format=raw \ -net nic,model=lan9118 \ -net user \ -serial stdio \ -no-reboot \ -no-shutdown \ -append "console=ttyAMA0,115200 root=/dev/ram0 rw init=/init" EOF chmod +x bbeos-dev/run-emulation.sh log_success "Development environment created in bbeos-dev/" } # Create debugging configuration create_debug_config() { log_info "Creating debugging configuration..." cat > qemu-debug.conf << EOF # BBeOS QEMU Debug Configuration # Machine configuration -machine $QEMU_MACHINE -cpu $QEMU_CPU -m $QEMU_RAM # Display configuration -display gtk -vga none # Kernel and initramfs -kernel $QEMU_KERNEL -dtb $QEMU_DTB -initrd $QEMU_INITRAMFS # Storage -drive file=$QEMU_DISK,if=sd,format=raw # Network -net nic,model=lan9118 -net user # Debugging -serial stdio -gdb tcp::1234 -S # Additional options -no-reboot -no-shutdown EOF log_success "Debug configuration created: qemu-debug.conf" } # Show help show_help() { echo "BBeOS Emulation Script" echo "=====================" echo "" echo "Usage: $0 [OPTION]" echo "" echo "Options:" echo " start - Start BBeOS emulation" echo " build - Build system components" echo " setup - Setup emulation environment" echo " dev - Create development environment" echo " debug - Start with debugging enabled" echo " clean - Clean build artifacts" echo " help - Show this help" echo "" echo "Examples:" echo " $0 setup - Setup emulation environment" echo " $0 start - Start BBeOS emulation" echo " $0 dev - Create development environment" echo "" } # Clean build artifacts clean_build() { log_info "Cleaning build artifacts..." rm -f $QEMU_DISK rm -f qemu-bbeos.conf rm -f qemu-debug.conf rm -rf bbeos-dev log_success "Build artifacts cleaned" } # Main function main() { case "${1:-start}" in "start") check_dependencies build_system create_virtual_disk start_emulation ;; "build") check_dependencies build_system ;; "setup") check_dependencies build_system create_virtual_disk create_qemu_config create_debug_config log_success "BBeOS emulation environment setup complete" ;; "dev") check_dependencies build_system create_dev_environment log_success "Development environment created" ;; "debug") check_dependencies build_system create_debug_config log_info "Starting BBeOS with debugging enabled..." log_info "Connect GDB to localhost:1234" qemu-system-arm -readconfig qemu-debug.conf ;; "clean") clean_build ;; "help"|"-h"|"--help") show_help ;; *) log_error "Unknown option: $1" show_help exit 1 ;; esac } # Run main function main "$@"