diff --git a/.gitignore b/.gitignore index c64ba14..a32a598 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ node_modules package-lock.json index.js *.tgz +pdfs diff --git a/bin/duh-bus.js b/bin/duh-bus.js index 8d5623e..03e8c93 100755 --- a/bin/duh-bus.js +++ b/bin/duh-bus.js @@ -1,9 +1,25 @@ #!/usr/bin/env node 'use strict'; +const process = require('process'); const path = require('path'); +const { program } = require('commander'); +const dl = require('../lib/amba-pdf-dl.js'); -const specPath = path.resolve(__dirname, '../specs'); +const main = async () => { + program + .option('--amba-pdf-dl ', 'download AMBA spec PDFs') + .parse(process.argv); + + const opts = program.opts(); + if (opts.ambaPdfDl) { + await dl(opts.ambaPdfDl); + return; + } + const specPath = path.resolve(__dirname, '../specs'); + console.log(specPath); +}; + +main(); -console.log(specPath); /* eslint no-console:0 */ diff --git a/lib/amba-pdf-dl.js b/lib/amba-pdf-dl.js new file mode 100644 index 0000000..df5e60c --- /dev/null +++ b/lib/amba-pdf-dl.js @@ -0,0 +1,38 @@ +'use strict'; + +const { createWriteStream, existsSync } = require('fs'); +const { mkdir } = require("fs/promises"); +const path = require('path'); +const { Readable } = require('stream'); +const { finished } = require('stream/promises'); + +const specs = require('./amba-specs.js'); + +const dl = async (ambaSpecsDl) => { + const dlFolderPath = path.resolve('.', ambaSpecsDl); + if (!existsSync(dlFolderPath)) { + await mkdir(dlFolderPath); + } + for (const spec of specs) { + const url = `https://documentation-service.arm.com/static/${spec.id}?token=`; + const res = await fetch(url); + const headers = res.headers.entries(); + let fileName; + for (const [key, val] of headers) { + if (key === 'content-disposition') { + const m = val.match(/^attachment; filename=(?[\w_-]+).pdf$/); + fileName = m.groups.baseName + '.pdf'; + } + } + const fullFileName = path.resolve('.', dlFolderPath, fileName); + if (!existsSync(fullFileName)) { + const fileStream = createWriteStream(fullFileName, { flags: 'wx'}); + await finished(Readable.fromWeb(res.body).pipe(fileStream)); + console.log(fileName + ' - downloded'); + } else { + console.log(fileName + ' - exists'); + } + } +}; + +module.exports = dl; diff --git a/lib/amba-specs.js b/lib/amba-specs.js new file mode 100644 index 0000000..28f59b0 --- /dev/null +++ b/lib/amba-specs.js @@ -0,0 +1,55 @@ +'use strict'; + +const ids = [ + // {id: '????????????????????????', amba: 2, protocol: 'APB2', rev: 'A', docid: 'IHI0011A', name: 'IHI0011A'}, + {id: '64257d8379edab6d64fb6f68', amba: 3, protocol: 'APB3', rev: 'B', docid: 'IHI0024b', name: 'IHI0024b'}, + {id: '64257f64314e245d086bc8b7', amba: 4, protocol: 'APB4', rev: 'C', docid: 'IHI0024C', name: 'IHI0024C_amba_apb_protocol_v2_0_spec'}, + {id: '60d5b505677cf7536a55c245', amba: 5, protocol: 'APB5', rev: 'D', docid: 'IHI0024D', name: 'IHI0024D_amba_apb_protocol_spec'}, + {id: '63fe2c1356ea36189d4e79f3', amba: 5, protocol: 'APB5', rev: 'E', docid: 'IHI0024E', name: 'IHI0024E_amba_apb_architecture_spec'}, + {id: '64258237314e245d086bc8c6', amba: 3, protocol: 'AHB-Lite', rev: 'A', docid: 'IHI0033a', name: 'IHI0033a'}, + {id: '5f91607cf86e16515cdc3b4b', amba: 5, protocol: 'AHB', rev: 'B.b', docid: 'IHI0033B_B', name: 'IHI0033B_B_amba_5_ahb_protocol_spec'}, + {id: '6141bf0d674a052ae36ca811', amba: 5, protocol: 'AHB', rev: 'C', docid: 'IHI0033C', name: 'IHI0033C_amba_ahb_protocol_spec'}, + {id: '5f915920f86e16515cdc3342', amba: 3, protocol: 'AXI', rev: 'B', docid: 'IHI0022B', name: 'AMBAaxi'}, + {id: '64256e84314e245d086bc88f', amba: 3, protocol: 'AXI', rev: 'C', docid: 'IHI0022C', name: 'IHI0022C_amba_axi_v2_0_protocol_spec'}, + {id: '64256ff4314e245d086bc893', amba: 4, protocol: 'AXI', rev: 'D', docid: 'IHI0022D', name: 'IHI0022D_amba_axi_protocol_spec'}, + {id: '6425706579edab6d64fb6f54', amba: 4, protocol: 'AXI', rev: 'E', docid: 'IHI0022E', name: 'IHI0022E_amba_axi_and_ace_protocol_spec'}, + {id: '5f915bbcf86e16515cdc3b23', amba: 5, protocol: 'AXI', rev: 'F.b', docid: 'IHI0022F_b', name: 'IHI0022F_b_amba_axi_protocol_spec'}, + {id: '5f915905f86e16515cdc333b', amba: 5, protocol: 'AXI', rev: 'G', docid: 'IHI0022G', name: 'IHI0022G_amba_axi_protocol_spec'}, + {id: '5f915965f86e16515cdc339c', amba: 5, protocol: 'AXI', rev: 'H', docid: 'IHI0022H', name: 'IHI0022H_amba_axi_protocol_spec'}, + {id: '602a9df190ee6824a1e02b98', amba: 5, protocol: 'AXI', rev: 'H.c', docid: 'IHI0022H_c', name: 'IHI0022H_c_amba_axi_protocol_spec'}, + {id: '63ff0ebd56ea36189d4e7ee7', amba: 5, protocol: 'AXI', rev: 'J', docid: 'IHI0022J', name: 'IHI0022J_amba_axi_protocol_spec'}, + {id: '651c285c15583d1bff972f94', amba: 5, protocol: 'AXI', rev: 'K', docid: 'IHI0022K', name: 'IHI0022K_amba_axi_protocol_spec'}, + {id: '642583d7314e245d086bc8c9', amba: 4, protocol: 'AXI-Stream', rev: 'A', docid: 'IHI0051A', name: 'IHI0051A_amba4_axi4_stream_v1_0_protocol_spec'}, + {id: '64819f1516f0f201aa6b963c', amba: 5, protocol: 'AXI-Stream', rev: 'B', docid: 'IHI0051B', name: 'IHI0051B_amba_axi_stream_protocol_spec'}, + {id: '5f914e1cf86e16515cdc2b3b', amba: 5, protocol: 'CHI', rev: 'B', docid: 'IHI0050B', name: 'amba_5_chi_architecture_specification_IHI0050B'}, + {id: '5f914e9bf86e16515cdc2b47', amba: 5, protocol: 'CHI', rev: 'C', docid: 'IHI0050C', name: 'IHI0050C_amba_5_chi_architecture_spec'}, + {id: '5f914ecbf86e16515cdc2b4d', amba: 5, protocol: 'CHI', rev: 'D', docid: 'IHI0050D', name: 'IHI0050D_amba_5_chi_architecture_spec'}, + {id: '6087f99b5e70d934bc69f1f0', amba: 5, protocol: 'CHI', rev: 'E.a', docid: 'IHI0050E_a', name: 'IHI0050E_a_amba_5_chi_architecture_spec'}, + {id: '6295e03db334256d9ea8ae86', amba: 5, protocol: 'CHI', rev: 'E.b', docid: 'IHI0050E_b', name: 'IHI0050E_b_amba_chi_architecture_spec'}, + {id: '63341ee5da191e7fe057d04b', amba: 5, protocol: 'CHI', rev: 'E.c', docid: 'IHI0050E_c', name: 'IHI0050E_c_amba_chi_architecture_spec'}, + {id: '65a69276b52744113be6343b', amba: 5, protocol: 'CHI', rev: 'F', docid: 'IHI0050F', name: 'IHI0050F_amba_chi_architecture_spec'}, + {id: '65e83256837c4d065f65591d', amba: 5, protocol: 'CHI', rev: 'F.b', docid: 'IHI0050F_b', name: 'IHI0050F_b_amba_chi_architecture_spec'}, + {id: '65e836aaa97073311e216fb9', amba: 5, protocol: 'CHI', rev: 'G', docid: 'IHI0050G', name: 'IHI0050G_amba_chi_architecture_spec'}, + {id: '5f915d9ff86e16515cdc3b30', amba: 5, protocol: 'GFB', rev: 'A', docid: 'IHI0083A', name: 'IHI0083A_amba_generic_flash_bus_architecture_specification'}, + {id: '6294e5a131ea212bb662277e', amba: 5, protocol: 'GFB', rev: 'A.b', docid: 'IHI0083A_b', name: 'IHI0083A_b_amba_generic_flash_bus_protocol_specification'}, + {id: '5f914f6ef86e16515cdc2b62', amba: 5, protocol: 'ATP', rev: 'A', docid: 'IHI0082A', name: 'IHI0082A_amba_adaptive_traffic_profiles_specification'}, + {id: '5f915e4ef86e16515cdc3b37', amba: 5, protocol: 'LPI', rev: 'B', docid: 'IHI0068B', name: 'IHI0068B_low_power_interface_spec'}, + {id: '5f915e69f86e16515cdc3b3e', amba: 5, protocol: 'LPI', rev: 'C', docid: 'IHI0068C', name: 'IHI0068C_low_power_interface_spec'}, + {id: '617a637283e60c5c768e2241', amba: 5, protocol: 'LPI', rev: 'D', docid: 'IHI0068D', name: 'IHI0068D_amba_low_power_interface_spec'}, + {id: '6425805779edab6d64fb6f72', amba: 3, protocol: 'ATB', rev: 'A', docid: 'IHI0032A', name: 'IHI0032a'}, + {id: '5fb7ec16d77dd807b9a80cb6', amba: 4, protocol: 'ATB', rev: 'B', docid: 'IHI0032B', name: 'IHI0032B_amba_atb_protocol_spec'}, + {id: '61b0bea883e60c5c768e4c6a', amba: 5, protocol: 'ATB', rev: 'C', docid: 'IHI0032C', name: 'IHI0032C_amba_atb_protocol_spec'}, + {id: '5fc5124e6620e02e2b67ebb4', amba: 5, protocol: 'LTI', rev: 'A', docid: 'IHI0089A', name: 'IHI0089A_amba_lti'}, + {id: '611131bd3d73a34b640e33ff', amba: 5, protocol: 'LTI', rev: 'A.b', docid: 'IHI0089A_b', name: 'IHI0089A_b_amba_lti_protocol_spec'}, + {id: '651d2bd515583d1bff973037', amba: 5, protocol: 'LTI', rev: 'B', docid: 'IHI0089B', name: 'IHI0089B_amba_lti_protocol_spec'}, + {id: '60ddf202677cf7536a55cd55', amba: 5, protocol: 'DTI', rev: 'E', docid: 'IHI0088E', name: 'IHI0088E_amba_dti_protocol_spec'}, + {id: '60ddf3840320e92fa40b6010', amba: 5, protocol: 'DTI', rev: 'E.b', docid: 'IHI0088E_b', name: 'IHI0088E_b_amba_dti_protocol_spec'}, + {id: '65e83b84a97073311e216fc1', amba: 5, protocol: 'DTI', rev: 'E.c', docid: 'IHI0088E_c', name: 'IHI0088E_c_amba_dti_protocol_spec'}, + {id: '65ef05752caafd7dd7a386d6', amba: 5, protocol: 'DTI', rev: 'F', docid: 'IHI0088F', name: 'IHI0088F_amba_dti_protocol_spec'}, + {id: '5f915d17f86e16515cdc3b2a', amba: 5, protocol: 'CXS', rev: 'A', docid: 'IHI0079A', name: 'IHI0079A_amba_cxs_protocol_spec-2'}, + {id: '60002aa43f22832ff1d6871b', amba: 5, protocol: 'CXS', rev: 'B', docid: 'IHI0079B', name: 'IHI0079B_amba_cxs_streaming_protocol_spec'}, + {id: '656d9b43c31bbd744e645613', amba: 5, protocol: 'CXS', rev: 'C', docid: 'IHI0079C', name: 'IHI0079C_amba_cxs_streaming_protocol_spec'}, + {id: '65cb95b0c2052a35156cea71', amba: 5, protocol: 'CHI-C2C', rev: 'A', docid: 'IHI0098A', name: 'IHI0098A_amba_chi_c2c_architecture_spec'}, +]; + +module.exports = ids; diff --git a/package.json b/package.json index 50e6fba..dfe4f79 100644 --- a/package.json +++ b/package.json @@ -41,6 +41,7 @@ "nyc": "^15.1.0" }, "dependencies": { + "commander": "^12.1.0", "json5": "^2.2.3" } }