@@ -29,6 +29,7 @@ const handle = app.getRequestHandler()
2929async function start ( ) {
3030 console . log ( 'Starting PiBox Host' )
3131 await startFramebuffer ( )
32+ await checkBootFirmwareCmdline ( )
3233 await getVersion ( )
3334 app . prepare ( ) . then ( async ( ) => {
3435 createServer ( ( req , res ) => {
@@ -92,9 +93,10 @@ async function getOrCreateKeys() {
9293}
9394
9495async function startFramebuffer ( ) {
96+ const path = '/boot/firmware/config.txt'
9597 try {
9698 // Check that SPI is enabled
97- let bootConfigLines = ( await readFile ( '/boot/config.txt' , 'utf8' ) ) . split ( '\n' )
99+ let bootConfigLines = ( await readFile ( path , 'utf8' ) ) . split ( '\n' )
98100 let requiresReboot = false
99101 bootConfigLines = bootConfigLines . map ( ( line ) => {
100102 if ( line === 'dtparam=spi=off' || line === '#dtparam=spi=on' || line === '#dtparam=spi=off' ) {
@@ -106,7 +108,8 @@ async function startFramebuffer() {
106108 } )
107109 if ( requiresReboot ) {
108110 console . log ( 'Enabling SPI, rebooting...' )
109- await writeFile ( '/boot/config.txt' , bootConfigLines . join ( '\n' ) )
111+ await writeFile ( path , bootConfigLines . join ( '\n' ) )
112+ await execAsync ( 'sync' )
110113 await execAsync ( 'reboot now' )
111114 process . exit ( )
112115 }
@@ -119,6 +122,23 @@ async function startFramebuffer() {
119122 }
120123}
121124
125+ async function checkBootFirmwareCmdline ( ) {
126+ let cmdlineOpts = ( await readFile ( '/boot/firmware/cmdline.txt' , 'utf8' ) ) . split ( ' ' )
127+ const includesPcieAspm = cmdlineOpts . find ( ( opt ) => opt . startsWith ( 'pcie_aspm=' ) )
128+ if ( includesPcieAspm ) {
129+ console . log ( '✓ PCIe ASPM mode set:' , includesPcieAspm )
130+ } else {
131+ // insert pcie_aspm=off before rootwait
132+ const rootwaitIndex = cmdlineOpts . indexOf ( 'rootwait' )
133+ cmdlineOpts . splice ( rootwaitIndex , 0 , 'pcie_aspm=off' )
134+ console . log ( 'Disabling PCIe ASPM mode, rebooting...' )
135+ await writeFile ( '/boot/firmware/cmdline.txt' , cmdlineOpts . join ( ' ' ) )
136+ await execAsync ( 'sync' )
137+ await execAsync ( 'reboot now' )
138+ process . exit ( )
139+ }
140+ }
141+
122142async function getVersion ( ) {
123143 try {
124144 const pkgPath = process . cwd ( ) + '/package.json'
0 commit comments