Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[deprecation] PRODUCT_ID macro #2446

Merged
merged 1 commit into from
Apr 28, 2022
Merged

Conversation

technobly
Copy link
Member

@technobly technobly commented Apr 28, 2022

Problem

  • Users would like to be able to use the same binary for multiple Products with the same functionality.
  • Internally we would like to not be bound to how many Products there can be.

Solution

Deprecate/remove the PRODUCT_ID macro in Device OS 4.0.0 - including this macro will cause a build error and show this message:

The PRODUCT_ID macro must be removed from your firmware source code. The same compiled firmware binary may be used in multiple products that share the same platform and functionality.

Steps to Test

  • Run unit tests
  • Run the example app below
  • Inspect the binaries

Example App

#include "Particle.h"
// The following app should error and generate the appropriate
// message. Comment out PRODUCT_ID and it should pass.
PRODUCT_ID(42);
PRODUCT_VERSION(3);
void setup() {
	pinMode(D7, OUTPUT);
}
void loop() {
	digitalWrite(D7, HIGH);
	delay(100);
	digitalWrite(D7, LOW);
	delay(100);
}

Here's a couple examples of what the resulting binary should compile as before (1) this PR and after (2) this PR:

// USING THE PARTICLE CLI
// ======================
$ particle binary inspect product_id_and_version1.bin
product_id_and_version1.bin
 CRC is ok (f54dc78f)
 Compiled for boron
 This is an application module number 2 at version 6
 It is firmware for product id 42 at version 3
 It depends on a system module number 1 at version 3301

$ particle binary inspect product_id_and_version2.bin
product_id_and_version2.bin
 CRC is ok (4bc2baf6)
 Compiled for boron
 This is an application module number 2 at version 6
 It is firmware for product id 13 at version 3
 It depends on a system module number 1 at version 3301

// USING THE BINARY VERSION READER
// ===============================
$ pmod product_id_and_version1.bin
got [Arguments] {
  '0': {
    filename: 'product_id_and_version1.bin',
    fileBuffer: <Buffer 00 40 0b 00 70 52 0b 00 00 00 06 00 0d 00 05 02 04 01 e5 0c 00 00 00 00 90 4f 0b 00 09 48 0a 49 88 42 08 b5 05 d0 09 4a 82 42 02 d0 12 1a 00 f0 fd fe ... 4674 more bytes>,
    crc: { ok: true, storedCrc: 'f54dc78f', actualCrc: 'f54dc78f' },
    prefixInfo: {
      moduleStartAddy: 'b4000',
      moduleEndAddy: 'b5270',
      reserved: 0,
      moduleFlags: 0,
      moduleVersion: 6,
      platformID: 13,
      moduleFunction: 5,
      moduleIndex: 2,
      depModuleFunction: 4,
      depModuleIndex: 1,
      depModuleVersion: 3301,
      dep2ModuleFunction: 0,
      dep2ModuleIndex: 0,
      dep2ModuleVersion: 0,
      prefixOffset: 0
    },
    suffixInfo: {
      productId: 42,
      productVersion: 3,
      fwUniqueId: '1afbb2505a6af6c17204771512b15135025121358fea03e54f78ff066bae9c46',
      reserved: 0,
      suffixSize: 40,
      crcBlock: 'f54dc78f'
    }
  },
  '1': null
}

$ pmod product_id_and_version2.bin
got [Arguments] {
  '0': {
    filename: 'product_id_and_version2.bin',
    fileBuffer: <Buffer 00 40 0b 00 70 52 0b 00 00 00 06 00 0d 00 05 02 04 01 e5 0c 00 00 00 00 90 4f 0b 00 09 48 0a 49 88 42 08 b5 05 d0 09 4a 82 42 02 d0 12 1a 00 f0 fd fe ... 4674 more bytes>,
    crc: { ok: true, storedCrc: '4bc2baf6', actualCrc: '4bc2baf6' },
    prefixInfo: {
      moduleStartAddy: 'b4000',
      moduleEndAddy: 'b5270',
      reserved: 0,
      moduleFlags: 0,
      moduleVersion: 6,
      platformID: 13,
      moduleFunction: 5,
      moduleIndex: 2,
      depModuleFunction: 4,
      depModuleIndex: 1,
      depModuleVersion: 3301,
      dep2ModuleFunction: 0,
      dep2ModuleIndex: 0,
      dep2ModuleVersion: 0,
      prefixOffset: 0
    },
    suffixInfo: {
      productId: 13,
      productVersion: 3,
      fwUniqueId: '66b6b78f3ea48e101b30fe2ac12922085a8a43ed931cda3a8d50134880d37f74',
      reserved: 0,
      suffixSize: 40,
      crcBlock: '4bc2baf6'
    }
  },
  '1': null
}

References

sc-102015


Completeness

  • User is totes amazing for contributing!
  • Contributor has signed CLA (Info here)
  • Problem and Solution clearly stated
  • Run unit/integration/application tests on device
  • Added documentation
  • Added to CHANGELOG.md after merging (add links to docs and issues)

Copy link
Member

@monkbroc monkbroc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice and simple implementation!

I looked in the hex dump of application firmware compiled with and without the PRODUCT_VERSION macro and saw the expected bytes before the suffix (platform id and version). I uploaded firmware binaries to the Console and saw that the error for uploading a non-product binary can be improved. I'll do that in a separate PR.

wiring/inc/spark_wiring_version.h Outdated Show resolved Hide resolved
wiring/inc/spark_wiring_version.h Outdated Show resolved Hide resolved
@technobly technobly merged commit 00f8056 into develop Apr 28, 2022
@technobly technobly deleted the feature/sc102015-product-id branch April 28, 2022 16:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants