#!/bin/bash
# Step 10: Kernel command line (swiotlb + DSI rotation)

step_10_cmdline() {
  local cmdline="/boot/firmware/cmdline.txt"
  [[ -f "$cmdline" ]] || cmdline="/boot/cmdline.txt"
  [[ -f "$cmdline" ]] || { log "WARNING: cmdline.txt not found"; return 0; }

  if [[ -n "$SWIOTLB_SIZE" ]] && ! grep -q 'swiotlb=' "$cmdline"; then
    sed -i "s/rootwait/rootwait swiotlb=$SWIOTLB_SIZE/" "$cmdline"
    log "Added swiotlb=$SWIOTLB_SIZE to cmdline"
  fi
  if [[ -n "$DSI_ROTATE" ]] && ! grep -q 'video=DSI-1:rotate=' "$cmdline"; then
    sed -i "s/\$/ video=DSI-1:rotate=$DSI_ROTATE/" "$cmdline"
    log "Added video=DSI-1:rotate=$DSI_ROTATE to cmdline"
  fi
}
